From d259dd2dd5cc1b73a8ff4f714234931311125499 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 13 Sep 2013 17:53:35 +0000 Subject: [PATCH] Merged r12131 and r12132 (#14798). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.3-stable@12134 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue.rb | 3 ++- test/unit/issue_nested_set_test.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index ee392b970..c6b2ab7da 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1337,7 +1337,8 @@ class Issue < ActiveRecord::Base if average == 0 average = 1 end - done = p.leaves.sum("COALESCE(estimated_hours, #{average}) * (CASE WHEN is_closed = #{connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)", :joins => :status).to_f + done = p.leaves.sum("COALESCE(CASE WHEN estimated_hours > 0 THEN estimated_hours ELSE NULL END, #{average}) " + + "* (CASE WHEN is_closed = #{connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)", :joins => :status).to_f progress = done / (average * leaves_count) p.done_ratio = progress.round end diff --git a/test/unit/issue_nested_set_test.rb b/test/unit/issue_nested_set_test.rb index 0d83671e0..3a53eb3af 100644 --- a/test/unit/issue_nested_set_test.rb +++ b/test/unit/issue_nested_set_test.rb @@ -302,6 +302,17 @@ class IssueNestedSetTest < ActiveSupport::TestCase assert_equal (50 * 20 + 20 * 10) / 30, parent.reload.done_ratio end + def test_parent_done_ratio_with_child_estimate_to_0_should_reach_100 + parent = Issue.generate! + issue1 = Issue.generate!(:parent_issue_id => parent.id) + issue2 = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 0) + assert_equal 0, parent.reload.done_ratio + issue1.reload.update_attribute :status_id, 5 + assert_equal 50, parent.reload.done_ratio + issue2.reload.update_attribute :status_id, 5 + assert_equal 100, parent.reload.done_ratio + end + def test_parent_estimate_should_be_sum_of_leaves parent = Issue.generate! Issue.generate!(:estimated_hours => nil, :parent_issue_id => parent.id) -- 2.39.5