##// END OF EJS Templates
remove empty setup method from VersionTest...
Toshi MARUYAMA -
r11650:bbca694881b9
parent child
Show More
@@ -1,243 +1,240
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 21 fixtures :projects, :users, :issues, :issue_statuses, :trackers, :enumerations, :versions, :projects_trackers
22 22
23 def setup
24 end
25
26 23 def test_create
27 24 v = Version.new(:project => Project.find(1), :name => '1.1', :effective_date => '2011-03-25')
28 25 assert v.save
29 26 assert_equal 'open', v.status
30 27 assert_equal 'none', v.sharing
31 28 end
32 29
33 30 def test_invalid_effective_date_validation
34 31 v = Version.new(:project => Project.find(1), :name => '1.1', :effective_date => '99999-01-01')
35 32 assert !v.valid?
36 33 v.effective_date = '2012-11-33'
37 34 assert !v.valid?
38 35 v.effective_date = '2012-31-11'
39 36 assert !v.valid?
40 37 v.effective_date = '-2012-31-11'
41 38 assert !v.valid?
42 39 v.effective_date = 'ABC'
43 40 assert !v.valid?
44 41 assert_include I18n.translate('activerecord.errors.messages.not_a_date'),
45 42 v.errors[:effective_date]
46 43 end
47 44
48 45 def test_progress_should_be_0_with_no_assigned_issues
49 46 project = Project.find(1)
50 47 v = Version.create!(:project => project, :name => 'Progress')
51 48 assert_equal 0, v.completed_percent
52 49 assert_equal 0, v.closed_percent
53 50 end
54 51
55 52 def test_progress_should_be_0_with_unbegun_assigned_issues
56 53 project = Project.find(1)
57 54 v = Version.create!(:project => project, :name => 'Progress')
58 55 add_issue(v)
59 56 add_issue(v, :done_ratio => 0)
60 57 assert_progress_equal 0, v.completed_percent
61 58 assert_progress_equal 0, v.closed_percent
62 59 end
63 60
64 61 def test_progress_should_be_100_with_closed_assigned_issues
65 62 project = Project.find(1)
66 63 status = IssueStatus.where(:is_closed => true).first
67 64 v = Version.create!(:project => project, :name => 'Progress')
68 65 add_issue(v, :status => status)
69 66 add_issue(v, :status => status, :done_ratio => 20)
70 67 add_issue(v, :status => status, :done_ratio => 70, :estimated_hours => 25)
71 68 add_issue(v, :status => status, :estimated_hours => 15)
72 69 assert_progress_equal 100.0, v.completed_percent
73 70 assert_progress_equal 100.0, v.closed_percent
74 71 end
75 72
76 73 def test_progress_should_consider_done_ratio_of_open_assigned_issues
77 74 project = Project.find(1)
78 75 v = Version.create!(:project => project, :name => 'Progress')
79 76 add_issue(v)
80 77 add_issue(v, :done_ratio => 20)
81 78 add_issue(v, :done_ratio => 70)
82 79 assert_progress_equal (0.0 + 20.0 + 70.0)/3, v.completed_percent
83 80 assert_progress_equal 0, v.closed_percent
84 81 end
85 82
86 83 def test_progress_should_consider_closed_issues_as_completed
87 84 project = Project.find(1)
88 85 v = Version.create!(:project => project, :name => 'Progress')
89 86 add_issue(v)
90 87 add_issue(v, :done_ratio => 20)
91 88 add_issue(v, :status => IssueStatus.where(:is_closed => true).first)
92 89 assert_progress_equal (0.0 + 20.0 + 100.0)/3, v.completed_percent
93 90 assert_progress_equal (100.0)/3, v.closed_percent
94 91 end
95 92
96 93 def test_progress_should_consider_estimated_hours_to_weigth_issues
97 94 project = Project.find(1)
98 95 v = Version.create!(:project => project, :name => 'Progress')
99 96 add_issue(v, :estimated_hours => 10)
100 97 add_issue(v, :estimated_hours => 20, :done_ratio => 30)
101 98 add_issue(v, :estimated_hours => 40, :done_ratio => 10)
102 99 add_issue(v, :estimated_hours => 25, :status => IssueStatus.where(:is_closed => true).first)
103 100 assert_progress_equal (10.0*0 + 20.0*0.3 + 40*0.1 + 25.0*1)/95.0*100, v.completed_percent
104 101 assert_progress_equal 25.0/95.0*100, v.closed_percent
105 102 end
106 103
107 104 def test_progress_should_consider_average_estimated_hours_to_weigth_unestimated_issues
108 105 project = Project.find(1)
109 106 v = Version.create!(:project => project, :name => 'Progress')
110 107 add_issue(v, :done_ratio => 20)
111 108 add_issue(v, :status => IssueStatus.where(:is_closed => true).first)
112 109 add_issue(v, :estimated_hours => 10, :done_ratio => 30)
113 110 add_issue(v, :estimated_hours => 40, :done_ratio => 10)
114 111 assert_progress_equal (25.0*0.2 + 25.0*1 + 10.0*0.3 + 40.0*0.1)/100.0*100, v.completed_percent
115 112 assert_progress_equal 25.0/100.0*100, v.closed_percent
116 113 end
117 114
118 115 def test_should_sort_scheduled_then_unscheduled_versions
119 116 Version.delete_all
120 117 v4 = Version.create!(:project_id => 1, :name => 'v4')
121 118 v3 = Version.create!(:project_id => 1, :name => 'v2', :effective_date => '2012-07-14')
122 119 v2 = Version.create!(:project_id => 1, :name => 'v1')
123 120 v1 = Version.create!(:project_id => 1, :name => 'v3', :effective_date => '2012-08-02')
124 121 v5 = Version.create!(:project_id => 1, :name => 'v5', :effective_date => '2012-07-02')
125 122
126 123 assert_equal [v5, v3, v1, v2, v4], [v1, v2, v3, v4, v5].sort
127 124 assert_equal [v5, v3, v1, v2, v4], Version.sorted.all
128 125 end
129 126
130 127 def test_completed_should_be_false_when_due_today
131 128 version = Version.create!(:project_id => 1, :effective_date => Date.today, :name => 'Due today')
132 129 assert_equal false, version.completed?
133 130 end
134 131
135 132 test "#behind_schedule? should be false if there are no issues assigned" do
136 133 version = Version.generate!(:effective_date => Date.yesterday)
137 134 assert_equal false, version.behind_schedule?
138 135 end
139 136
140 137 test "#behind_schedule? should be false if there is no effective_date" do
141 138 version = Version.generate!(:effective_date => nil)
142 139 assert_equal false, version.behind_schedule?
143 140 end
144 141
145 142 test "#behind_schedule? should be false if all of the issues are ahead of schedule" do
146 143 version = Version.create!(:project_id => 1, :name => 'test', :effective_date => 7.days.from_now.to_date)
147 144 add_issue(version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left
148 145 add_issue(version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left
149 146 assert_equal 60, version.completed_percent
150 147 assert_equal false, version.behind_schedule?
151 148 end
152 149
153 150 test "#behind_schedule? should be true if any of the issues are behind schedule" do
154 151 version = Version.create!(:project_id => 1, :name => 'test', :effective_date => 7.days.from_now.to_date)
155 152 add_issue(version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left
156 153 add_issue(version, :start_date => 7.days.ago, :done_ratio => 20) # 14 day span, 20% done, 50% time left
157 154 assert_equal 40, version.completed_percent
158 155 assert_equal true, version.behind_schedule?
159 156 end
160 157
161 158 test "#behind_schedule? should be false if all of the issues are complete" do
162 159 version = Version.create!(:project_id => 1, :name => 'test', :effective_date => 7.days.from_now.to_date)
163 160 add_issue(version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span
164 161 add_issue(version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span
165 162 assert_equal 100, version.completed_percent
166 163 assert_equal false, version.behind_schedule?
167 164 end
168 165
169 166 test "#estimated_hours should return 0 with no assigned issues" do
170 167 version = Version.generate!
171 168 assert_equal 0, version.estimated_hours
172 169 end
173 170
174 171 test "#estimated_hours should return 0 with no estimated hours" do
175 172 version = Version.create!(:project_id => 1, :name => 'test')
176 173 add_issue(version)
177 174 assert_equal 0, version.estimated_hours
178 175 end
179 176
180 177 test "#estimated_hours should return return the sum of estimated hours" do
181 178 version = Version.create!(:project_id => 1, :name => 'test')
182 179 add_issue(version, :estimated_hours => 2.5)
183 180 add_issue(version, :estimated_hours => 5)
184 181 assert_equal 7.5, version.estimated_hours
185 182 end
186 183
187 184 test "#estimated_hours should return the sum of leaves estimated hours" do
188 185 version = Version.create!(:project_id => 1, :name => 'test')
189 186 parent = add_issue(version)
190 187 add_issue(version, :estimated_hours => 2.5, :parent_issue_id => parent.id)
191 188 add_issue(version, :estimated_hours => 5, :parent_issue_id => parent.id)
192 189 assert_equal 7.5, version.estimated_hours
193 190 end
194 191
195 192 test "should update all issue's fixed_version associations in case the hierarchy changed XXX" do
196 193 User.current = User.find(1) # Need the admin's permissions
197 194
198 195 @version = Version.find(7)
199 196 # Separate hierarchy
200 197 project_1_issue = Issue.find(1)
201 198 project_1_issue.fixed_version = @version
202 199 assert project_1_issue.save, project_1_issue.errors.full_messages.to_s
203 200
204 201 project_5_issue = Issue.find(6)
205 202 project_5_issue.fixed_version = @version
206 203 assert project_5_issue.save
207 204
208 205 # Project
209 206 project_2_issue = Issue.find(4)
210 207 project_2_issue.fixed_version = @version
211 208 assert project_2_issue.save
212 209
213 210 # Update the sharing
214 211 @version.sharing = 'none'
215 212 assert @version.save
216 213
217 214 # Project 1 now out of the shared scope
218 215 project_1_issue.reload
219 216 assert_equal nil, project_1_issue.fixed_version, "Fixed version is still set after changing the Version's sharing"
220 217
221 218 # Project 5 now out of the shared scope
222 219 project_5_issue.reload
223 220 assert_equal nil, project_5_issue.fixed_version, "Fixed version is still set after changing the Version's sharing"
224 221
225 222 # Project 2 issue remains
226 223 project_2_issue.reload
227 224 assert_equal @version, project_2_issue.fixed_version
228 225 end
229 226
230 227 private
231 228
232 229 def add_issue(version, attributes={})
233 230 Issue.create!({:project => version.project,
234 231 :fixed_version => version,
235 232 :subject => 'Test',
236 233 :author => User.first,
237 234 :tracker => version.project.trackers.first}.merge(attributes))
238 235 end
239 236
240 237 def assert_progress_equal(expected_float, actual_float, message="")
241 238 assert_in_delta(expected_float, actual_float, 0.000001, message="")
242 239 end
243 240 end
General Comments 0
You need to be logged in to leave comments. Login now