if issue_id && p = Issue.find_by_id(issue_id)
if p.priority_derived?
# priority = highest priority of open children
+ # priority is left unchanged if all children are closed and there's no default priority defined
if priority_position = p.children.open.joins(:priority).maximum("#{IssuePriority.table_name}.position")
p.priority = IssuePriority.find_by_position(priority_position)
- else
- p.priority = IssuePriority.default
+ elsif default_priority = IssuePriority.default
+ p.priority = default_priority
end
end
end
end
+ def test_parent_priority_should_be_set_to_default_when_all_children_are_closed
+ with_settings :parent_issue_priority => 'derived' do
+ parent = Issue.generate!
+ child = parent.generate_child!(:priority => IssuePriority.find_by_name('High'))
+ assert_equal 'High', parent.reload.priority.name
+ child.status = IssueStatus.where(:is_closed => true).first
+ child.save!
+ assert_equal 'Normal', parent.reload.priority.name
+ end
+ end
+
+ def test_parent_priority_should_be_left_unchanged_when_all_children_are_closed_and_no_default_priority
+ IssuePriority.update_all :is_default => false
+
+ with_settings :parent_issue_priority => 'derived' do
+ parent = Issue.generate!(:priority => IssuePriority.find_by_name('Normal'))
+ child = parent.generate_child!(:priority => IssuePriority.find_by_name('High'))
+ assert_equal 'High', parent.reload.priority.name
+ child.status = IssueStatus.where(:is_closed => true).first
+ child.save!
+ assert_equal 'High', parent.reload.priority.name
+ end
+ end
+
def test_parent_done_ratio_should_be_read_only_with_parent_issue_done_ratio_set_to_derived
with_settings :parent_issue_done_ratio => 'derived' do
issue = Issue.generate_with_child!