]> source.dussan.org Git - redmine.git/commitdiff
Closing all subtasks causes error if default priority is not defined and priority...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 1 Oct 2016 09:38:58 +0000 (09:38 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 1 Oct 2016 09:38:58 +0000 (09:38 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@15857 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/unit/issue_subtasking_test.rb

index e2699394b40e5e1bd212e3c3cd810fef16fbea23..aca55775eef7e79d2c2bdefe4fee813f3d4b3d24 100644 (file)
@@ -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
 
index 020bcfdfc727f3ca3777ba83bcbb47ebe5931372..e878601b1039605321f443f2bf87aa2b0748ca90 100644 (file)
@@ -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!