From 83e0be5d07de590e35f30b81c5870ce02746e6b7 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Sun, 26 Sep 2010 18:13:31 +0000 Subject: [PATCH] Fixes reverting an issue to a status with a done_ratio of 0%. #5170 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 6 +++--- test/fixtures/issues.yml | 1 + test/unit/issue_test.rb | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index c49952306..b72d7b4ad 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -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 diff --git a/test/fixtures/issues.yml b/test/fixtures/issues.yml index 3adda3121..eec014ff4 100644 --- a/test/fixtures/issues.yml +++ b/test/fixtures/issues.yml @@ -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 diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index dd10e0120..043eac146 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -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 -- 2.39.5