@@ -1,592 +1,592 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | |
|
20 | 20 | class IssueTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :projects, :users, :members, :member_roles, :roles, |
|
22 | 22 | :trackers, :projects_trackers, |
|
23 | 23 | :versions, |
|
24 | 24 | :issue_statuses, :issue_categories, :issue_relations, :workflows, |
|
25 | 25 | :enumerations, |
|
26 | 26 | :issues, |
|
27 | 27 | :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, |
|
28 | 28 | :time_entries |
|
29 | 29 | |
|
30 | 30 | def test_create |
|
31 | 31 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create', :description => 'IssueTest#test_create', :estimated_hours => '1:30') |
|
32 | 32 | assert issue.save |
|
33 | 33 | issue.reload |
|
34 | 34 | assert_equal 1.5, issue.estimated_hours |
|
35 | 35 | end |
|
36 | 36 | |
|
37 | 37 | def test_create_minimal |
|
38 | 38 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create') |
|
39 | 39 | assert issue.save |
|
40 | 40 | assert issue.description.nil? |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | 43 | def test_create_with_required_custom_field |
|
44 | 44 | field = IssueCustomField.find_by_name('Database') |
|
45 | 45 | field.update_attribute(:is_required, true) |
|
46 | 46 | |
|
47 | 47 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'test_create', :description => 'IssueTest#test_create_with_required_custom_field') |
|
48 | 48 | assert issue.available_custom_fields.include?(field) |
|
49 | 49 | # No value for the custom field |
|
50 | 50 | assert !issue.save |
|
51 | 51 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) |
|
52 | 52 | # Blank value |
|
53 | 53 | issue.custom_field_values = { field.id => '' } |
|
54 | 54 | assert !issue.save |
|
55 | 55 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) |
|
56 | 56 | # Invalid value |
|
57 | 57 | issue.custom_field_values = { field.id => 'SQLServer' } |
|
58 | 58 | assert !issue.save |
|
59 | 59 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) |
|
60 | 60 | # Valid value |
|
61 | 61 | issue.custom_field_values = { field.id => 'PostgreSQL' } |
|
62 | 62 | assert issue.save |
|
63 | 63 | issue.reload |
|
64 | 64 | assert_equal 'PostgreSQL', issue.custom_value_for(field).value |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | def test_visible_scope_for_anonymous |
|
68 | 68 | # Anonymous user should see issues of public projects only |
|
69 | 69 | issues = Issue.visible(User.anonymous).all |
|
70 | 70 | assert issues.any? |
|
71 | 71 | assert_nil issues.detect {|issue| !issue.project.is_public?} |
|
72 | 72 | # Anonymous user should not see issues without permission |
|
73 | 73 | Role.anonymous.remove_permission!(:view_issues) |
|
74 | 74 | issues = Issue.visible(User.anonymous).all |
|
75 | 75 | assert issues.empty? |
|
76 | 76 | end |
|
77 | 77 | |
|
78 | 78 | def test_visible_scope_for_user |
|
79 | 79 | user = User.find(9) |
|
80 | 80 | assert user.projects.empty? |
|
81 | 81 | # Non member user should see issues of public projects only |
|
82 | 82 | issues = Issue.visible(user).all |
|
83 | 83 | assert issues.any? |
|
84 | 84 | assert_nil issues.detect {|issue| !issue.project.is_public?} |
|
85 | 85 | # Non member user should not see issues without permission |
|
86 | 86 | Role.non_member.remove_permission!(:view_issues) |
|
87 | 87 | user.reload |
|
88 | 88 | issues = Issue.visible(user).all |
|
89 | 89 | assert issues.empty? |
|
90 | 90 | # User should see issues of projects for which he has view_issues permissions only |
|
91 | 91 | Member.create!(:principal => user, :project_id => 2, :role_ids => [1]) |
|
92 | 92 | user.reload |
|
93 | 93 | issues = Issue.visible(user).all |
|
94 | 94 | assert issues.any? |
|
95 | 95 | assert_nil issues.detect {|issue| issue.project_id != 2} |
|
96 | 96 | end |
|
97 | 97 | |
|
98 | 98 | def test_visible_scope_for_admin |
|
99 | 99 | user = User.find(1) |
|
100 | 100 | user.members.each(&:destroy) |
|
101 | 101 | assert user.projects.empty? |
|
102 | 102 | issues = Issue.visible(user).all |
|
103 | 103 | assert issues.any? |
|
104 | 104 | # Admin should see issues on private projects that he does not belong to |
|
105 | 105 | assert issues.detect {|issue| !issue.project.is_public?} |
|
106 | 106 | end |
|
107 | 107 | |
|
108 | 108 | def test_errors_full_messages_should_include_custom_fields_errors |
|
109 | 109 | field = IssueCustomField.find_by_name('Database') |
|
110 | 110 | |
|
111 | 111 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'test_create', :description => 'IssueTest#test_create_with_required_custom_field') |
|
112 | 112 | assert issue.available_custom_fields.include?(field) |
|
113 | 113 | # Invalid value |
|
114 | 114 | issue.custom_field_values = { field.id => 'SQLServer' } |
|
115 | 115 | |
|
116 | 116 | assert !issue.valid? |
|
117 | 117 | assert_equal 1, issue.errors.full_messages.size |
|
118 | 118 | assert_equal "Database #{I18n.translate('activerecord.errors.messages.inclusion')}", issue.errors.full_messages.first |
|
119 | 119 | end |
|
120 | 120 | |
|
121 | 121 | def test_update_issue_with_required_custom_field |
|
122 | 122 | field = IssueCustomField.find_by_name('Database') |
|
123 | 123 | field.update_attribute(:is_required, true) |
|
124 | 124 | |
|
125 | 125 | issue = Issue.find(1) |
|
126 | 126 | assert_nil issue.custom_value_for(field) |
|
127 | 127 | assert issue.available_custom_fields.include?(field) |
|
128 | 128 | # No change to custom values, issue can be saved |
|
129 | 129 | assert issue.save |
|
130 | 130 | # Blank value |
|
131 | 131 | issue.custom_field_values = { field.id => '' } |
|
132 | 132 | assert !issue.save |
|
133 | 133 | # Valid value |
|
134 | 134 | issue.custom_field_values = { field.id => 'PostgreSQL' } |
|
135 | 135 | assert issue.save |
|
136 | 136 | issue.reload |
|
137 | 137 | assert_equal 'PostgreSQL', issue.custom_value_for(field).value |
|
138 | 138 | end |
|
139 | 139 | |
|
140 | 140 | def test_should_not_update_attributes_if_custom_fields_validation_fails |
|
141 | 141 | issue = Issue.find(1) |
|
142 | 142 | field = IssueCustomField.find_by_name('Database') |
|
143 | 143 | assert issue.available_custom_fields.include?(field) |
|
144 | 144 | |
|
145 | 145 | issue.custom_field_values = { field.id => 'Invalid' } |
|
146 | 146 | issue.subject = 'Should be not be saved' |
|
147 | 147 | assert !issue.save |
|
148 | 148 | |
|
149 | 149 | issue.reload |
|
150 | 150 | assert_equal "Can't print recipes", issue.subject |
|
151 | 151 | end |
|
152 | 152 | |
|
153 | 153 | def test_should_not_recreate_custom_values_objects_on_update |
|
154 | 154 | field = IssueCustomField.find_by_name('Database') |
|
155 | 155 | |
|
156 | 156 | issue = Issue.find(1) |
|
157 | 157 | issue.custom_field_values = { field.id => 'PostgreSQL' } |
|
158 | 158 | assert issue.save |
|
159 | 159 | custom_value = issue.custom_value_for(field) |
|
160 | 160 | issue.reload |
|
161 | 161 | issue.custom_field_values = { field.id => 'MySQL' } |
|
162 | 162 | assert issue.save |
|
163 | 163 | issue.reload |
|
164 | 164 | assert_equal custom_value.id, issue.custom_value_for(field).id |
|
165 | 165 | end |
|
166 | 166 | |
|
167 | 167 | def test_assigning_tracker_id_should_reload_custom_fields_values |
|
168 | 168 | issue = Issue.new(:project => Project.find(1)) |
|
169 | 169 | assert issue.custom_field_values.empty? |
|
170 | 170 | issue.tracker_id = 1 |
|
171 | 171 | assert issue.custom_field_values.any? |
|
172 | 172 | end |
|
173 | 173 | |
|
174 | 174 | def test_assigning_attributes_should_assign_tracker_id_first |
|
175 | 175 | attributes = ActiveSupport::OrderedHash.new |
|
176 | 176 | attributes['custom_field_values'] = { '1' => 'MySQL' } |
|
177 | 177 | attributes['tracker_id'] = '1' |
|
178 | 178 | issue = Issue.new(:project => Project.find(1)) |
|
179 | 179 | issue.attributes = attributes |
|
180 | 180 | assert_not_nil issue.custom_value_for(1) |
|
181 | 181 | assert_equal 'MySQL', issue.custom_value_for(1).value |
|
182 | 182 | end |
|
183 | 183 | |
|
184 | 184 | def test_should_update_issue_with_disabled_tracker |
|
185 | 185 | p = Project.find(1) |
|
186 | 186 | issue = Issue.find(1) |
|
187 | 187 | |
|
188 | 188 | p.trackers.delete(issue.tracker) |
|
189 | 189 | assert !p.trackers.include?(issue.tracker) |
|
190 | 190 | |
|
191 | 191 | issue.reload |
|
192 | 192 | issue.subject = 'New subject' |
|
193 | 193 | assert issue.save |
|
194 | 194 | end |
|
195 | 195 | |
|
196 | 196 | def test_should_not_set_a_disabled_tracker |
|
197 | 197 | p = Project.find(1) |
|
198 | 198 | p.trackers.delete(Tracker.find(2)) |
|
199 | 199 | |
|
200 | 200 | issue = Issue.find(1) |
|
201 | 201 | issue.tracker_id = 2 |
|
202 | 202 | issue.subject = 'New subject' |
|
203 | 203 | assert !issue.save |
|
204 | 204 | assert_not_nil issue.errors.on(:tracker_id) |
|
205 | 205 | end |
|
206 | 206 | |
|
207 | 207 | def test_category_based_assignment |
|
208 | 208 | issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1) |
|
209 | 209 | assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to |
|
210 | 210 | end |
|
211 | 211 | |
|
212 | 212 | def test_copy |
|
213 | 213 | issue = Issue.new.copy_from(1) |
|
214 | 214 | assert issue.save |
|
215 | 215 | issue.reload |
|
216 | 216 | orig = Issue.find(1) |
|
217 | 217 | assert_equal orig.subject, issue.subject |
|
218 | 218 | assert_equal orig.tracker, issue.tracker |
|
219 |
assert_equal |
|
|
219 | assert_equal "125", issue.custom_value_for(2).value | |
|
220 | 220 | end |
|
221 | 221 | |
|
222 | 222 | def test_copy_should_copy_status |
|
223 | 223 | orig = Issue.find(8) |
|
224 | 224 | assert orig.status != IssueStatus.default |
|
225 | 225 | |
|
226 | 226 | issue = Issue.new.copy_from(orig) |
|
227 | 227 | assert issue.save |
|
228 | 228 | issue.reload |
|
229 | 229 | assert_equal orig.status, issue.status |
|
230 | 230 | end |
|
231 | 231 | |
|
232 | 232 | def test_should_close_duplicates |
|
233 | 233 | # Create 3 issues |
|
234 | 234 | issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test') |
|
235 | 235 | assert issue1.save |
|
236 | 236 | issue2 = issue1.clone |
|
237 | 237 | assert issue2.save |
|
238 | 238 | issue3 = issue1.clone |
|
239 | 239 | assert issue3.save |
|
240 | 240 | |
|
241 | 241 | # 2 is a dupe of 1 |
|
242 | 242 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
243 | 243 | # And 3 is a dupe of 2 |
|
244 | 244 | IssueRelation.create(:issue_from => issue3, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
245 | 245 | # And 3 is a dupe of 1 (circular duplicates) |
|
246 | 246 | IssueRelation.create(:issue_from => issue3, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
247 | 247 | |
|
248 | 248 | assert issue1.reload.duplicates.include?(issue2) |
|
249 | 249 | |
|
250 | 250 | # Closing issue 1 |
|
251 | 251 | issue1.init_journal(User.find(:first), "Closing issue1") |
|
252 | 252 | issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true} |
|
253 | 253 | assert issue1.save |
|
254 | 254 | # 2 and 3 should be also closed |
|
255 | 255 | assert issue2.reload.closed? |
|
256 | 256 | assert issue3.reload.closed? |
|
257 | 257 | end |
|
258 | 258 | |
|
259 | 259 | def test_should_not_close_duplicated_issue |
|
260 | 260 | # Create 3 issues |
|
261 | 261 | issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test') |
|
262 | 262 | assert issue1.save |
|
263 | 263 | issue2 = issue1.clone |
|
264 | 264 | assert issue2.save |
|
265 | 265 | |
|
266 | 266 | # 2 is a dupe of 1 |
|
267 | 267 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
268 | 268 | # 2 is a dup of 1 but 1 is not a duplicate of 2 |
|
269 | 269 | assert !issue2.reload.duplicates.include?(issue1) |
|
270 | 270 | |
|
271 | 271 | # Closing issue 2 |
|
272 | 272 | issue2.init_journal(User.find(:first), "Closing issue2") |
|
273 | 273 | issue2.status = IssueStatus.find :first, :conditions => {:is_closed => true} |
|
274 | 274 | assert issue2.save |
|
275 | 275 | # 1 should not be also closed |
|
276 | 276 | assert !issue1.reload.closed? |
|
277 | 277 | end |
|
278 | 278 | |
|
279 | 279 | def test_assignable_versions |
|
280 | 280 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, :subject => 'New issue') |
|
281 | 281 | assert_equal ['open'], issue.assignable_versions.collect(&:status).uniq |
|
282 | 282 | end |
|
283 | 283 | |
|
284 | 284 | def test_should_not_be_able_to_assign_a_new_issue_to_a_closed_version |
|
285 | 285 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, :subject => 'New issue') |
|
286 | 286 | assert !issue.save |
|
287 | 287 | assert_not_nil issue.errors.on(:fixed_version_id) |
|
288 | 288 | end |
|
289 | 289 | |
|
290 | 290 | def test_should_not_be_able_to_assign_a_new_issue_to_a_locked_version |
|
291 | 291 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 2, :subject => 'New issue') |
|
292 | 292 | assert !issue.save |
|
293 | 293 | assert_not_nil issue.errors.on(:fixed_version_id) |
|
294 | 294 | end |
|
295 | 295 | |
|
296 | 296 | def test_should_be_able_to_assign_a_new_issue_to_an_open_version |
|
297 | 297 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 3, :subject => 'New issue') |
|
298 | 298 | assert issue.save |
|
299 | 299 | end |
|
300 | 300 | |
|
301 | 301 | def test_should_be_able_to_update_an_issue_assigned_to_a_closed_version |
|
302 | 302 | issue = Issue.find(11) |
|
303 | 303 | assert_equal 'closed', issue.fixed_version.status |
|
304 | 304 | issue.subject = 'Subject changed' |
|
305 | 305 | assert issue.save |
|
306 | 306 | end |
|
307 | 307 | |
|
308 | 308 | def test_should_not_be_able_to_reopen_an_issue_assigned_to_a_closed_version |
|
309 | 309 | issue = Issue.find(11) |
|
310 | 310 | issue.status_id = 1 |
|
311 | 311 | assert !issue.save |
|
312 | 312 | assert_not_nil issue.errors.on_base |
|
313 | 313 | end |
|
314 | 314 | |
|
315 | 315 | def test_should_be_able_to_reopen_and_reassign_an_issue_assigned_to_a_closed_version |
|
316 | 316 | issue = Issue.find(11) |
|
317 | 317 | issue.status_id = 1 |
|
318 | 318 | issue.fixed_version_id = 3 |
|
319 | 319 | assert issue.save |
|
320 | 320 | end |
|
321 | 321 | |
|
322 | 322 | def test_should_be_able_to_reopen_an_issue_assigned_to_a_locked_version |
|
323 | 323 | issue = Issue.find(12) |
|
324 | 324 | assert_equal 'locked', issue.fixed_version.status |
|
325 | 325 | issue.status_id = 1 |
|
326 | 326 | assert issue.save |
|
327 | 327 | end |
|
328 | 328 | |
|
329 | 329 | def test_move_to_another_project_with_same_category |
|
330 | 330 | issue = Issue.find(1) |
|
331 | 331 | assert issue.move_to(Project.find(2)) |
|
332 | 332 | issue.reload |
|
333 | 333 | assert_equal 2, issue.project_id |
|
334 | 334 | # Category changes |
|
335 | 335 | assert_equal 4, issue.category_id |
|
336 | 336 | # Make sure time entries were move to the target project |
|
337 | 337 | assert_equal 2, issue.time_entries.first.project_id |
|
338 | 338 | end |
|
339 | 339 | |
|
340 | 340 | def test_move_to_another_project_without_same_category |
|
341 | 341 | issue = Issue.find(2) |
|
342 | 342 | assert issue.move_to(Project.find(2)) |
|
343 | 343 | issue.reload |
|
344 | 344 | assert_equal 2, issue.project_id |
|
345 | 345 | # Category cleared |
|
346 | 346 | assert_nil issue.category_id |
|
347 | 347 | end |
|
348 | 348 | |
|
349 | 349 | def test_move_to_another_project_should_clear_fixed_version_when_not_shared |
|
350 | 350 | issue = Issue.find(1) |
|
351 | 351 | issue.update_attribute(:fixed_version_id, 1) |
|
352 | 352 | assert issue.move_to(Project.find(2)) |
|
353 | 353 | issue.reload |
|
354 | 354 | assert_equal 2, issue.project_id |
|
355 | 355 | # Cleared fixed_version |
|
356 | 356 | assert_equal nil, issue.fixed_version |
|
357 | 357 | end |
|
358 | 358 | |
|
359 | 359 | def test_move_to_another_project_should_keep_fixed_version_when_shared_with_the_target_project |
|
360 | 360 | issue = Issue.find(1) |
|
361 | 361 | issue.update_attribute(:fixed_version_id, 4) |
|
362 | 362 | assert issue.move_to(Project.find(5)) |
|
363 | 363 | issue.reload |
|
364 | 364 | assert_equal 5, issue.project_id |
|
365 | 365 | # Keep fixed_version |
|
366 | 366 | assert_equal 4, issue.fixed_version_id |
|
367 | 367 | end |
|
368 | 368 | |
|
369 | 369 | def test_move_to_another_project_should_clear_fixed_version_when_not_shared_with_the_target_project |
|
370 | 370 | issue = Issue.find(1) |
|
371 | 371 | issue.update_attribute(:fixed_version_id, 1) |
|
372 | 372 | assert issue.move_to(Project.find(5)) |
|
373 | 373 | issue.reload |
|
374 | 374 | assert_equal 5, issue.project_id |
|
375 | 375 | # Cleared fixed_version |
|
376 | 376 | assert_equal nil, issue.fixed_version |
|
377 | 377 | end |
|
378 | 378 | |
|
379 | 379 | def test_move_to_another_project_should_keep_fixed_version_when_shared_systemwide |
|
380 | 380 | issue = Issue.find(1) |
|
381 | 381 | issue.update_attribute(:fixed_version_id, 7) |
|
382 | 382 | assert issue.move_to(Project.find(2)) |
|
383 | 383 | issue.reload |
|
384 | 384 | assert_equal 2, issue.project_id |
|
385 | 385 | # Keep fixed_version |
|
386 | 386 | assert_equal 7, issue.fixed_version_id |
|
387 | 387 | end |
|
388 | 388 | |
|
389 | 389 | def test_copy_to_the_same_project |
|
390 | 390 | issue = Issue.find(1) |
|
391 | 391 | copy = nil |
|
392 | 392 | assert_difference 'Issue.count' do |
|
393 | 393 | copy = issue.move_to(issue.project, nil, :copy => true) |
|
394 | 394 | end |
|
395 | 395 | assert_kind_of Issue, copy |
|
396 | 396 | assert_equal issue.project, copy.project |
|
397 | 397 | assert_equal "125", copy.custom_value_for(2).value |
|
398 | 398 | end |
|
399 | 399 | |
|
400 | 400 | def test_copy_to_another_project_and_tracker |
|
401 | 401 | issue = Issue.find(1) |
|
402 | 402 | copy = nil |
|
403 | 403 | assert_difference 'Issue.count' do |
|
404 | 404 | copy = issue.move_to(Project.find(3), Tracker.find(2), :copy => true) |
|
405 | 405 | end |
|
406 | 406 | assert_kind_of Issue, copy |
|
407 | 407 | assert_equal Project.find(3), copy.project |
|
408 | 408 | assert_equal Tracker.find(2), copy.tracker |
|
409 | 409 | # Custom field #2 is not associated with target tracker |
|
410 | 410 | assert_nil copy.custom_value_for(2) |
|
411 | 411 | end |
|
412 | 412 | |
|
413 | 413 | context "#move_to" do |
|
414 | 414 | context "as a copy" do |
|
415 | 415 | setup do |
|
416 | 416 | @issue = Issue.find(1) |
|
417 | 417 | @copy = nil |
|
418 | 418 | end |
|
419 | 419 | |
|
420 | 420 | should "allow assigned_to changes" do |
|
421 | 421 | @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}}) |
|
422 | 422 | assert_equal 3, @copy.assigned_to_id |
|
423 | 423 | end |
|
424 | 424 | |
|
425 | 425 | should "allow status changes" do |
|
426 | 426 | @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:status_id => 2}}) |
|
427 | 427 | assert_equal 2, @copy.status_id |
|
428 | 428 | end |
|
429 | 429 | |
|
430 | 430 | should "allow start date changes" do |
|
431 | 431 | date = Date.today |
|
432 | 432 | @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:start_date => date}}) |
|
433 | 433 | assert_equal date, @copy.start_date |
|
434 | 434 | end |
|
435 | 435 | |
|
436 | 436 | should "allow due date changes" do |
|
437 | 437 | date = Date.today |
|
438 | 438 | @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:due_date => date}}) |
|
439 | 439 | |
|
440 | 440 | assert_equal date, @copy.due_date |
|
441 | 441 | end |
|
442 | 442 | end |
|
443 | 443 | end |
|
444 | 444 | |
|
445 | 445 | def test_recipients_should_not_include_users_that_cannot_view_the_issue |
|
446 | 446 | issue = Issue.find(12) |
|
447 | 447 | assert issue.recipients.include?(issue.author.mail) |
|
448 | 448 | # move the issue to a private project |
|
449 | 449 | copy = issue.move_to(Project.find(5), Tracker.find(2), :copy => true) |
|
450 | 450 | # author is not a member of project anymore |
|
451 | 451 | assert !copy.recipients.include?(copy.author.mail) |
|
452 | 452 | end |
|
453 | 453 | |
|
454 | 454 | def test_watcher_recipients_should_not_include_users_that_cannot_view_the_issue |
|
455 | 455 | user = User.find(3) |
|
456 | 456 | issue = Issue.find(9) |
|
457 | 457 | Watcher.create!(:user => user, :watchable => issue) |
|
458 | 458 | assert issue.watched_by?(user) |
|
459 | 459 | assert !issue.watcher_recipients.include?(user.mail) |
|
460 | 460 | end |
|
461 | 461 | |
|
462 | 462 | def test_issue_destroy |
|
463 | 463 | Issue.find(1).destroy |
|
464 | 464 | assert_nil Issue.find_by_id(1) |
|
465 | 465 | assert_nil TimeEntry.find_by_issue_id(1) |
|
466 | 466 | end |
|
467 | 467 | |
|
468 | 468 | def test_blocked |
|
469 | 469 | blocked_issue = Issue.find(9) |
|
470 | 470 | blocking_issue = Issue.find(10) |
|
471 | 471 | |
|
472 | 472 | assert blocked_issue.blocked? |
|
473 | 473 | assert !blocking_issue.blocked? |
|
474 | 474 | end |
|
475 | 475 | |
|
476 | 476 | def test_blocked_issues_dont_allow_closed_statuses |
|
477 | 477 | blocked_issue = Issue.find(9) |
|
478 | 478 | |
|
479 | 479 | allowed_statuses = blocked_issue.new_statuses_allowed_to(users(:users_002)) |
|
480 | 480 | assert !allowed_statuses.empty? |
|
481 | 481 | closed_statuses = allowed_statuses.select {|st| st.is_closed?} |
|
482 | 482 | assert closed_statuses.empty? |
|
483 | 483 | end |
|
484 | 484 | |
|
485 | 485 | def test_unblocked_issues_allow_closed_statuses |
|
486 | 486 | blocking_issue = Issue.find(10) |
|
487 | 487 | |
|
488 | 488 | allowed_statuses = blocking_issue.new_statuses_allowed_to(users(:users_002)) |
|
489 | 489 | assert !allowed_statuses.empty? |
|
490 | 490 | closed_statuses = allowed_statuses.select {|st| st.is_closed?} |
|
491 | 491 | assert !closed_statuses.empty? |
|
492 | 492 | end |
|
493 | 493 | |
|
494 | 494 | def test_overdue |
|
495 | 495 | assert Issue.new(:due_date => 1.day.ago.to_date).overdue? |
|
496 | 496 | assert !Issue.new(:due_date => Date.today).overdue? |
|
497 | 497 | assert !Issue.new(:due_date => 1.day.from_now.to_date).overdue? |
|
498 | 498 | assert !Issue.new(:due_date => nil).overdue? |
|
499 | 499 | assert !Issue.new(:due_date => 1.day.ago.to_date, :status => IssueStatus.find(:first, :conditions => {:is_closed => true})).overdue? |
|
500 | 500 | end |
|
501 | 501 | |
|
502 | 502 | def test_assignable_users |
|
503 | 503 | assert_kind_of User, Issue.find(1).assignable_users.first |
|
504 | 504 | end |
|
505 | 505 | |
|
506 | 506 | def test_create_should_send_email_notification |
|
507 | 507 | ActionMailer::Base.deliveries.clear |
|
508 | 508 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create', :estimated_hours => '1:30') |
|
509 | 509 | |
|
510 | 510 | assert issue.save |
|
511 | 511 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
512 | 512 | end |
|
513 | 513 | |
|
514 | 514 | def test_stale_issue_should_not_send_email_notification |
|
515 | 515 | ActionMailer::Base.deliveries.clear |
|
516 | 516 | issue = Issue.find(1) |
|
517 | 517 | stale = Issue.find(1) |
|
518 | 518 | |
|
519 | 519 | issue.init_journal(User.find(1)) |
|
520 | 520 | issue.subject = 'Subjet update' |
|
521 | 521 | assert issue.save |
|
522 | 522 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
523 | 523 | ActionMailer::Base.deliveries.clear |
|
524 | 524 | |
|
525 | 525 | stale.init_journal(User.find(1)) |
|
526 | 526 | stale.subject = 'Another subjet update' |
|
527 | 527 | assert_raise ActiveRecord::StaleObjectError do |
|
528 | 528 | stale.save |
|
529 | 529 | end |
|
530 | 530 | assert ActionMailer::Base.deliveries.empty? |
|
531 | 531 | end |
|
532 | 532 | |
|
533 | 533 | context "#done_ratio" do |
|
534 | 534 | setup do |
|
535 | 535 | @issue = Issue.find(1) |
|
536 | 536 | @issue_status = IssueStatus.find(1) |
|
537 | 537 | @issue_status.update_attribute(:default_done_ratio, 50) |
|
538 | 538 | end |
|
539 | 539 | |
|
540 | 540 | context "with Setting.issue_done_ratio using the issue_field" do |
|
541 | 541 | setup do |
|
542 | 542 | Setting.issue_done_ratio = 'issue_field' |
|
543 | 543 | end |
|
544 | 544 | |
|
545 | 545 | should "read the issue's field" do |
|
546 | 546 | assert_equal 0, @issue.done_ratio |
|
547 | 547 | end |
|
548 | 548 | end |
|
549 | 549 | |
|
550 | 550 | context "with Setting.issue_done_ratio using the issue_status" do |
|
551 | 551 | setup do |
|
552 | 552 | Setting.issue_done_ratio = 'issue_status' |
|
553 | 553 | end |
|
554 | 554 | |
|
555 | 555 | should "read the Issue Status's default done ratio" do |
|
556 | 556 | assert_equal 50, @issue.done_ratio |
|
557 | 557 | end |
|
558 | 558 | end |
|
559 | 559 | end |
|
560 | 560 | |
|
561 | 561 | context "#update_done_ratio_from_issue_status" do |
|
562 | 562 | setup do |
|
563 | 563 | @issue = Issue.find(1) |
|
564 | 564 | @issue_status = IssueStatus.find(1) |
|
565 | 565 | @issue_status.update_attribute(:default_done_ratio, 50) |
|
566 | 566 | end |
|
567 | 567 | |
|
568 | 568 | context "with Setting.issue_done_ratio using the issue_field" do |
|
569 | 569 | setup do |
|
570 | 570 | Setting.issue_done_ratio = 'issue_field' |
|
571 | 571 | end |
|
572 | 572 | |
|
573 | 573 | should "not change the issue" do |
|
574 | 574 | @issue.update_done_ratio_from_issue_status |
|
575 | 575 | |
|
576 | 576 | assert_equal 0, @issue.done_ratio |
|
577 | 577 | end |
|
578 | 578 | end |
|
579 | 579 | |
|
580 | 580 | context "with Setting.issue_done_ratio using the issue_status" do |
|
581 | 581 | setup do |
|
582 | 582 | Setting.issue_done_ratio = 'issue_status' |
|
583 | 583 | end |
|
584 | 584 | |
|
585 | 585 | should "not change the issue's done ratio" do |
|
586 | 586 | @issue.update_done_ratio_from_issue_status |
|
587 | 587 | |
|
588 | 588 | assert_equal 50, @issue.done_ratio |
|
589 | 589 | end |
|
590 | 590 | end |
|
591 | 591 | end |
|
592 | 592 | end |
General Comments 0
You need to be logged in to leave comments.
Login now