Mercurial > hg > soundsoftware-site
comparison test/unit/version_test.rb @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | bb32da3bea34 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2013 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
35 assert !v.valid? | 35 assert !v.valid? |
36 v.effective_date = '2012-11-33' | 36 v.effective_date = '2012-11-33' |
37 assert !v.valid? | 37 assert !v.valid? |
38 v.effective_date = '2012-31-11' | 38 v.effective_date = '2012-31-11' |
39 assert !v.valid? | 39 assert !v.valid? |
40 v.effective_date = '-2012-31-11' | |
41 assert !v.valid? | |
40 v.effective_date = 'ABC' | 42 v.effective_date = 'ABC' |
41 assert !v.valid? | 43 assert !v.valid? |
42 assert_include I18n.translate('activerecord.errors.messages.not_a_date'), | 44 assert_include I18n.translate('activerecord.errors.messages.not_a_date'), |
43 v.errors[:effective_date] | 45 v.errors[:effective_date] |
44 end | 46 end |
45 | 47 |
46 def test_progress_should_be_0_with_no_assigned_issues | 48 def test_progress_should_be_0_with_no_assigned_issues |
47 project = Project.find(1) | 49 project = Project.find(1) |
48 v = Version.create!(:project => project, :name => 'Progress') | 50 v = Version.create!(:project => project, :name => 'Progress') |
49 assert_equal 0, v.completed_pourcent | 51 assert_equal 0, v.completed_percent |
50 assert_equal 0, v.closed_pourcent | 52 assert_equal 0, v.closed_percent |
51 end | 53 end |
52 | 54 |
53 def test_progress_should_be_0_with_unbegun_assigned_issues | 55 def test_progress_should_be_0_with_unbegun_assigned_issues |
54 project = Project.find(1) | 56 project = Project.find(1) |
55 v = Version.create!(:project => project, :name => 'Progress') | 57 v = Version.create!(:project => project, :name => 'Progress') |
56 add_issue(v) | 58 add_issue(v) |
57 add_issue(v, :done_ratio => 0) | 59 add_issue(v, :done_ratio => 0) |
58 assert_progress_equal 0, v.completed_pourcent | 60 assert_progress_equal 0, v.completed_percent |
59 assert_progress_equal 0, v.closed_pourcent | 61 assert_progress_equal 0, v.closed_percent |
60 end | 62 end |
61 | 63 |
62 def test_progress_should_be_100_with_closed_assigned_issues | 64 def test_progress_should_be_100_with_closed_assigned_issues |
63 project = Project.find(1) | 65 project = Project.find(1) |
64 status = IssueStatus.find(:first, :conditions => {:is_closed => true}) | 66 status = IssueStatus.where(:is_closed => true).first |
65 v = Version.create!(:project => project, :name => 'Progress') | 67 v = Version.create!(:project => project, :name => 'Progress') |
66 add_issue(v, :status => status) | 68 add_issue(v, :status => status) |
67 add_issue(v, :status => status, :done_ratio => 20) | 69 add_issue(v, :status => status, :done_ratio => 20) |
68 add_issue(v, :status => status, :done_ratio => 70, :estimated_hours => 25) | 70 add_issue(v, :status => status, :done_ratio => 70, :estimated_hours => 25) |
69 add_issue(v, :status => status, :estimated_hours => 15) | 71 add_issue(v, :status => status, :estimated_hours => 15) |
70 assert_progress_equal 100.0, v.completed_pourcent | 72 assert_progress_equal 100.0, v.completed_percent |
71 assert_progress_equal 100.0, v.closed_pourcent | 73 assert_progress_equal 100.0, v.closed_percent |
72 end | 74 end |
73 | 75 |
74 def test_progress_should_consider_done_ratio_of_open_assigned_issues | 76 def test_progress_should_consider_done_ratio_of_open_assigned_issues |
75 project = Project.find(1) | 77 project = Project.find(1) |
76 v = Version.create!(:project => project, :name => 'Progress') | 78 v = Version.create!(:project => project, :name => 'Progress') |
77 add_issue(v) | 79 add_issue(v) |
78 add_issue(v, :done_ratio => 20) | 80 add_issue(v, :done_ratio => 20) |
79 add_issue(v, :done_ratio => 70) | 81 add_issue(v, :done_ratio => 70) |
80 assert_progress_equal (0.0 + 20.0 + 70.0)/3, v.completed_pourcent | 82 assert_progress_equal (0.0 + 20.0 + 70.0)/3, v.completed_percent |
81 assert_progress_equal 0, v.closed_pourcent | 83 assert_progress_equal 0, v.closed_percent |
82 end | 84 end |
83 | 85 |
84 def test_progress_should_consider_closed_issues_as_completed | 86 def test_progress_should_consider_closed_issues_as_completed |
85 project = Project.find(1) | 87 project = Project.find(1) |
86 v = Version.create!(:project => project, :name => 'Progress') | 88 v = Version.create!(:project => project, :name => 'Progress') |
87 add_issue(v) | 89 add_issue(v) |
88 add_issue(v, :done_ratio => 20) | 90 add_issue(v, :done_ratio => 20) |
89 add_issue(v, :status => IssueStatus.find(:first, :conditions => {:is_closed => true})) | 91 add_issue(v, :status => IssueStatus.where(:is_closed => true).first) |
90 assert_progress_equal (0.0 + 20.0 + 100.0)/3, v.completed_pourcent | 92 assert_progress_equal (0.0 + 20.0 + 100.0)/3, v.completed_percent |
91 assert_progress_equal (100.0)/3, v.closed_pourcent | 93 assert_progress_equal (100.0)/3, v.closed_percent |
92 end | 94 end |
93 | 95 |
94 def test_progress_should_consider_estimated_hours_to_weigth_issues | 96 def test_progress_should_consider_estimated_hours_to_weigth_issues |
95 project = Project.find(1) | 97 project = Project.find(1) |
96 v = Version.create!(:project => project, :name => 'Progress') | 98 v = Version.create!(:project => project, :name => 'Progress') |
97 add_issue(v, :estimated_hours => 10) | 99 add_issue(v, :estimated_hours => 10) |
98 add_issue(v, :estimated_hours => 20, :done_ratio => 30) | 100 add_issue(v, :estimated_hours => 20, :done_ratio => 30) |
99 add_issue(v, :estimated_hours => 40, :done_ratio => 10) | 101 add_issue(v, :estimated_hours => 40, :done_ratio => 10) |
100 add_issue(v, :estimated_hours => 25, :status => IssueStatus.find(:first, :conditions => {:is_closed => true})) | 102 add_issue(v, :estimated_hours => 25, :status => IssueStatus.where(:is_closed => true).first) |
101 assert_progress_equal (10.0*0 + 20.0*0.3 + 40*0.1 + 25.0*1)/95.0*100, v.completed_pourcent | 103 assert_progress_equal (10.0*0 + 20.0*0.3 + 40*0.1 + 25.0*1)/95.0*100, v.completed_percent |
102 assert_progress_equal 25.0/95.0*100, v.closed_pourcent | 104 assert_progress_equal 25.0/95.0*100, v.closed_percent |
103 end | 105 end |
104 | 106 |
105 def test_progress_should_consider_average_estimated_hours_to_weigth_unestimated_issues | 107 def test_progress_should_consider_average_estimated_hours_to_weigth_unestimated_issues |
106 project = Project.find(1) | 108 project = Project.find(1) |
107 v = Version.create!(:project => project, :name => 'Progress') | 109 v = Version.create!(:project => project, :name => 'Progress') |
108 add_issue(v, :done_ratio => 20) | 110 add_issue(v, :done_ratio => 20) |
109 add_issue(v, :status => IssueStatus.find(:first, :conditions => {:is_closed => true})) | 111 add_issue(v, :status => IssueStatus.where(:is_closed => true).first) |
110 add_issue(v, :estimated_hours => 10, :done_ratio => 30) | 112 add_issue(v, :estimated_hours => 10, :done_ratio => 30) |
111 add_issue(v, :estimated_hours => 40, :done_ratio => 10) | 113 add_issue(v, :estimated_hours => 40, :done_ratio => 10) |
112 assert_progress_equal (25.0*0.2 + 25.0*1 + 10.0*0.3 + 40.0*0.1)/100.0*100, v.completed_pourcent | 114 assert_progress_equal (25.0*0.2 + 25.0*1 + 10.0*0.3 + 40.0*0.1)/100.0*100, v.completed_percent |
113 assert_progress_equal 25.0/100.0*100, v.closed_pourcent | 115 assert_progress_equal 25.0/100.0*100, v.closed_percent |
114 end | 116 end |
115 | 117 |
116 def test_should_sort_scheduled_then_unscheduled_versions | 118 def test_should_sort_scheduled_then_unscheduled_versions |
117 Version.delete_all | 119 Version.delete_all |
118 v4 = Version.create!(:project_id => 1, :name => 'v4') | 120 v4 = Version.create!(:project_id => 1, :name => 'v4') |
150 | 152 |
151 should "be false if all of the issues are ahead of schedule" do | 153 should "be false if all of the issues are ahead of schedule" do |
152 @version.update_attribute(:effective_date, 7.days.from_now.to_date) | 154 @version.update_attribute(:effective_date, 7.days.from_now.to_date) |
153 add_issue(@version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left | 155 add_issue(@version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left |
154 add_issue(@version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left | 156 add_issue(@version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left |
155 assert_equal 60, @version.completed_pourcent | 157 assert_equal 60, @version.completed_percent |
156 assert_equal false, @version.behind_schedule? | 158 assert_equal false, @version.behind_schedule? |
157 end | 159 end |
158 | 160 |
159 should "be true if any of the issues are behind schedule" do | 161 should "be true if any of the issues are behind schedule" do |
160 @version.update_attribute(:effective_date, 7.days.from_now.to_date) | 162 @version.update_attribute(:effective_date, 7.days.from_now.to_date) |
161 add_issue(@version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left | 163 add_issue(@version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left |
162 add_issue(@version, :start_date => 7.days.ago, :done_ratio => 20) # 14 day span, 20% done, 50% time left | 164 add_issue(@version, :start_date => 7.days.ago, :done_ratio => 20) # 14 day span, 20% done, 50% time left |
163 assert_equal 40, @version.completed_pourcent | 165 assert_equal 40, @version.completed_percent |
164 assert_equal true, @version.behind_schedule? | 166 assert_equal true, @version.behind_schedule? |
165 end | 167 end |
166 | 168 |
167 should "be false if all of the issues are complete" do | 169 should "be false if all of the issues are complete" do |
168 @version.update_attribute(:effective_date, 7.days.from_now.to_date) | 170 @version.update_attribute(:effective_date, 7.days.from_now.to_date) |
169 add_issue(@version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span | 171 add_issue(@version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span |
170 add_issue(@version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span | 172 add_issue(@version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span |
171 assert_equal 100, @version.completed_pourcent | 173 assert_equal 100, @version.completed_percent |
172 assert_equal false, @version.behind_schedule? | 174 assert_equal false, @version.behind_schedule? |
173 end | 175 end |
174 end | 176 end |
175 | 177 |
176 context "#estimated_hours" do | 178 context "#estimated_hours" do |
240 | 242 |
241 def add_issue(version, attributes={}) | 243 def add_issue(version, attributes={}) |
242 Issue.create!({:project => version.project, | 244 Issue.create!({:project => version.project, |
243 :fixed_version => version, | 245 :fixed_version => version, |
244 :subject => 'Test', | 246 :subject => 'Test', |
245 :author => User.find(:first), | 247 :author => User.first, |
246 :tracker => version.project.trackers.find(:first)}.merge(attributes)) | 248 :tracker => version.project.trackers.first}.merge(attributes)) |
247 end | 249 end |
248 | 250 |
249 def assert_progress_equal(expected_float, actual_float, message="") | 251 def assert_progress_equal(expected_float, actual_float, message="") |
250 assert_in_delta(expected_float, actual_float, 0.000001, message="") | 252 assert_in_delta(expected_float, actual_float, 0.000001, message="") |
251 end | 253 end |