@@ -1,240 +1,245 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class VersionTest < ActiveSupport::TestCase |
|
21 |
fixtures :projects, :users, :issues, :issue_statuses, :trackers, |
|
|
21 | fixtures :projects, :users, :issues, :issue_statuses, :trackers, | |
|
22 | :enumerations, :versions, :projects_trackers | |
|
22 | 23 | |
|
23 | 24 | def test_create |
|
24 |
v = Version.new(:project => Project.find(1), :name => '1.1', |
|
|
25 | v = Version.new(:project => Project.find(1), :name => '1.1', | |
|
26 | :effective_date => '2011-03-25') | |
|
25 | 27 | assert v.save |
|
26 | 28 | assert_equal 'open', v.status |
|
27 | 29 | assert_equal 'none', v.sharing |
|
28 | 30 | end |
|
29 | 31 | |
|
30 | 32 | def test_invalid_effective_date_validation |
|
31 |
v = Version.new(:project => Project.find(1), :name => '1.1', |
|
|
33 | v = Version.new(:project => Project.find(1), :name => '1.1', | |
|
34 | :effective_date => '99999-01-01') | |
|
32 | 35 | assert !v.valid? |
|
33 | 36 | v.effective_date = '2012-11-33' |
|
34 | 37 | assert !v.valid? |
|
35 | 38 | v.effective_date = '2012-31-11' |
|
36 | 39 | assert !v.valid? |
|
37 | 40 | v.effective_date = '-2012-31-11' |
|
38 | 41 | assert !v.valid? |
|
39 | 42 | v.effective_date = 'ABC' |
|
40 | 43 | assert !v.valid? |
|
41 | 44 | assert_include I18n.translate('activerecord.errors.messages.not_a_date'), |
|
42 | 45 | v.errors[:effective_date] |
|
43 | 46 | end |
|
44 | 47 | |
|
45 | 48 | def test_progress_should_be_0_with_no_assigned_issues |
|
46 | 49 | project = Project.find(1) |
|
47 | 50 | v = Version.create!(:project => project, :name => 'Progress') |
|
48 | 51 | assert_equal 0, v.completed_percent |
|
49 | 52 | assert_equal 0, v.closed_percent |
|
50 | 53 | end |
|
51 | 54 | |
|
52 | 55 | def test_progress_should_be_0_with_unbegun_assigned_issues |
|
53 | 56 | project = Project.find(1) |
|
54 | 57 | v = Version.create!(:project => project, :name => 'Progress') |
|
55 | 58 | add_issue(v) |
|
56 | 59 | add_issue(v, :done_ratio => 0) |
|
57 | 60 | assert_progress_equal 0, v.completed_percent |
|
58 | 61 | assert_progress_equal 0, v.closed_percent |
|
59 | 62 | end |
|
60 | 63 | |
|
61 | 64 | def test_progress_should_be_100_with_closed_assigned_issues |
|
62 | 65 | project = Project.find(1) |
|
63 | 66 | status = IssueStatus.where(:is_closed => true).first |
|
64 | 67 | v = Version.create!(:project => project, :name => 'Progress') |
|
65 | 68 | add_issue(v, :status => status) |
|
66 | 69 | add_issue(v, :status => status, :done_ratio => 20) |
|
67 | 70 | add_issue(v, :status => status, :done_ratio => 70, :estimated_hours => 25) |
|
68 | 71 | add_issue(v, :status => status, :estimated_hours => 15) |
|
69 | 72 | assert_progress_equal 100.0, v.completed_percent |
|
70 | 73 | assert_progress_equal 100.0, v.closed_percent |
|
71 | 74 | end |
|
72 | 75 | |
|
73 | 76 | def test_progress_should_consider_done_ratio_of_open_assigned_issues |
|
74 | 77 | project = Project.find(1) |
|
75 | 78 | v = Version.create!(:project => project, :name => 'Progress') |
|
76 | 79 | add_issue(v) |
|
77 | 80 | add_issue(v, :done_ratio => 20) |
|
78 | 81 | add_issue(v, :done_ratio => 70) |
|
79 | 82 | assert_progress_equal (0.0 + 20.0 + 70.0)/3, v.completed_percent |
|
80 | 83 | assert_progress_equal 0, v.closed_percent |
|
81 | 84 | end |
|
82 | 85 | |
|
83 | 86 | def test_progress_should_consider_closed_issues_as_completed |
|
84 | 87 | project = Project.find(1) |
|
85 | 88 | v = Version.create!(:project => project, :name => 'Progress') |
|
86 | 89 | add_issue(v) |
|
87 | 90 | add_issue(v, :done_ratio => 20) |
|
88 | 91 | add_issue(v, :status => IssueStatus.where(:is_closed => true).first) |
|
89 | 92 | assert_progress_equal (0.0 + 20.0 + 100.0)/3, v.completed_percent |
|
90 | 93 | assert_progress_equal (100.0)/3, v.closed_percent |
|
91 | 94 | end |
|
92 | 95 | |
|
93 | 96 | def test_progress_should_consider_estimated_hours_to_weigth_issues |
|
94 | 97 | project = Project.find(1) |
|
95 | 98 | v = Version.create!(:project => project, :name => 'Progress') |
|
96 | 99 | add_issue(v, :estimated_hours => 10) |
|
97 | 100 | add_issue(v, :estimated_hours => 20, :done_ratio => 30) |
|
98 | 101 | add_issue(v, :estimated_hours => 40, :done_ratio => 10) |
|
99 | 102 | add_issue(v, :estimated_hours => 25, :status => IssueStatus.where(:is_closed => true).first) |
|
100 | 103 | assert_progress_equal (10.0*0 + 20.0*0.3 + 40*0.1 + 25.0*1)/95.0*100, v.completed_percent |
|
101 | 104 | assert_progress_equal 25.0/95.0*100, v.closed_percent |
|
102 | 105 | end |
|
103 | 106 | |
|
104 | 107 | def test_progress_should_consider_average_estimated_hours_to_weigth_unestimated_issues |
|
105 | 108 | project = Project.find(1) |
|
106 | 109 | v = Version.create!(:project => project, :name => 'Progress') |
|
107 | 110 | add_issue(v, :done_ratio => 20) |
|
108 | 111 | add_issue(v, :status => IssueStatus.where(:is_closed => true).first) |
|
109 | 112 | add_issue(v, :estimated_hours => 10, :done_ratio => 30) |
|
110 | 113 | add_issue(v, :estimated_hours => 40, :done_ratio => 10) |
|
111 | 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 |
|
112 | 115 | assert_progress_equal 25.0/100.0*100, v.closed_percent |
|
113 | 116 | end |
|
114 | 117 | |
|
115 | 118 | def test_should_sort_scheduled_then_unscheduled_versions |
|
116 | 119 | Version.delete_all |
|
117 | 120 | v4 = Version.create!(:project_id => 1, :name => 'v4') |
|
118 | 121 | v3 = Version.create!(:project_id => 1, :name => 'v2', :effective_date => '2012-07-14') |
|
119 | 122 | v2 = Version.create!(:project_id => 1, :name => 'v1') |
|
120 | 123 | v1 = Version.create!(:project_id => 1, :name => 'v3', :effective_date => '2012-08-02') |
|
121 | 124 | v5 = Version.create!(:project_id => 1, :name => 'v5', :effective_date => '2012-07-02') |
|
122 | 125 | |
|
123 | 126 | assert_equal [v5, v3, v1, v2, v4], [v1, v2, v3, v4, v5].sort |
|
124 | 127 | assert_equal [v5, v3, v1, v2, v4], Version.sorted.all |
|
125 | 128 | end |
|
126 | 129 | |
|
127 | 130 | def test_completed_should_be_false_when_due_today |
|
128 | 131 | version = Version.create!(:project_id => 1, :effective_date => Date.today, :name => 'Due today') |
|
129 | 132 | assert_equal false, version.completed? |
|
130 | 133 | end |
|
131 | 134 | |
|
132 | 135 | test "#behind_schedule? should be false if there are no issues assigned" do |
|
133 | 136 | version = Version.generate!(:effective_date => Date.yesterday) |
|
134 | 137 | assert_equal false, version.behind_schedule? |
|
135 | 138 | end |
|
136 | 139 | |
|
137 | 140 | test "#behind_schedule? should be false if there is no effective_date" do |
|
138 | 141 | version = Version.generate!(:effective_date => nil) |
|
139 | 142 | assert_equal false, version.behind_schedule? |
|
140 | 143 | end |
|
141 | 144 | |
|
142 | 145 | test "#behind_schedule? should be false if all of the issues are ahead of schedule" do |
|
143 | 146 | version = Version.create!(:project_id => 1, :name => 'test', :effective_date => 7.days.from_now.to_date) |
|
144 | 147 | add_issue(version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left |
|
145 | 148 | add_issue(version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left |
|
146 | 149 | assert_equal 60, version.completed_percent |
|
147 | 150 | assert_equal false, version.behind_schedule? |
|
148 | 151 | end |
|
149 | 152 | |
|
150 | 153 | test "#behind_schedule? should be true if any of the issues are behind schedule" do |
|
151 | 154 | version = Version.create!(:project_id => 1, :name => 'test', :effective_date => 7.days.from_now.to_date) |
|
152 | 155 | add_issue(version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left |
|
153 | 156 | add_issue(version, :start_date => 7.days.ago, :done_ratio => 20) # 14 day span, 20% done, 50% time left |
|
154 | 157 | assert_equal 40, version.completed_percent |
|
155 | 158 | assert_equal true, version.behind_schedule? |
|
156 | 159 | end |
|
157 | 160 | |
|
158 | 161 | test "#behind_schedule? should be false if all of the issues are complete" do |
|
159 | 162 | version = Version.create!(:project_id => 1, :name => 'test', :effective_date => 7.days.from_now.to_date) |
|
160 | 163 | add_issue(version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span |
|
161 | 164 | add_issue(version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span |
|
162 | 165 | assert_equal 100, version.completed_percent |
|
163 | 166 | assert_equal false, version.behind_schedule? |
|
164 | 167 | end |
|
165 | 168 | |
|
166 | 169 | test "#estimated_hours should return 0 with no assigned issues" do |
|
167 | 170 | version = Version.generate! |
|
168 | 171 | assert_equal 0, version.estimated_hours |
|
169 | 172 | end |
|
170 | 173 | |
|
171 | 174 | test "#estimated_hours should return 0 with no estimated hours" do |
|
172 | 175 | version = Version.create!(:project_id => 1, :name => 'test') |
|
173 | 176 | add_issue(version) |
|
174 | 177 | assert_equal 0, version.estimated_hours |
|
175 | 178 | end |
|
176 | 179 | |
|
177 | 180 | test "#estimated_hours should return return the sum of estimated hours" do |
|
178 | 181 | version = Version.create!(:project_id => 1, :name => 'test') |
|
179 | 182 | add_issue(version, :estimated_hours => 2.5) |
|
180 | 183 | add_issue(version, :estimated_hours => 5) |
|
181 | 184 | assert_equal 7.5, version.estimated_hours |
|
182 | 185 | end |
|
183 | 186 | |
|
184 | 187 | test "#estimated_hours should return the sum of leaves estimated hours" do |
|
185 | 188 | version = Version.create!(:project_id => 1, :name => 'test') |
|
186 | 189 | parent = add_issue(version) |
|
187 | 190 | add_issue(version, :estimated_hours => 2.5, :parent_issue_id => parent.id) |
|
188 | 191 | add_issue(version, :estimated_hours => 5, :parent_issue_id => parent.id) |
|
189 | 192 | assert_equal 7.5, version.estimated_hours |
|
190 | 193 | end |
|
191 | 194 | |
|
192 | 195 | test "should update all issue's fixed_version associations in case the hierarchy changed XXX" do |
|
193 | 196 | User.current = User.find(1) # Need the admin's permissions |
|
194 | 197 | |
|
195 | 198 | @version = Version.find(7) |
|
196 | 199 | # Separate hierarchy |
|
197 | 200 | project_1_issue = Issue.find(1) |
|
198 | 201 | project_1_issue.fixed_version = @version |
|
199 | 202 | assert project_1_issue.save, project_1_issue.errors.full_messages.to_s |
|
200 | 203 | |
|
201 | 204 | project_5_issue = Issue.find(6) |
|
202 | 205 | project_5_issue.fixed_version = @version |
|
203 | 206 | assert project_5_issue.save |
|
204 | 207 | |
|
205 | 208 | # Project |
|
206 | 209 | project_2_issue = Issue.find(4) |
|
207 | 210 | project_2_issue.fixed_version = @version |
|
208 | 211 | assert project_2_issue.save |
|
209 | 212 | |
|
210 | 213 | # Update the sharing |
|
211 | 214 | @version.sharing = 'none' |
|
212 | 215 | assert @version.save |
|
213 | 216 | |
|
214 | 217 | # Project 1 now out of the shared scope |
|
215 | 218 | project_1_issue.reload |
|
216 |
assert_equal nil, project_1_issue.fixed_version, |
|
|
219 | assert_equal nil, project_1_issue.fixed_version, | |
|
220 | "Fixed version is still set after changing the Version's sharing" | |
|
217 | 221 | |
|
218 | 222 | # Project 5 now out of the shared scope |
|
219 | 223 | project_5_issue.reload |
|
220 |
assert_equal nil, project_5_issue.fixed_version, |
|
|
224 | assert_equal nil, project_5_issue.fixed_version, | |
|
225 | "Fixed version is still set after changing the Version's sharing" | |
|
221 | 226 | |
|
222 | 227 | # Project 2 issue remains |
|
223 | 228 | project_2_issue.reload |
|
224 | 229 | assert_equal @version, project_2_issue.fixed_version |
|
225 | 230 | end |
|
226 | 231 | |
|
227 | 232 | private |
|
228 | 233 | |
|
229 | 234 | def add_issue(version, attributes={}) |
|
230 | 235 | Issue.create!({:project => version.project, |
|
231 | 236 | :fixed_version => version, |
|
232 | 237 | :subject => 'Test', |
|
233 | 238 | :author => User.first, |
|
234 | 239 | :tracker => version.project.trackers.first}.merge(attributes)) |
|
235 | 240 | end |
|
236 | 241 | |
|
237 | 242 | def assert_progress_equal(expected_float, actual_float, message="") |
|
238 | 243 | assert_in_delta(expected_float, actual_float, 0.000001, message="") |
|
239 | 244 | end |
|
240 | 245 | end |
General Comments 0
You need to be logged in to leave comments.
Login now