@@ -629,6 +629,7 class Issue < ActiveRecord::Base | |||||
629 | end |
|
629 | end | |
630 | reload |
|
630 | reload | |
631 | elsif parent_issue_id != parent_id |
|
631 | elsif parent_issue_id != parent_id | |
|
632 | former_parent_id = parent_id | |||
632 | # moving an existing issue |
|
633 | # moving an existing issue | |
633 | if @parent_issue && @parent_issue.root_id == root_id |
|
634 | if @parent_issue && @parent_issue.root_id == root_id | |
634 | # inside the same tree |
|
635 | # inside the same tree | |
@@ -658,12 +659,18 class Issue < ActiveRecord::Base | |||||
658 | relation.destroy unless relation.valid? |
|
659 | relation.destroy unless relation.valid? | |
659 | end |
|
660 | end | |
660 | end |
|
661 | end | |
|
662 | # update former parent | |||
|
663 | recalculate_attributes_for(former_parent_id) if former_parent_id | |||
661 | end |
|
664 | end | |
662 | remove_instance_variable(:@parent_issue) if instance_variable_defined?(:@parent_issue) |
|
665 | remove_instance_variable(:@parent_issue) if instance_variable_defined?(:@parent_issue) | |
663 | end |
|
666 | end | |
664 |
|
667 | |||
665 | def update_parent_attributes |
|
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 | # priority = highest priority of children |
|
674 | # priority = highest priority of children | |
668 | if priority_position = p.children.maximum("#{IssuePriority.table_name}.position", :include => :priority) |
|
675 | if priority_position = p.children.maximum("#{IssuePriority.table_name}.position", :include => :priority) | |
669 | p.priority = IssuePriority.find_by_position(priority_position) |
|
676 | p.priority = IssuePriority.find_by_position(priority_position) |
@@ -273,6 +273,15 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
273 | assert_equal 12, parent.reload.estimated_hours |
|
273 | assert_equal 12, parent.reload.estimated_hours | |
274 | end |
|
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 | def test_reschuling_a_parent_should_reschedule_subtasks |
|
286 | def test_reschuling_a_parent_should_reschedule_subtasks | |
278 | parent = create_issue! |
|
287 | parent = create_issue! |
General Comments 0
You need to be logged in to leave comments.
Login now