Project

General

Profile

Defect #23151 ยป test.rb

Test file highlighting the problem - Gregor Schmidt, 2016-06-23 15:25

 
1
require File.expand_path('../../test_helper', __FILE__)
2

    
3
class IssueSubtaskingTest < ActiveSupport::TestCase
4
  fixtures :projects, :users, :roles, :members, :member_roles,
5
           :trackers, :projects_trackers,
6
           :issue_statuses, :issue_categories, :enumerations,
7
           :issues,
8
           :enabled_modules,
9
           :workflows
10

    
11
  def test_parent_done_ratio_with_estimated_hours_and_multiple_levels_of_children
12
    with_settings :parent_issue_done_ratio => 'derived' do
13
      #
14
      # [1_0_0]             - (3h)
15
      #  | |
16
      #  | +- [1_1_0]       - 1h
17
      #  |
18
      #  +--- [1_2_0]       - (2h)
19
      #        | |
20
      #        | +- [1_2_1] - 1h
21
      #        |
22
      #        +--- [1_2_1] - 1h
23
      #
24
      # If 1_1_0 is done (i.e. Status == closed || done_ratio == 100), then 1h
25
      # out of 3h of work on the sub tasks are completed. So 1_0_0's done_ratio
26
      # should be (1 / 3) == 33 %.
27

    
28
      issue_1_0_0 = Issue.generate!
29
      issue_1_1_0 = issue_1_0_0.generate_child!(:estimated_hours => 1)
30
      issue_1_2_0 = issue_1_0_0.generate_child!
31
      issue_1_2_1 = issue_1_2_0.generate_child!(:estimated_hours => 1)
32
      issue_1_2_2 = issue_1_2_0.generate_child!(:estimated_hours => 1)
33

    
34
      issue_1_1_0.update(:done_ratio => 100)
35

    
36
      issue_1_0_0.reload
37

    
38
      assert_equal 33, issue_1_0_0.done_ratio
39
    end
40
  end
41

    
42
  def test_parent_done_ratio_with_estimated_hours_and_multiple_levels_of_children_part_two
43
    with_settings :parent_issue_done_ratio => 'derived' do
44
      #
45
      # [1_0_0]             - 1h (Total 5h)
46
      #  | |
47
      #  | +- [1_1_0]       - 1h (Total 1h)
48
      #  |
49
      #  +--- [1_2_0]       - 1h (Total 3h)
50
      #        | |
51
      #        | +- [1_2_1] - 1h (Total 1h)
52
      #        |
53
      #        +--- [1_2_1] - 1h (Total 1h)
54
      #
55
      # If 1_1_0 is done (i.e. Status == closed || done_ratio == 100), then 1h
56
      # out of 4h of work on the sub tasks are completed. So 1_0_0's done_ratio
57
      # should be (1 / 4) == 25 %.
58

    
59
      issue_1_0_0 = Issue.generate!(:estimated_hours => 1)
60
      issue_1_1_0 = issue_1_0_0.generate_child!(:estimated_hours => 1)
61
      issue_1_2_0 = issue_1_0_0.generate_child!(:estimated_hours => 1)
62
      issue_1_2_1 = issue_1_2_0.generate_child!(:estimated_hours => 1)
63
      issue_1_2_2 = issue_1_2_0.generate_child!(:estimated_hours => 1)
64

    
65
      issue_1_1_0.update(:done_ratio => 100)
66

    
67
      issue_1_0_0.reload
68

    
69
      assert_equal 25, issue_1_0_0.done_ratio
70
    end
71
  end
72
end
    (1-1/1)