From b8ffc995c187fff2f4434d17f6141190c048b0a5 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 6 Feb 2014 18:00:37 +0000 Subject: [PATCH] Merged r12745 (#15870). git-svn-id: http://svn.redmine.org/redmine/branches/2.4-stable@12847 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue.rb | 2 +- test/unit/issue_nested_set_test.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 0101abf00..582caaa60 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1352,7 +1352,7 @@ class Issue < ActiveRecord::Base 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 + average = p.leaves.where("estimated_hours > 0").average(:estimated_hours).to_f if average == 0 average = 1 end diff --git a/test/unit/issue_nested_set_test.rb b/test/unit/issue_nested_set_test.rb index 3c611be28..215cc8823 100644 --- a/test/unit/issue_nested_set_test.rb +++ b/test/unit/issue_nested_set_test.rb @@ -358,6 +358,18 @@ class IssueNestedSetTest < ActiveSupport::TestCase assert_equal 12, parent.reload.estimated_hours end + def test_done_ratio_of_parent_with_a_child_with_estimated_time_at_0_should_not_exceed_100 + parent = Issue.generate! + Issue.generate!(:estimated_hours => 40, :parent_issue_id => parent.id) + Issue.generate!(:estimated_hours => 40, :parent_issue_id => parent.id) + Issue.generate!(:estimated_hours => 20, :parent_issue_id => parent.id) + Issue.generate!(:estimated_hours => 0, :parent_issue_id => parent.id) + parent.reload.children.each do |child| + child.update_attribute :status_id, 5 + end + assert_equal 100, parent.reload.done_ratio + end + def test_move_parent_updates_old_parent_attributes first_parent = Issue.generate! second_parent = Issue.generate!