Project

General

Profile

Defect #15957 ยป percent_done_in_parent_issues.diff

Holger Just, 2014-01-24 18:34

View differences:

app/models/issue.rb
1355 1355
      unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio
1356 1356
        leaves_count = p.leaves.count
1357 1357
        if leaves_count > 0
1358
          average = p.leaves.average(:estimated_hours).to_f
1358
          average = p.leaves.average("CASE WHEN estimated_hours > 0 THEN estimated_hours ELSE NULL END").to_f
1359 1359
          if average == 0
1360 1360
            average = 1
1361 1361
          end
test/unit/issue_nested_set_test.rb
338 338
  def test_parent_done_ratio_with_child_estimate_to_0_should_reach_100
339 339
    parent = Issue.generate!
340 340
    issue1 = Issue.generate!(:parent_issue_id => parent.id)
341
    issue2 = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 0)
341
    issue2 = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 10)
342
    issue3 = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 0)
342 343
    assert_equal 0, parent.reload.done_ratio
343 344
    issue1.reload.update_attribute :status_id, 5
344
    assert_equal 50, parent.reload.done_ratio
345
    assert_equal 33, parent.reload.done_ratio
345 346
    issue2.reload.update_attribute :status_id, 5
347
    assert_equal 67, parent.reload.done_ratio
348
    issue3.reload.update_attribute :status_id, 5
346 349
    assert_equal 100, parent.reload.done_ratio
347 350
  end
    (1-1/1)