5524_svn.diff

Jean-Baptiste Barth, 2010-06-08 19:50

Download (2.03 KB)

View differences:

test/unit/issue_nested_set_test.rb (working copy)
273 273
    assert_equal 12, parent.reload.estimated_hours
274 274
  end
275 275

  
276
  def test_move_parent_updates_old_parent_attributes
277
    first_parent = create_issue!
278
    second_parent = create_issue!
279
    child = create_issue!(:estimated_hours => 5, :parent_issue_id => first_parent.id)
280
    assert_equal 5, first_parent.reload.estimated_hours
281
    child.update_attributes(:estimated_hours => 7, :parent_issue_id => second_parent.id)
282
    assert_equal 7, second_parent.reload.estimated_hours
283
    assert_nil first_parent.reload.estimated_hours
284
  end
276 285

  
277 286
  def test_reschuling_a_parent_should_reschedule_subtasks
278 287
    parent = create_issue!
app/models/issue.rb (working copy)
629 629
      end
630 630
      reload
631 631
    elsif parent_issue_id != parent_id
632
      former_parent_id = parent_id
632 633
      # moving an existing issue
633 634
      if @parent_issue && @parent_issue.root_id == root_id
634 635
        # inside the same tree
......
658 659
          relation.destroy unless relation.valid?
659 660
        end
660 661
      end
662
      # update former parent
663
      recalculate_attributes_for(former_parent_id) if former_parent_id
661 664
    end
662 665
    remove_instance_variable(:@parent_issue) if instance_variable_defined?(:@parent_issue)
663 666
  end
664 667
  
665 668
  def update_parent_attributes
666
    if parent_id && p = Issue.find_by_id(parent_id)
669
    recalculate_attributes_for(parent_id) if parent_id
670
  end
671

  
672
  def recalculate_attributes_for(issue_id)
673
    if issue_id && p = Issue.find_by_id(issue_id)
667 674
      # priority = highest priority of children
668 675
      if priority_position = p.children.maximum("#{IssuePriority.table_name}.position", :include => :priority)
669 676
        p.priority = IssuePriority.find_by_position(priority_position)