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