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