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