From 7fddbc25ba2c9ffac4cb894cd7383727c38ef91f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 1 Oct 2016 09:38:58 +0000 Subject: [PATCH] Closing all subtasks causes error if default priority is not defined and priority is derived from subtasks (#23878). git-svn-id: http://svn.redmine.org/redmine/trunk@15857 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue.rb | 5 +++-- test/unit/issue_subtasking_test.rb | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index e2699394b..aca55775e 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1542,10 +1542,11 @@ class Issue < ActiveRecord::Base 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 diff --git a/test/unit/issue_subtasking_test.rb b/test/unit/issue_subtasking_test.rb index 020bcfdfc..e878601b1 100644 --- a/test/unit/issue_subtasking_test.rb +++ b/test/unit/issue_subtasking_test.rb @@ -108,6 +108,30 @@ class IssueSubtaskingTest < ActiveSupport::TestCase 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! -- 2.39.5