]> source.dussan.org Git - redmine.git/commitdiff
Fixes reverting an issue to a status with a done_ratio of 0%. #5170
authorEric Davis <edavis@littlestreamsoftware.com>
Sun, 26 Sep 2010 18:13:31 +0000 (18:13 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Sun, 26 Sep 2010 18:13:31 +0000 (18:13 +0000)
Contributed by Felix Schäfer

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4186 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/fixtures/issues.yml
test/unit/issue_test.rb

index c49952306b0147a242cb80f760defc692c9ab9a6..b72d7b4addf294da16c018514c1600b536c0cab8 100644 (file)
@@ -263,7 +263,7 @@ class Issue < ActiveRecord::Base
   end
   
   def done_ratio
-    if Issue.use_status_for_done_ratio? && status && status.default_done_ratio?
+    if Issue.use_status_for_done_ratio? && status && status.default_done_ratio
       status.default_done_ratio
     else
       read_attribute(:done_ratio)
@@ -326,7 +326,7 @@ class Issue < ActiveRecord::Base
   # Set the done_ratio using the status if that setting is set.  This will keep the done_ratios
   # even if the user turns off the setting later
   def update_done_ratio_from_issue_status
-    if Issue.use_status_for_done_ratio? && status && status.default_done_ratio?
+    if Issue.use_status_for_done_ratio? && status && status.default_done_ratio
       self.done_ratio = status.default_done_ratio
     end
   end
@@ -714,7 +714,7 @@ class Issue < ActiveRecord::Base
       end
       
       # done ratio = weighted average ratio of leaves
-      unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio?
+      unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio
         leaves_count = p.leaves.count
         if leaves_count > 0
           average = p.leaves.average(:estimated_hours).to_f
index 3adda31215b5fdb18a10a537aec8957012a137ea..eec014ff4fb2592c8248f9fd938cd575ccfad8c4 100644 (file)
@@ -38,6 +38,7 @@ issues_002:
   lft: 1
   rgt: 2
   lock_version: 3
+  done_ratio: 30
 issues_003: 
   created_on: 2006-07-19 21:07:27 +02:00
   project_id: 1
index dd10e01204723828a6cb4e31b722888bf2e7f5fd..043eac146774951f34abc147f208557314b071b1 100644 (file)
@@ -593,6 +593,9 @@ class IssueTest < ActiveSupport::TestCase
       @issue = Issue.find(1)
       @issue_status = IssueStatus.find(1)
       @issue_status.update_attribute(:default_done_ratio, 50)
+      @issue2 = Issue.find(2)
+      @issue_status2 = IssueStatus.find(2)
+      @issue_status2.update_attribute(:default_done_ratio, 0)
     end
     
     context "with Setting.issue_done_ratio using the issue_field" do
@@ -602,6 +605,7 @@ class IssueTest < ActiveSupport::TestCase
       
       should "read the issue's field" do
         assert_equal 0, @issue.done_ratio
+        assert_equal 30, @issue2.done_ratio
       end
     end
 
@@ -612,6 +616,7 @@ class IssueTest < ActiveSupport::TestCase
       
       should "read the Issue Status's default done ratio" do
         assert_equal 50, @issue.done_ratio
+        assert_equal 0, @issue2.done_ratio
       end
     end
   end
@@ -621,6 +626,9 @@ class IssueTest < ActiveSupport::TestCase
       @issue = Issue.find(1)
       @issue_status = IssueStatus.find(1)
       @issue_status.update_attribute(:default_done_ratio, 50)
+      @issue2 = Issue.find(2)
+      @issue_status2 = IssueStatus.find(2)
+      @issue_status2.update_attribute(:default_done_ratio, 0)
     end
     
     context "with Setting.issue_done_ratio using the issue_field" do
@@ -630,8 +638,10 @@ class IssueTest < ActiveSupport::TestCase
       
       should "not change the issue" do
         @issue.update_done_ratio_from_issue_status
+        @issue2.update_done_ratio_from_issue_status
 
-        assert_equal 0, @issue.done_ratio
+        assert_equal 0, @issue.read_attribute(:done_ratio)
+        assert_equal 30, @issue2.read_attribute(:done_ratio)
       end
     end
 
@@ -640,10 +650,12 @@ class IssueTest < ActiveSupport::TestCase
         Setting.issue_done_ratio = 'issue_status'
       end
       
-      should "not change the issue's done ratio" do
+      should "change the issue's done ratio" do
         @issue.update_done_ratio_from_issue_status
+        @issue2.update_done_ratio_from_issue_status
 
-        assert_equal 50, @issue.done_ratio
+        assert_equal 50, @issue.read_attribute(:done_ratio)
+        assert_equal 0, @issue2.read_attribute(:done_ratio)
       end
     end
   end