Mercurial > hg > soundsoftware-site
comparison .svn/pristine/07/0781c86b247e4cfc1df644f5ac2c5e1a6fb8ca1d.svn-base @ 1464:261b3d9a4903 redmine-2.4
Update to Redmine 2.4 branch rev 12663
author | Chris Cannam |
---|---|
date | Tue, 14 Jan 2014 14:37:42 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1296:038ba2d95de8 | 1464:261b3d9a4903 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 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 IssueTest < ActiveSupport::TestCase | |
21 fixtures :projects, :users, :members, :member_roles, :roles, | |
22 :groups_users, | |
23 :trackers, :projects_trackers, | |
24 :enabled_modules, | |
25 :versions, | |
26 :issue_statuses, :issue_categories, :issue_relations, :workflows, | |
27 :enumerations, | |
28 :issues, :journals, :journal_details, | |
29 :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, | |
30 :time_entries | |
31 | |
32 include Redmine::I18n | |
33 | |
34 def teardown | |
35 User.current = nil | |
36 end | |
37 | |
38 def test_initialize | |
39 issue = Issue.new | |
40 | |
41 assert_nil issue.project_id | |
42 assert_nil issue.tracker_id | |
43 assert_nil issue.author_id | |
44 assert_nil issue.assigned_to_id | |
45 assert_nil issue.category_id | |
46 | |
47 assert_equal IssueStatus.default, issue.status | |
48 assert_equal IssuePriority.default, issue.priority | |
49 end | |
50 | |
51 def test_create | |
52 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, | |
53 :status_id => 1, :priority => IssuePriority.all.first, | |
54 :subject => 'test_create', | |
55 :description => 'IssueTest#test_create', :estimated_hours => '1:30') | |
56 assert issue.save | |
57 issue.reload | |
58 assert_equal 1.5, issue.estimated_hours | |
59 end | |
60 | |
61 def test_create_minimal | |
62 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, | |
63 :status_id => 1, :priority => IssuePriority.all.first, | |
64 :subject => 'test_create') | |
65 assert issue.save | |
66 assert issue.description.nil? | |
67 assert_nil issue.estimated_hours | |
68 end | |
69 | |
70 def test_start_date_format_should_be_validated | |
71 set_language_if_valid 'en' | |
72 ['2012', 'ABC', '2012-15-20'].each do |invalid_date| | |
73 issue = Issue.new(:start_date => invalid_date) | |
74 assert !issue.valid? | |
75 assert_include 'Start date is not a valid date', issue.errors.full_messages, "No error found for invalid date #{invalid_date}" | |
76 end | |
77 end | |
78 | |
79 def test_due_date_format_should_be_validated | |
80 set_language_if_valid 'en' | |
81 ['2012', 'ABC', '2012-15-20'].each do |invalid_date| | |
82 issue = Issue.new(:due_date => invalid_date) | |
83 assert !issue.valid? | |
84 assert_include 'Due date is not a valid date', issue.errors.full_messages, "No error found for invalid date #{invalid_date}" | |
85 end | |
86 end | |
87 | |
88 def test_due_date_lesser_than_start_date_should_not_validate | |
89 set_language_if_valid 'en' | |
90 issue = Issue.new(:start_date => '2012-10-06', :due_date => '2012-10-02') | |
91 assert !issue.valid? | |
92 assert_include 'Due date must be greater than start date', issue.errors.full_messages | |
93 end | |
94 | |
95 def test_estimated_hours_should_be_validated | |
96 set_language_if_valid 'en' | |
97 ['-2'].each do |invalid| | |
98 issue = Issue.new(:estimated_hours => invalid) | |
99 assert !issue.valid? | |
100 assert_include 'Estimated time is invalid', issue.errors.full_messages | |
101 end | |
102 end | |
103 | |
104 def test_create_with_required_custom_field | |
105 set_language_if_valid 'en' | |
106 field = IssueCustomField.find_by_name('Database') | |
107 field.update_attribute(:is_required, true) | |
108 | |
109 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, | |
110 :status_id => 1, :subject => 'test_create', | |
111 :description => 'IssueTest#test_create_with_required_custom_field') | |
112 assert issue.available_custom_fields.include?(field) | |
113 # No value for the custom field | |
114 assert !issue.save | |
115 assert_equal ["Database can't be blank"], issue.errors.full_messages | |
116 # Blank value | |
117 issue.custom_field_values = { field.id => '' } | |
118 assert !issue.save | |
119 assert_equal ["Database can't be blank"], issue.errors.full_messages | |
120 # Invalid value | |
121 issue.custom_field_values = { field.id => 'SQLServer' } | |
122 assert !issue.save | |
123 assert_equal ["Database is not included in the list"], issue.errors.full_messages | |
124 # Valid value | |
125 issue.custom_field_values = { field.id => 'PostgreSQL' } | |
126 assert issue.save | |
127 issue.reload | |
128 assert_equal 'PostgreSQL', issue.custom_value_for(field).value | |
129 end | |
130 | |
131 def test_create_with_group_assignment | |
132 with_settings :issue_group_assignment => '1' do | |
133 assert Issue.new(:project_id => 2, :tracker_id => 1, :author_id => 1, | |
134 :subject => 'Group assignment', | |
135 :assigned_to_id => 11).save | |
136 issue = Issue.first(:order => 'id DESC') | |
137 assert_kind_of Group, issue.assigned_to | |
138 assert_equal Group.find(11), issue.assigned_to | |
139 end | |
140 end | |
141 | |
142 def test_create_with_parent_issue_id | |
143 issue = Issue.new(:project_id => 1, :tracker_id => 1, | |
144 :author_id => 1, :subject => 'Group assignment', | |
145 :parent_issue_id => 1) | |
146 assert_save issue | |
147 assert_equal 1, issue.parent_issue_id | |
148 assert_equal Issue.find(1), issue.parent | |
149 end | |
150 | |
151 def test_create_with_sharp_parent_issue_id | |
152 issue = Issue.new(:project_id => 1, :tracker_id => 1, | |
153 :author_id => 1, :subject => 'Group assignment', | |
154 :parent_issue_id => "#1") | |
155 assert_save issue | |
156 assert_equal 1, issue.parent_issue_id | |
157 assert_equal Issue.find(1), issue.parent | |
158 end | |
159 | |
160 def test_create_with_invalid_parent_issue_id | |
161 set_language_if_valid 'en' | |
162 issue = Issue.new(:project_id => 1, :tracker_id => 1, | |
163 :author_id => 1, :subject => 'Group assignment', | |
164 :parent_issue_id => '01ABC') | |
165 assert !issue.save | |
166 assert_equal '01ABC', issue.parent_issue_id | |
167 assert_include 'Parent task is invalid', issue.errors.full_messages | |
168 end | |
169 | |
170 def test_create_with_invalid_sharp_parent_issue_id | |
171 set_language_if_valid 'en' | |
172 issue = Issue.new(:project_id => 1, :tracker_id => 1, | |
173 :author_id => 1, :subject => 'Group assignment', | |
174 :parent_issue_id => '#01ABC') | |
175 assert !issue.save | |
176 assert_equal '#01ABC', issue.parent_issue_id | |
177 assert_include 'Parent task is invalid', issue.errors.full_messages | |
178 end | |
179 | |
180 def assert_visibility_match(user, issues) | |
181 assert_equal issues.collect(&:id).sort, Issue.all.select {|issue| issue.visible?(user)}.collect(&:id).sort | |
182 end | |
183 | |
184 def test_visible_scope_for_anonymous | |
185 # Anonymous user should see issues of public projects only | |
186 issues = Issue.visible(User.anonymous).all | |
187 assert issues.any? | |
188 assert_nil issues.detect {|issue| !issue.project.is_public?} | |
189 assert_nil issues.detect {|issue| issue.is_private?} | |
190 assert_visibility_match User.anonymous, issues | |
191 end | |
192 | |
193 def test_visible_scope_for_anonymous_without_view_issues_permissions | |
194 # Anonymous user should not see issues without permission | |
195 Role.anonymous.remove_permission!(:view_issues) | |
196 issues = Issue.visible(User.anonymous).all | |
197 assert issues.empty? | |
198 assert_visibility_match User.anonymous, issues | |
199 end | |
200 | |
201 def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_default | |
202 assert Role.anonymous.update_attribute(:issues_visibility, 'default') | |
203 issue = Issue.generate!(:author => User.anonymous, :assigned_to => User.anonymous, :is_private => true) | |
204 assert_nil Issue.where(:id => issue.id).visible(User.anonymous).first | |
205 assert !issue.visible?(User.anonymous) | |
206 end | |
207 | |
208 def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_own | |
209 assert Role.anonymous.update_attribute(:issues_visibility, 'own') | |
210 issue = Issue.generate!(:author => User.anonymous, :assigned_to => User.anonymous, :is_private => true) | |
211 assert_nil Issue.where(:id => issue.id).visible(User.anonymous).first | |
212 assert !issue.visible?(User.anonymous) | |
213 end | |
214 | |
215 def test_visible_scope_for_non_member | |
216 user = User.find(9) | |
217 assert user.projects.empty? | |
218 # Non member user should see issues of public projects only | |
219 issues = Issue.visible(user).all | |
220 assert issues.any? | |
221 assert_nil issues.detect {|issue| !issue.project.is_public?} | |
222 assert_nil issues.detect {|issue| issue.is_private?} | |
223 assert_visibility_match user, issues | |
224 end | |
225 | |
226 def test_visible_scope_for_non_member_with_own_issues_visibility | |
227 Role.non_member.update_attribute :issues_visibility, 'own' | |
228 Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 9, :subject => 'Issue by non member') | |
229 user = User.find(9) | |
230 | |
231 issues = Issue.visible(user).all | |
232 assert issues.any? | |
233 assert_nil issues.detect {|issue| issue.author != user} | |
234 assert_visibility_match user, issues | |
235 end | |
236 | |
237 def test_visible_scope_for_non_member_without_view_issues_permissions | |
238 # Non member user should not see issues without permission | |
239 Role.non_member.remove_permission!(:view_issues) | |
240 user = User.find(9) | |
241 assert user.projects.empty? | |
242 issues = Issue.visible(user).all | |
243 assert issues.empty? | |
244 assert_visibility_match user, issues | |
245 end | |
246 | |
247 def test_visible_scope_for_member | |
248 user = User.find(9) | |
249 # User should see issues of projects for which he has view_issues permissions only | |
250 Role.non_member.remove_permission!(:view_issues) | |
251 Member.create!(:principal => user, :project_id => 3, :role_ids => [2]) | |
252 issues = Issue.visible(user).all | |
253 assert issues.any? | |
254 assert_nil issues.detect {|issue| issue.project_id != 3} | |
255 assert_nil issues.detect {|issue| issue.is_private?} | |
256 assert_visibility_match user, issues | |
257 end | |
258 | |
259 def test_visible_scope_for_member_with_groups_should_return_assigned_issues | |
260 user = User.find(8) | |
261 assert user.groups.any? | |
262 Member.create!(:principal => user.groups.first, :project_id => 1, :role_ids => [2]) | |
263 Role.non_member.remove_permission!(:view_issues) | |
264 | |
265 issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, | |
266 :status_id => 1, :priority => IssuePriority.all.first, | |
267 :subject => 'Assignment test', | |
268 :assigned_to => user.groups.first, | |
269 :is_private => true) | |
270 | |
271 Role.find(2).update_attribute :issues_visibility, 'default' | |
272 issues = Issue.visible(User.find(8)).all | |
273 assert issues.any? | |
274 assert issues.include?(issue) | |
275 | |
276 Role.find(2).update_attribute :issues_visibility, 'own' | |
277 issues = Issue.visible(User.find(8)).all | |
278 assert issues.any? | |
279 assert issues.include?(issue) | |
280 end | |
281 | |
282 def test_visible_scope_for_admin | |
283 user = User.find(1) | |
284 user.members.each(&:destroy) | |
285 assert user.projects.empty? | |
286 issues = Issue.visible(user).all | |
287 assert issues.any? | |
288 # Admin should see issues on private projects that he does not belong to | |
289 assert issues.detect {|issue| !issue.project.is_public?} | |
290 # Admin should see private issues of other users | |
291 assert issues.detect {|issue| issue.is_private? && issue.author != user} | |
292 assert_visibility_match user, issues | |
293 end | |
294 | |
295 def test_visible_scope_with_project | |
296 project = Project.find(1) | |
297 issues = Issue.visible(User.find(2), :project => project).all | |
298 projects = issues.collect(&:project).uniq | |
299 assert_equal 1, projects.size | |
300 assert_equal project, projects.first | |
301 end | |
302 | |
303 def test_visible_scope_with_project_and_subprojects | |
304 project = Project.find(1) | |
305 issues = Issue.visible(User.find(2), :project => project, :with_subprojects => true).all | |
306 projects = issues.collect(&:project).uniq | |
307 assert projects.size > 1 | |
308 assert_equal [], projects.select {|p| !p.is_or_is_descendant_of?(project)} | |
309 end | |
310 | |
311 def test_visible_and_nested_set_scopes | |
312 assert_equal 0, Issue.find(1).descendants.visible.all.size | |
313 end | |
314 | |
315 def test_open_scope | |
316 issues = Issue.open.all | |
317 assert_nil issues.detect(&:closed?) | |
318 end | |
319 | |
320 def test_open_scope_with_arg | |
321 issues = Issue.open(false).all | |
322 assert_equal issues, issues.select(&:closed?) | |
323 end | |
324 | |
325 def test_fixed_version_scope_with_a_version_should_return_its_fixed_issues | |
326 version = Version.find(2) | |
327 assert version.fixed_issues.any? | |
328 assert_equal version.fixed_issues.to_a.sort, Issue.fixed_version(version).to_a.sort | |
329 end | |
330 | |
331 def test_fixed_version_scope_with_empty_array_should_return_no_result | |
332 assert_equal 0, Issue.fixed_version([]).count | |
333 end | |
334 | |
335 def test_errors_full_messages_should_include_custom_fields_errors | |
336 field = IssueCustomField.find_by_name('Database') | |
337 | |
338 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, | |
339 :status_id => 1, :subject => 'test_create', | |
340 :description => 'IssueTest#test_create_with_required_custom_field') | |
341 assert issue.available_custom_fields.include?(field) | |
342 # Invalid value | |
343 issue.custom_field_values = { field.id => 'SQLServer' } | |
344 | |
345 assert !issue.valid? | |
346 assert_equal 1, issue.errors.full_messages.size | |
347 assert_equal "Database #{I18n.translate('activerecord.errors.messages.inclusion')}", | |
348 issue.errors.full_messages.first | |
349 end | |
350 | |
351 def test_update_issue_with_required_custom_field | |
352 field = IssueCustomField.find_by_name('Database') | |
353 field.update_attribute(:is_required, true) | |
354 | |
355 issue = Issue.find(1) | |
356 assert_nil issue.custom_value_for(field) | |
357 assert issue.available_custom_fields.include?(field) | |
358 # No change to custom values, issue can be saved | |
359 assert issue.save | |
360 # Blank value | |
361 issue.custom_field_values = { field.id => '' } | |
362 assert !issue.save | |
363 # Valid value | |
364 issue.custom_field_values = { field.id => 'PostgreSQL' } | |
365 assert issue.save | |
366 issue.reload | |
367 assert_equal 'PostgreSQL', issue.custom_value_for(field).value | |
368 end | |
369 | |
370 def test_should_not_update_attributes_if_custom_fields_validation_fails | |
371 issue = Issue.find(1) | |
372 field = IssueCustomField.find_by_name('Database') | |
373 assert issue.available_custom_fields.include?(field) | |
374 | |
375 issue.custom_field_values = { field.id => 'Invalid' } | |
376 issue.subject = 'Should be not be saved' | |
377 assert !issue.save | |
378 | |
379 issue.reload | |
380 assert_equal "Can't print recipes", issue.subject | |
381 end | |
382 | |
383 def test_should_not_recreate_custom_values_objects_on_update | |
384 field = IssueCustomField.find_by_name('Database') | |
385 | |
386 issue = Issue.find(1) | |
387 issue.custom_field_values = { field.id => 'PostgreSQL' } | |
388 assert issue.save | |
389 custom_value = issue.custom_value_for(field) | |
390 issue.reload | |
391 issue.custom_field_values = { field.id => 'MySQL' } | |
392 assert issue.save | |
393 issue.reload | |
394 assert_equal custom_value.id, issue.custom_value_for(field).id | |
395 end | |
396 | |
397 def test_should_not_update_custom_fields_on_changing_tracker_with_different_custom_fields | |
398 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, | |
399 :status_id => 1, :subject => 'Test', | |
400 :custom_field_values => {'2' => 'Test'}) | |
401 assert !Tracker.find(2).custom_field_ids.include?(2) | |
402 | |
403 issue = Issue.find(issue.id) | |
404 issue.attributes = {:tracker_id => 2, :custom_field_values => {'1' => ''}} | |
405 | |
406 issue = Issue.find(issue.id) | |
407 custom_value = issue.custom_value_for(2) | |
408 assert_not_nil custom_value | |
409 assert_equal 'Test', custom_value.value | |
410 end | |
411 | |
412 def test_assigning_tracker_id_should_reload_custom_fields_values | |
413 issue = Issue.new(:project => Project.find(1)) | |
414 assert issue.custom_field_values.empty? | |
415 issue.tracker_id = 1 | |
416 assert issue.custom_field_values.any? | |
417 end | |
418 | |
419 def test_assigning_attributes_should_assign_project_and_tracker_first | |
420 seq = sequence('seq') | |
421 issue = Issue.new | |
422 issue.expects(:project_id=).in_sequence(seq) | |
423 issue.expects(:tracker_id=).in_sequence(seq) | |
424 issue.expects(:subject=).in_sequence(seq) | |
425 issue.attributes = {:tracker_id => 2, :project_id => 1, :subject => 'Test'} | |
426 end | |
427 | |
428 def test_assigning_tracker_and_custom_fields_should_assign_custom_fields | |
429 attributes = ActiveSupport::OrderedHash.new | |
430 attributes['custom_field_values'] = { '1' => 'MySQL' } | |
431 attributes['tracker_id'] = '1' | |
432 issue = Issue.new(:project => Project.find(1)) | |
433 issue.attributes = attributes | |
434 assert_equal 'MySQL', issue.custom_field_value(1) | |
435 end | |
436 | |
437 def test_reload_should_reload_custom_field_values | |
438 issue = Issue.generate! | |
439 issue.custom_field_values = {'2' => 'Foo'} | |
440 issue.save! | |
441 | |
442 issue = Issue.order('id desc').first | |
443 assert_equal 'Foo', issue.custom_field_value(2) | |
444 | |
445 issue.custom_field_values = {'2' => 'Bar'} | |
446 assert_equal 'Bar', issue.custom_field_value(2) | |
447 | |
448 issue.reload | |
449 assert_equal 'Foo', issue.custom_field_value(2) | |
450 end | |
451 | |
452 def test_should_update_issue_with_disabled_tracker | |
453 p = Project.find(1) | |
454 issue = Issue.find(1) | |
455 | |
456 p.trackers.delete(issue.tracker) | |
457 assert !p.trackers.include?(issue.tracker) | |
458 | |
459 issue.reload | |
460 issue.subject = 'New subject' | |
461 assert issue.save | |
462 end | |
463 | |
464 def test_should_not_set_a_disabled_tracker | |
465 p = Project.find(1) | |
466 p.trackers.delete(Tracker.find(2)) | |
467 | |
468 issue = Issue.find(1) | |
469 issue.tracker_id = 2 | |
470 issue.subject = 'New subject' | |
471 assert !issue.save | |
472 assert_not_equal [], issue.errors[:tracker_id] | |
473 end | |
474 | |
475 def test_category_based_assignment | |
476 issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, | |
477 :status_id => 1, :priority => IssuePriority.all.first, | |
478 :subject => 'Assignment test', | |
479 :description => 'Assignment test', :category_id => 1) | |
480 assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to | |
481 end | |
482 | |
483 def test_new_statuses_allowed_to | |
484 WorkflowTransition.delete_all | |
485 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, | |
486 :old_status_id => 1, :new_status_id => 2, | |
487 :author => false, :assignee => false) | |
488 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, | |
489 :old_status_id => 1, :new_status_id => 3, | |
490 :author => true, :assignee => false) | |
491 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, | |
492 :old_status_id => 1, :new_status_id => 4, | |
493 :author => false, :assignee => true) | |
494 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, | |
495 :old_status_id => 1, :new_status_id => 5, | |
496 :author => true, :assignee => true) | |
497 status = IssueStatus.find(1) | |
498 role = Role.find(1) | |
499 tracker = Tracker.find(1) | |
500 user = User.find(2) | |
501 | |
502 issue = Issue.generate!(:tracker => tracker, :status => status, | |
503 :project_id => 1, :author_id => 1) | |
504 assert_equal [1, 2], issue.new_statuses_allowed_to(user).map(&:id) | |
505 | |
506 issue = Issue.generate!(:tracker => tracker, :status => status, | |
507 :project_id => 1, :author => user) | |
508 assert_equal [1, 2, 3, 5], issue.new_statuses_allowed_to(user).map(&:id) | |
509 | |
510 issue = Issue.generate!(:tracker => tracker, :status => status, | |
511 :project_id => 1, :author_id => 1, | |
512 :assigned_to => user) | |
513 assert_equal [1, 2, 4, 5], issue.new_statuses_allowed_to(user).map(&:id) | |
514 | |
515 issue = Issue.generate!(:tracker => tracker, :status => status, | |
516 :project_id => 1, :author => user, | |
517 :assigned_to => user) | |
518 assert_equal [1, 2, 3, 4, 5], issue.new_statuses_allowed_to(user).map(&:id) | |
519 | |
520 group = Group.generate! | |
521 group.users << user | |
522 issue = Issue.generate!(:tracker => tracker, :status => status, | |
523 :project_id => 1, :author => user, | |
524 :assigned_to => group) | |
525 assert_equal [1, 2, 3, 4, 5], issue.new_statuses_allowed_to(user).map(&:id) | |
526 end | |
527 | |
528 def test_new_statuses_allowed_to_should_consider_group_assignment | |
529 WorkflowTransition.delete_all | |
530 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, | |
531 :old_status_id => 1, :new_status_id => 4, | |
532 :author => false, :assignee => true) | |
533 user = User.find(2) | |
534 group = Group.generate! | |
535 group.users << user | |
536 | |
537 issue = Issue.generate!(:author_id => 1, :assigned_to => group) | |
538 assert_include 4, issue.new_statuses_allowed_to(user).map(&:id) | |
539 end | |
540 | |
541 def test_new_statuses_allowed_to_should_return_all_transitions_for_admin | |
542 admin = User.find(1) | |
543 issue = Issue.find(1) | |
544 assert !admin.member_of?(issue.project) | |
545 expected_statuses = [issue.status] + | |
546 WorkflowTransition.find_all_by_old_status_id( | |
547 issue.status_id).map(&:new_status).uniq.sort | |
548 assert_equal expected_statuses, issue.new_statuses_allowed_to(admin) | |
549 end | |
550 | |
551 def test_new_statuses_allowed_to_should_return_default_and_current_status_when_copying | |
552 issue = Issue.find(1).copy | |
553 assert_equal [1], issue.new_statuses_allowed_to(User.find(2)).map(&:id) | |
554 | |
555 issue = Issue.find(2).copy | |
556 assert_equal [1, 2], issue.new_statuses_allowed_to(User.find(2)).map(&:id) | |
557 end | |
558 | |
559 def test_safe_attributes_names_should_not_include_disabled_field | |
560 tracker = Tracker.new(:core_fields => %w(assigned_to_id fixed_version_id)) | |
561 | |
562 issue = Issue.new(:tracker => tracker) | |
563 assert_include 'tracker_id', issue.safe_attribute_names | |
564 assert_include 'status_id', issue.safe_attribute_names | |
565 assert_include 'subject', issue.safe_attribute_names | |
566 assert_include 'description', issue.safe_attribute_names | |
567 assert_include 'custom_field_values', issue.safe_attribute_names | |
568 assert_include 'custom_fields', issue.safe_attribute_names | |
569 assert_include 'lock_version', issue.safe_attribute_names | |
570 | |
571 tracker.core_fields.each do |field| | |
572 assert_include field, issue.safe_attribute_names | |
573 end | |
574 | |
575 tracker.disabled_core_fields.each do |field| | |
576 assert_not_include field, issue.safe_attribute_names | |
577 end | |
578 end | |
579 | |
580 def test_safe_attributes_should_ignore_disabled_fields | |
581 tracker = Tracker.find(1) | |
582 tracker.core_fields = %w(assigned_to_id due_date) | |
583 tracker.save! | |
584 | |
585 issue = Issue.new(:tracker => tracker) | |
586 issue.safe_attributes = {'start_date' => '2012-07-14', 'due_date' => '2012-07-14'} | |
587 assert_nil issue.start_date | |
588 assert_equal Date.parse('2012-07-14'), issue.due_date | |
589 end | |
590 | |
591 def test_safe_attributes_should_accept_target_tracker_enabled_fields | |
592 source = Tracker.find(1) | |
593 source.core_fields = [] | |
594 source.save! | |
595 target = Tracker.find(2) | |
596 target.core_fields = %w(assigned_to_id due_date) | |
597 target.save! | |
598 | |
599 issue = Issue.new(:tracker => source) | |
600 issue.safe_attributes = {'tracker_id' => 2, 'due_date' => '2012-07-14'} | |
601 assert_equal target, issue.tracker | |
602 assert_equal Date.parse('2012-07-14'), issue.due_date | |
603 end | |
604 | |
605 def test_safe_attributes_should_not_include_readonly_fields | |
606 WorkflowPermission.delete_all | |
607 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, | |
608 :role_id => 1, :field_name => 'due_date', | |
609 :rule => 'readonly') | |
610 user = User.find(2) | |
611 | |
612 issue = Issue.new(:project_id => 1, :tracker_id => 1) | |
613 assert_equal %w(due_date), issue.read_only_attribute_names(user) | |
614 assert_not_include 'due_date', issue.safe_attribute_names(user) | |
615 | |
616 issue.send :safe_attributes=, {'start_date' => '2012-07-14', 'due_date' => '2012-07-14'}, user | |
617 assert_equal Date.parse('2012-07-14'), issue.start_date | |
618 assert_nil issue.due_date | |
619 end | |
620 | |
621 def test_safe_attributes_should_not_include_readonly_custom_fields | |
622 cf1 = IssueCustomField.create!(:name => 'Writable field', | |
623 :field_format => 'string', | |
624 :is_for_all => true, :tracker_ids => [1]) | |
625 cf2 = IssueCustomField.create!(:name => 'Readonly field', | |
626 :field_format => 'string', | |
627 :is_for_all => true, :tracker_ids => [1]) | |
628 WorkflowPermission.delete_all | |
629 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, | |
630 :role_id => 1, :field_name => cf2.id.to_s, | |
631 :rule => 'readonly') | |
632 user = User.find(2) | |
633 issue = Issue.new(:project_id => 1, :tracker_id => 1) | |
634 assert_equal [cf2.id.to_s], issue.read_only_attribute_names(user) | |
635 assert_not_include cf2.id.to_s, issue.safe_attribute_names(user) | |
636 | |
637 issue.send :safe_attributes=, {'custom_field_values' => { | |
638 cf1.id.to_s => 'value1', cf2.id.to_s => 'value2' | |
639 }}, user | |
640 assert_equal 'value1', issue.custom_field_value(cf1) | |
641 assert_nil issue.custom_field_value(cf2) | |
642 | |
643 issue.send :safe_attributes=, {'custom_fields' => [ | |
644 {'id' => cf1.id.to_s, 'value' => 'valuea'}, | |
645 {'id' => cf2.id.to_s, 'value' => 'valueb'} | |
646 ]}, user | |
647 assert_equal 'valuea', issue.custom_field_value(cf1) | |
648 assert_nil issue.custom_field_value(cf2) | |
649 end | |
650 | |
651 def test_editable_custom_field_values_should_return_non_readonly_custom_values | |
652 cf1 = IssueCustomField.create!(:name => 'Writable field', :field_format => 'string', | |
653 :is_for_all => true, :tracker_ids => [1, 2]) | |
654 cf2 = IssueCustomField.create!(:name => 'Readonly field', :field_format => 'string', | |
655 :is_for_all => true, :tracker_ids => [1, 2]) | |
656 WorkflowPermission.delete_all | |
657 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, | |
658 :field_name => cf2.id.to_s, :rule => 'readonly') | |
659 user = User.find(2) | |
660 | |
661 issue = Issue.new(:project_id => 1, :tracker_id => 1) | |
662 values = issue.editable_custom_field_values(user) | |
663 assert values.detect {|value| value.custom_field == cf1} | |
664 assert_nil values.detect {|value| value.custom_field == cf2} | |
665 | |
666 issue.tracker_id = 2 | |
667 values = issue.editable_custom_field_values(user) | |
668 assert values.detect {|value| value.custom_field == cf1} | |
669 assert values.detect {|value| value.custom_field == cf2} | |
670 end | |
671 | |
672 def test_safe_attributes_should_accept_target_tracker_writable_fields | |
673 WorkflowPermission.delete_all | |
674 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, | |
675 :role_id => 1, :field_name => 'due_date', | |
676 :rule => 'readonly') | |
677 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, | |
678 :role_id => 1, :field_name => 'start_date', | |
679 :rule => 'readonly') | |
680 user = User.find(2) | |
681 | |
682 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1) | |
683 | |
684 issue.send :safe_attributes=, {'start_date' => '2012-07-12', | |
685 'due_date' => '2012-07-14'}, user | |
686 assert_equal Date.parse('2012-07-12'), issue.start_date | |
687 assert_nil issue.due_date | |
688 | |
689 issue.send :safe_attributes=, {'start_date' => '2012-07-15', | |
690 'due_date' => '2012-07-16', | |
691 'tracker_id' => 2}, user | |
692 assert_equal Date.parse('2012-07-12'), issue.start_date | |
693 assert_equal Date.parse('2012-07-16'), issue.due_date | |
694 end | |
695 | |
696 def test_safe_attributes_should_accept_target_status_writable_fields | |
697 WorkflowPermission.delete_all | |
698 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, | |
699 :role_id => 1, :field_name => 'due_date', | |
700 :rule => 'readonly') | |
701 WorkflowPermission.create!(:old_status_id => 2, :tracker_id => 1, | |
702 :role_id => 1, :field_name => 'start_date', | |
703 :rule => 'readonly') | |
704 user = User.find(2) | |
705 | |
706 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1) | |
707 | |
708 issue.send :safe_attributes=, {'start_date' => '2012-07-12', | |
709 'due_date' => '2012-07-14'}, | |
710 user | |
711 assert_equal Date.parse('2012-07-12'), issue.start_date | |
712 assert_nil issue.due_date | |
713 | |
714 issue.send :safe_attributes=, {'start_date' => '2012-07-15', | |
715 'due_date' => '2012-07-16', | |
716 'status_id' => 2}, | |
717 user | |
718 assert_equal Date.parse('2012-07-12'), issue.start_date | |
719 assert_equal Date.parse('2012-07-16'), issue.due_date | |
720 end | |
721 | |
722 def test_required_attributes_should_be_validated | |
723 cf = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', | |
724 :is_for_all => true, :tracker_ids => [1, 2]) | |
725 | |
726 WorkflowPermission.delete_all | |
727 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, | |
728 :role_id => 1, :field_name => 'due_date', | |
729 :rule => 'required') | |
730 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, | |
731 :role_id => 1, :field_name => 'category_id', | |
732 :rule => 'required') | |
733 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, | |
734 :role_id => 1, :field_name => cf.id.to_s, | |
735 :rule => 'required') | |
736 | |
737 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, | |
738 :role_id => 1, :field_name => 'start_date', | |
739 :rule => 'required') | |
740 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, | |
741 :role_id => 1, :field_name => cf.id.to_s, | |
742 :rule => 'required') | |
743 user = User.find(2) | |
744 | |
745 issue = Issue.new(:project_id => 1, :tracker_id => 1, | |
746 :status_id => 1, :subject => 'Required fields', | |
747 :author => user) | |
748 assert_equal [cf.id.to_s, "category_id", "due_date"], | |
749 issue.required_attribute_names(user).sort | |
750 assert !issue.save, "Issue was saved" | |
751 assert_equal ["Category can't be blank", "Due date can't be blank", "Foo can't be blank"], | |
752 issue.errors.full_messages.sort | |
753 | |
754 issue.tracker_id = 2 | |
755 assert_equal [cf.id.to_s, "start_date"], issue.required_attribute_names(user).sort | |
756 assert !issue.save, "Issue was saved" | |
757 assert_equal ["Foo can't be blank", "Start date can't be blank"], | |
758 issue.errors.full_messages.sort | |
759 | |
760 issue.start_date = Date.today | |
761 issue.custom_field_values = {cf.id.to_s => 'bar'} | |
762 assert issue.save | |
763 end | |
764 | |
765 def test_required_attribute_names_for_multiple_roles_should_intersect_rules | |
766 WorkflowPermission.delete_all | |
767 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, | |
768 :role_id => 1, :field_name => 'due_date', | |
769 :rule => 'required') | |
770 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, | |
771 :role_id => 1, :field_name => 'start_date', | |
772 :rule => 'required') | |
773 user = User.find(2) | |
774 member = Member.find(1) | |
775 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1) | |
776 | |
777 assert_equal %w(due_date start_date), issue.required_attribute_names(user).sort | |
778 | |
779 member.role_ids = [1, 2] | |
780 member.save! | |
781 assert_equal [], issue.required_attribute_names(user.reload) | |
782 | |
783 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, | |
784 :role_id => 2, :field_name => 'due_date', | |
785 :rule => 'required') | |
786 assert_equal %w(due_date), issue.required_attribute_names(user) | |
787 | |
788 member.role_ids = [1, 2, 3] | |
789 member.save! | |
790 assert_equal [], issue.required_attribute_names(user.reload) | |
791 | |
792 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, | |
793 :role_id => 2, :field_name => 'due_date', | |
794 :rule => 'readonly') | |
795 # required + readonly => required | |
796 assert_equal %w(due_date), issue.required_attribute_names(user) | |
797 end | |
798 | |
799 def test_read_only_attribute_names_for_multiple_roles_should_intersect_rules | |
800 WorkflowPermission.delete_all | |
801 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, | |
802 :role_id => 1, :field_name => 'due_date', | |
803 :rule => 'readonly') | |
804 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, | |
805 :role_id => 1, :field_name => 'start_date', | |
806 :rule => 'readonly') | |
807 user = User.find(2) | |
808 member = Member.find(1) | |
809 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1) | |
810 | |
811 assert_equal %w(due_date start_date), issue.read_only_attribute_names(user).sort | |
812 | |
813 member.role_ids = [1, 2] | |
814 member.save! | |
815 assert_equal [], issue.read_only_attribute_names(user.reload) | |
816 | |
817 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, | |
818 :role_id => 2, :field_name => 'due_date', | |
819 :rule => 'readonly') | |
820 assert_equal %w(due_date), issue.read_only_attribute_names(user) | |
821 end | |
822 | |
823 def test_copy | |
824 issue = Issue.new.copy_from(1) | |
825 assert issue.copy? | |
826 assert issue.save | |
827 issue.reload | |
828 orig = Issue.find(1) | |
829 assert_equal orig.subject, issue.subject | |
830 assert_equal orig.tracker, issue.tracker | |
831 assert_equal "125", issue.custom_value_for(2).value | |
832 end | |
833 | |
834 def test_copy_should_copy_status | |
835 orig = Issue.find(8) | |
836 assert orig.status != IssueStatus.default | |
837 | |
838 issue = Issue.new.copy_from(orig) | |
839 assert issue.save | |
840 issue.reload | |
841 assert_equal orig.status, issue.status | |
842 end | |
843 | |
844 def test_copy_should_add_relation_with_copied_issue | |
845 copied = Issue.find(1) | |
846 issue = Issue.new.copy_from(copied) | |
847 assert issue.save | |
848 issue.reload | |
849 | |
850 assert_equal 1, issue.relations.size | |
851 relation = issue.relations.first | |
852 assert_equal 'copied_to', relation.relation_type | |
853 assert_equal copied, relation.issue_from | |
854 assert_equal issue, relation.issue_to | |
855 end | |
856 | |
857 def test_copy_should_copy_subtasks | |
858 issue = Issue.generate_with_descendants! | |
859 | |
860 copy = issue.reload.copy | |
861 copy.author = User.find(7) | |
862 assert_difference 'Issue.count', 1+issue.descendants.count do | |
863 assert copy.save | |
864 end | |
865 copy.reload | |
866 assert_equal %w(Child1 Child2), copy.children.map(&:subject).sort | |
867 child_copy = copy.children.detect {|c| c.subject == 'Child1'} | |
868 assert_equal %w(Child11), child_copy.children.map(&:subject).sort | |
869 assert_equal copy.author, child_copy.author | |
870 end | |
871 | |
872 def test_copy_as_a_child_of_copied_issue_should_not_copy_itself | |
873 parent = Issue.generate! | |
874 child1 = Issue.generate!(:parent_issue_id => parent.id, :subject => 'Child 1') | |
875 child2 = Issue.generate!(:parent_issue_id => parent.id, :subject => 'Child 2') | |
876 | |
877 copy = parent.reload.copy | |
878 copy.parent_issue_id = parent.id | |
879 copy.author = User.find(7) | |
880 assert_difference 'Issue.count', 3 do | |
881 assert copy.save | |
882 end | |
883 parent.reload | |
884 copy.reload | |
885 assert_equal parent, copy.parent | |
886 assert_equal 3, parent.children.count | |
887 assert_equal 5, parent.descendants.count | |
888 assert_equal 2, copy.children.count | |
889 assert_equal 2, copy.descendants.count | |
890 end | |
891 | |
892 def test_copy_as_a_descendant_of_copied_issue_should_not_copy_itself | |
893 parent = Issue.generate! | |
894 child1 = Issue.generate!(:parent_issue_id => parent.id, :subject => 'Child 1') | |
895 child2 = Issue.generate!(:parent_issue_id => parent.id, :subject => 'Child 2') | |
896 | |
897 copy = parent.reload.copy | |
898 copy.parent_issue_id = child1.id | |
899 copy.author = User.find(7) | |
900 assert_difference 'Issue.count', 3 do | |
901 assert copy.save | |
902 end | |
903 parent.reload | |
904 child1.reload | |
905 copy.reload | |
906 assert_equal child1, copy.parent | |
907 assert_equal 2, parent.children.count | |
908 assert_equal 5, parent.descendants.count | |
909 assert_equal 1, child1.children.count | |
910 assert_equal 3, child1.descendants.count | |
911 assert_equal 2, copy.children.count | |
912 assert_equal 2, copy.descendants.count | |
913 end | |
914 | |
915 def test_copy_should_copy_subtasks_to_target_project | |
916 issue = Issue.generate_with_descendants! | |
917 | |
918 copy = issue.copy(:project_id => 3) | |
919 assert_difference 'Issue.count', 1+issue.descendants.count do | |
920 assert copy.save | |
921 end | |
922 assert_equal [3], copy.reload.descendants.map(&:project_id).uniq | |
923 end | |
924 | |
925 def test_copy_should_not_copy_subtasks_twice_when_saving_twice | |
926 issue = Issue.generate_with_descendants! | |
927 | |
928 copy = issue.reload.copy | |
929 assert_difference 'Issue.count', 1+issue.descendants.count do | |
930 assert copy.save | |
931 assert copy.save | |
932 end | |
933 end | |
934 | |
935 def test_should_not_call_after_project_change_on_creation | |
936 issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1, | |
937 :subject => 'Test', :author_id => 1) | |
938 issue.expects(:after_project_change).never | |
939 issue.save! | |
940 end | |
941 | |
942 def test_should_not_call_after_project_change_on_update | |
943 issue = Issue.find(1) | |
944 issue.project = Project.find(1) | |
945 issue.subject = 'No project change' | |
946 issue.expects(:after_project_change).never | |
947 issue.save! | |
948 end | |
949 | |
950 def test_should_call_after_project_change_on_project_change | |
951 issue = Issue.find(1) | |
952 issue.project = Project.find(2) | |
953 issue.expects(:after_project_change).once | |
954 issue.save! | |
955 end | |
956 | |
957 def test_adding_journal_should_update_timestamp | |
958 issue = Issue.find(1) | |
959 updated_on_was = issue.updated_on | |
960 | |
961 issue.init_journal(User.first, "Adding notes") | |
962 assert_difference 'Journal.count' do | |
963 assert issue.save | |
964 end | |
965 issue.reload | |
966 | |
967 assert_not_equal updated_on_was, issue.updated_on | |
968 end | |
969 | |
970 def test_should_close_duplicates | |
971 # Create 3 issues | |
972 issue1 = Issue.generate! | |
973 issue2 = Issue.generate! | |
974 issue3 = Issue.generate! | |
975 | |
976 # 2 is a dupe of 1 | |
977 IssueRelation.create!(:issue_from => issue2, :issue_to => issue1, | |
978 :relation_type => IssueRelation::TYPE_DUPLICATES) | |
979 # And 3 is a dupe of 2 | |
980 IssueRelation.create!(:issue_from => issue3, :issue_to => issue2, | |
981 :relation_type => IssueRelation::TYPE_DUPLICATES) | |
982 # And 3 is a dupe of 1 (circular duplicates) | |
983 IssueRelation.create!(:issue_from => issue3, :issue_to => issue1, | |
984 :relation_type => IssueRelation::TYPE_DUPLICATES) | |
985 | |
986 assert issue1.reload.duplicates.include?(issue2) | |
987 | |
988 # Closing issue 1 | |
989 issue1.init_journal(User.first, "Closing issue1") | |
990 issue1.status = IssueStatus.where(:is_closed => true).first | |
991 assert issue1.save | |
992 # 2 and 3 should be also closed | |
993 assert issue2.reload.closed? | |
994 assert issue3.reload.closed? | |
995 end | |
996 | |
997 def test_should_not_close_duplicated_issue | |
998 issue1 = Issue.generate! | |
999 issue2 = Issue.generate! | |
1000 | |
1001 # 2 is a dupe of 1 | |
1002 IssueRelation.create(:issue_from => issue2, :issue_to => issue1, | |
1003 :relation_type => IssueRelation::TYPE_DUPLICATES) | |
1004 # 2 is a dup of 1 but 1 is not a duplicate of 2 | |
1005 assert !issue2.reload.duplicates.include?(issue1) | |
1006 | |
1007 # Closing issue 2 | |
1008 issue2.init_journal(User.first, "Closing issue2") | |
1009 issue2.status = IssueStatus.where(:is_closed => true).first | |
1010 assert issue2.save | |
1011 # 1 should not be also closed | |
1012 assert !issue1.reload.closed? | |
1013 end | |
1014 | |
1015 def test_assignable_versions | |
1016 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, | |
1017 :status_id => 1, :fixed_version_id => 1, | |
1018 :subject => 'New issue') | |
1019 assert_equal ['open'], issue.assignable_versions.collect(&:status).uniq | |
1020 end | |
1021 | |
1022 def test_should_not_be_able_to_assign_a_new_issue_to_a_closed_version | |
1023 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, | |
1024 :status_id => 1, :fixed_version_id => 1, | |
1025 :subject => 'New issue') | |
1026 assert !issue.save | |
1027 assert_not_equal [], issue.errors[:fixed_version_id] | |
1028 end | |
1029 | |
1030 def test_should_not_be_able_to_assign_a_new_issue_to_a_locked_version | |
1031 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, | |
1032 :status_id => 1, :fixed_version_id => 2, | |
1033 :subject => 'New issue') | |
1034 assert !issue.save | |
1035 assert_not_equal [], issue.errors[:fixed_version_id] | |
1036 end | |
1037 | |
1038 def test_should_be_able_to_assign_a_new_issue_to_an_open_version | |
1039 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, | |
1040 :status_id => 1, :fixed_version_id => 3, | |
1041 :subject => 'New issue') | |
1042 assert issue.save | |
1043 end | |
1044 | |
1045 def test_should_be_able_to_update_an_issue_assigned_to_a_closed_version | |
1046 issue = Issue.find(11) | |
1047 assert_equal 'closed', issue.fixed_version.status | |
1048 issue.subject = 'Subject changed' | |
1049 assert issue.save | |
1050 end | |
1051 | |
1052 def test_should_not_be_able_to_reopen_an_issue_assigned_to_a_closed_version | |
1053 issue = Issue.find(11) | |
1054 issue.status_id = 1 | |
1055 assert !issue.save | |
1056 assert_not_equal [], issue.errors[:base] | |
1057 end | |
1058 | |
1059 def test_should_be_able_to_reopen_and_reassign_an_issue_assigned_to_a_closed_version | |
1060 issue = Issue.find(11) | |
1061 issue.status_id = 1 | |
1062 issue.fixed_version_id = 3 | |
1063 assert issue.save | |
1064 end | |
1065 | |
1066 def test_should_be_able_to_reopen_an_issue_assigned_to_a_locked_version | |
1067 issue = Issue.find(12) | |
1068 assert_equal 'locked', issue.fixed_version.status | |
1069 issue.status_id = 1 | |
1070 assert issue.save | |
1071 end | |
1072 | |
1073 def test_should_not_be_able_to_keep_unshared_version_when_changing_project | |
1074 issue = Issue.find(2) | |
1075 assert_equal 2, issue.fixed_version_id | |
1076 issue.project_id = 3 | |
1077 assert_nil issue.fixed_version_id | |
1078 issue.fixed_version_id = 2 | |
1079 assert !issue.save | |
1080 assert_include 'Target version is not included in the list', issue.errors.full_messages | |
1081 end | |
1082 | |
1083 def test_should_keep_shared_version_when_changing_project | |
1084 Version.find(2).update_attribute :sharing, 'tree' | |
1085 | |
1086 issue = Issue.find(2) | |
1087 assert_equal 2, issue.fixed_version_id | |
1088 issue.project_id = 3 | |
1089 assert_equal 2, issue.fixed_version_id | |
1090 assert issue.save | |
1091 end | |
1092 | |
1093 def test_allowed_target_projects_on_move_should_include_projects_with_issue_tracking_enabled | |
1094 assert_include Project.find(2), Issue.allowed_target_projects_on_move(User.find(2)) | |
1095 end | |
1096 | |
1097 def test_allowed_target_projects_on_move_should_not_include_projects_with_issue_tracking_disabled | |
1098 Project.find(2).disable_module! :issue_tracking | |
1099 assert_not_include Project.find(2), Issue.allowed_target_projects_on_move(User.find(2)) | |
1100 end | |
1101 | |
1102 def test_move_to_another_project_with_same_category | |
1103 issue = Issue.find(1) | |
1104 issue.project = Project.find(2) | |
1105 assert issue.save | |
1106 issue.reload | |
1107 assert_equal 2, issue.project_id | |
1108 # Category changes | |
1109 assert_equal 4, issue.category_id | |
1110 # Make sure time entries were move to the target project | |
1111 assert_equal 2, issue.time_entries.first.project_id | |
1112 end | |
1113 | |
1114 def test_move_to_another_project_without_same_category | |
1115 issue = Issue.find(2) | |
1116 issue.project = Project.find(2) | |
1117 assert issue.save | |
1118 issue.reload | |
1119 assert_equal 2, issue.project_id | |
1120 # Category cleared | |
1121 assert_nil issue.category_id | |
1122 end | |
1123 | |
1124 def test_move_to_another_project_should_clear_fixed_version_when_not_shared | |
1125 issue = Issue.find(1) | |
1126 issue.update_attribute(:fixed_version_id, 1) | |
1127 issue.project = Project.find(2) | |
1128 assert issue.save | |
1129 issue.reload | |
1130 assert_equal 2, issue.project_id | |
1131 # Cleared fixed_version | |
1132 assert_equal nil, issue.fixed_version | |
1133 end | |
1134 | |
1135 def test_move_to_another_project_should_keep_fixed_version_when_shared_with_the_target_project | |
1136 issue = Issue.find(1) | |
1137 issue.update_attribute(:fixed_version_id, 4) | |
1138 issue.project = Project.find(5) | |
1139 assert issue.save | |
1140 issue.reload | |
1141 assert_equal 5, issue.project_id | |
1142 # Keep fixed_version | |
1143 assert_equal 4, issue.fixed_version_id | |
1144 end | |
1145 | |
1146 def test_move_to_another_project_should_clear_fixed_version_when_not_shared_with_the_target_project | |
1147 issue = Issue.find(1) | |
1148 issue.update_attribute(:fixed_version_id, 1) | |
1149 issue.project = Project.find(5) | |
1150 assert issue.save | |
1151 issue.reload | |
1152 assert_equal 5, issue.project_id | |
1153 # Cleared fixed_version | |
1154 assert_equal nil, issue.fixed_version | |
1155 end | |
1156 | |
1157 def test_move_to_another_project_should_keep_fixed_version_when_shared_systemwide | |
1158 issue = Issue.find(1) | |
1159 issue.update_attribute(:fixed_version_id, 7) | |
1160 issue.project = Project.find(2) | |
1161 assert issue.save | |
1162 issue.reload | |
1163 assert_equal 2, issue.project_id | |
1164 # Keep fixed_version | |
1165 assert_equal 7, issue.fixed_version_id | |
1166 end | |
1167 | |
1168 def test_move_to_another_project_should_keep_parent_if_valid | |
1169 issue = Issue.find(1) | |
1170 issue.update_attribute(:parent_issue_id, 2) | |
1171 issue.project = Project.find(3) | |
1172 assert issue.save | |
1173 issue.reload | |
1174 assert_equal 2, issue.parent_id | |
1175 end | |
1176 | |
1177 def test_move_to_another_project_should_clear_parent_if_not_valid | |
1178 issue = Issue.find(1) | |
1179 issue.update_attribute(:parent_issue_id, 2) | |
1180 issue.project = Project.find(2) | |
1181 assert issue.save | |
1182 issue.reload | |
1183 assert_nil issue.parent_id | |
1184 end | |
1185 | |
1186 def test_move_to_another_project_with_disabled_tracker | |
1187 issue = Issue.find(1) | |
1188 target = Project.find(2) | |
1189 target.tracker_ids = [3] | |
1190 target.save | |
1191 issue.project = target | |
1192 assert issue.save | |
1193 issue.reload | |
1194 assert_equal 2, issue.project_id | |
1195 assert_equal 3, issue.tracker_id | |
1196 end | |
1197 | |
1198 def test_copy_to_the_same_project | |
1199 issue = Issue.find(1) | |
1200 copy = issue.copy | |
1201 assert_difference 'Issue.count' do | |
1202 copy.save! | |
1203 end | |
1204 assert_kind_of Issue, copy | |
1205 assert_equal issue.project, copy.project | |
1206 assert_equal "125", copy.custom_value_for(2).value | |
1207 end | |
1208 | |
1209 def test_copy_to_another_project_and_tracker | |
1210 issue = Issue.find(1) | |
1211 copy = issue.copy(:project_id => 3, :tracker_id => 2) | |
1212 assert_difference 'Issue.count' do | |
1213 copy.save! | |
1214 end | |
1215 copy.reload | |
1216 assert_kind_of Issue, copy | |
1217 assert_equal Project.find(3), copy.project | |
1218 assert_equal Tracker.find(2), copy.tracker | |
1219 # Custom field #2 is not associated with target tracker | |
1220 assert_nil copy.custom_value_for(2) | |
1221 end | |
1222 | |
1223 test "#copy should not create a journal" do | |
1224 copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3) | |
1225 copy.save! | |
1226 assert_equal 0, copy.reload.journals.size | |
1227 end | |
1228 | |
1229 test "#copy should allow assigned_to changes" do | |
1230 copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3) | |
1231 assert_equal 3, copy.assigned_to_id | |
1232 end | |
1233 | |
1234 test "#copy should allow status changes" do | |
1235 copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :status_id => 2) | |
1236 assert_equal 2, copy.status_id | |
1237 end | |
1238 | |
1239 test "#copy should allow start date changes" do | |
1240 date = Date.today | |
1241 copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :start_date => date) | |
1242 assert_equal date, copy.start_date | |
1243 end | |
1244 | |
1245 test "#copy should allow due date changes" do | |
1246 date = Date.today | |
1247 copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :due_date => date) | |
1248 assert_equal date, copy.due_date | |
1249 end | |
1250 | |
1251 test "#copy should set current user as author" do | |
1252 User.current = User.find(9) | |
1253 copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2) | |
1254 assert_equal User.current, copy.author | |
1255 end | |
1256 | |
1257 test "#copy should create a journal with notes" do | |
1258 date = Date.today | |
1259 notes = "Notes added when copying" | |
1260 copy = Issue.find(1).copy(:project_id => 3, :tracker_id => 2, :start_date => date) | |
1261 copy.init_journal(User.current, notes) | |
1262 copy.save! | |
1263 | |
1264 assert_equal 1, copy.journals.size | |
1265 journal = copy.journals.first | |
1266 assert_equal 0, journal.details.size | |
1267 assert_equal notes, journal.notes | |
1268 end | |
1269 | |
1270 def test_valid_parent_project | |
1271 issue = Issue.find(1) | |
1272 issue_in_same_project = Issue.find(2) | |
1273 issue_in_child_project = Issue.find(5) | |
1274 issue_in_grandchild_project = Issue.generate!(:project_id => 6, :tracker_id => 1) | |
1275 issue_in_other_child_project = Issue.find(6) | |
1276 issue_in_different_tree = Issue.find(4) | |
1277 | |
1278 with_settings :cross_project_subtasks => '' do | |
1279 assert_equal true, issue.valid_parent_project?(issue_in_same_project) | |
1280 assert_equal false, issue.valid_parent_project?(issue_in_child_project) | |
1281 assert_equal false, issue.valid_parent_project?(issue_in_grandchild_project) | |
1282 assert_equal false, issue.valid_parent_project?(issue_in_different_tree) | |
1283 end | |
1284 | |
1285 with_settings :cross_project_subtasks => 'system' do | |
1286 assert_equal true, issue.valid_parent_project?(issue_in_same_project) | |
1287 assert_equal true, issue.valid_parent_project?(issue_in_child_project) | |
1288 assert_equal true, issue.valid_parent_project?(issue_in_different_tree) | |
1289 end | |
1290 | |
1291 with_settings :cross_project_subtasks => 'tree' do | |
1292 assert_equal true, issue.valid_parent_project?(issue_in_same_project) | |
1293 assert_equal true, issue.valid_parent_project?(issue_in_child_project) | |
1294 assert_equal true, issue.valid_parent_project?(issue_in_grandchild_project) | |
1295 assert_equal false, issue.valid_parent_project?(issue_in_different_tree) | |
1296 | |
1297 assert_equal true, issue_in_child_project.valid_parent_project?(issue_in_same_project) | |
1298 assert_equal true, issue_in_child_project.valid_parent_project?(issue_in_other_child_project) | |
1299 end | |
1300 | |
1301 with_settings :cross_project_subtasks => 'descendants' do | |
1302 assert_equal true, issue.valid_parent_project?(issue_in_same_project) | |
1303 assert_equal false, issue.valid_parent_project?(issue_in_child_project) | |
1304 assert_equal false, issue.valid_parent_project?(issue_in_grandchild_project) | |
1305 assert_equal false, issue.valid_parent_project?(issue_in_different_tree) | |
1306 | |
1307 assert_equal true, issue_in_child_project.valid_parent_project?(issue) | |
1308 assert_equal false, issue_in_child_project.valid_parent_project?(issue_in_other_child_project) | |
1309 end | |
1310 end | |
1311 | |
1312 def test_recipients_should_include_previous_assignee | |
1313 user = User.find(3) | |
1314 user.members.update_all ["mail_notification = ?", false] | |
1315 user.update_attribute :mail_notification, 'only_assigned' | |
1316 | |
1317 issue = Issue.find(2) | |
1318 issue.assigned_to = nil | |
1319 assert_include user.mail, issue.recipients | |
1320 issue.save! | |
1321 assert !issue.recipients.include?(user.mail) | |
1322 end | |
1323 | |
1324 def test_recipients_should_not_include_users_that_cannot_view_the_issue | |
1325 issue = Issue.find(12) | |
1326 assert issue.recipients.include?(issue.author.mail) | |
1327 # copy the issue to a private project | |
1328 copy = issue.copy(:project_id => 5, :tracker_id => 2) | |
1329 # author is not a member of project anymore | |
1330 assert !copy.recipients.include?(copy.author.mail) | |
1331 end | |
1332 | |
1333 def test_recipients_should_include_the_assigned_group_members | |
1334 group_member = User.generate! | |
1335 group = Group.generate! | |
1336 group.users << group_member | |
1337 | |
1338 issue = Issue.find(12) | |
1339 issue.assigned_to = group | |
1340 assert issue.recipients.include?(group_member.mail) | |
1341 end | |
1342 | |
1343 def test_watcher_recipients_should_not_include_users_that_cannot_view_the_issue | |
1344 user = User.find(3) | |
1345 issue = Issue.find(9) | |
1346 Watcher.create!(:user => user, :watchable => issue) | |
1347 assert issue.watched_by?(user) | |
1348 assert !issue.watcher_recipients.include?(user.mail) | |
1349 end | |
1350 | |
1351 def test_issue_destroy | |
1352 Issue.find(1).destroy | |
1353 assert_nil Issue.find_by_id(1) | |
1354 assert_nil TimeEntry.find_by_issue_id(1) | |
1355 end | |
1356 | |
1357 def test_destroying_a_deleted_issue_should_not_raise_an_error | |
1358 issue = Issue.find(1) | |
1359 Issue.find(1).destroy | |
1360 | |
1361 assert_nothing_raised do | |
1362 assert_no_difference 'Issue.count' do | |
1363 issue.destroy | |
1364 end | |
1365 assert issue.destroyed? | |
1366 end | |
1367 end | |
1368 | |
1369 def test_destroying_a_stale_issue_should_not_raise_an_error | |
1370 issue = Issue.find(1) | |
1371 Issue.find(1).update_attribute :subject, "Updated" | |
1372 | |
1373 assert_nothing_raised do | |
1374 assert_difference 'Issue.count', -1 do | |
1375 issue.destroy | |
1376 end | |
1377 assert issue.destroyed? | |
1378 end | |
1379 end | |
1380 | |
1381 def test_blocked | |
1382 blocked_issue = Issue.find(9) | |
1383 blocking_issue = Issue.find(10) | |
1384 | |
1385 assert blocked_issue.blocked? | |
1386 assert !blocking_issue.blocked? | |
1387 end | |
1388 | |
1389 def test_blocked_issues_dont_allow_closed_statuses | |
1390 blocked_issue = Issue.find(9) | |
1391 | |
1392 allowed_statuses = blocked_issue.new_statuses_allowed_to(users(:users_002)) | |
1393 assert !allowed_statuses.empty? | |
1394 closed_statuses = allowed_statuses.select {|st| st.is_closed?} | |
1395 assert closed_statuses.empty? | |
1396 end | |
1397 | |
1398 def test_unblocked_issues_allow_closed_statuses | |
1399 blocking_issue = Issue.find(10) | |
1400 | |
1401 allowed_statuses = blocking_issue.new_statuses_allowed_to(users(:users_002)) | |
1402 assert !allowed_statuses.empty? | |
1403 closed_statuses = allowed_statuses.select {|st| st.is_closed?} | |
1404 assert !closed_statuses.empty? | |
1405 end | |
1406 | |
1407 def test_reschedule_an_issue_without_dates | |
1408 with_settings :non_working_week_days => [] do | |
1409 issue = Issue.new(:start_date => nil, :due_date => nil) | |
1410 issue.reschedule_on '2012-10-09'.to_date | |
1411 assert_equal '2012-10-09'.to_date, issue.start_date | |
1412 assert_equal '2012-10-09'.to_date, issue.due_date | |
1413 end | |
1414 | |
1415 with_settings :non_working_week_days => %w(6 7) do | |
1416 issue = Issue.new(:start_date => nil, :due_date => nil) | |
1417 issue.reschedule_on '2012-10-09'.to_date | |
1418 assert_equal '2012-10-09'.to_date, issue.start_date | |
1419 assert_equal '2012-10-09'.to_date, issue.due_date | |
1420 | |
1421 issue = Issue.new(:start_date => nil, :due_date => nil) | |
1422 issue.reschedule_on '2012-10-13'.to_date | |
1423 assert_equal '2012-10-15'.to_date, issue.start_date | |
1424 assert_equal '2012-10-15'.to_date, issue.due_date | |
1425 end | |
1426 end | |
1427 | |
1428 def test_reschedule_an_issue_with_start_date | |
1429 with_settings :non_working_week_days => [] do | |
1430 issue = Issue.new(:start_date => '2012-10-09', :due_date => nil) | |
1431 issue.reschedule_on '2012-10-13'.to_date | |
1432 assert_equal '2012-10-13'.to_date, issue.start_date | |
1433 assert_equal '2012-10-13'.to_date, issue.due_date | |
1434 end | |
1435 | |
1436 with_settings :non_working_week_days => %w(6 7) do | |
1437 issue = Issue.new(:start_date => '2012-10-09', :due_date => nil) | |
1438 issue.reschedule_on '2012-10-11'.to_date | |
1439 assert_equal '2012-10-11'.to_date, issue.start_date | |
1440 assert_equal '2012-10-11'.to_date, issue.due_date | |
1441 | |
1442 issue = Issue.new(:start_date => '2012-10-09', :due_date => nil) | |
1443 issue.reschedule_on '2012-10-13'.to_date | |
1444 assert_equal '2012-10-15'.to_date, issue.start_date | |
1445 assert_equal '2012-10-15'.to_date, issue.due_date | |
1446 end | |
1447 end | |
1448 | |
1449 def test_reschedule_an_issue_with_start_and_due_dates | |
1450 with_settings :non_working_week_days => [] do | |
1451 issue = Issue.new(:start_date => '2012-10-09', :due_date => '2012-10-15') | |
1452 issue.reschedule_on '2012-10-13'.to_date | |
1453 assert_equal '2012-10-13'.to_date, issue.start_date | |
1454 assert_equal '2012-10-19'.to_date, issue.due_date | |
1455 end | |
1456 | |
1457 with_settings :non_working_week_days => %w(6 7) do | |
1458 issue = Issue.new(:start_date => '2012-10-09', :due_date => '2012-10-19') # 8 working days | |
1459 issue.reschedule_on '2012-10-11'.to_date | |
1460 assert_equal '2012-10-11'.to_date, issue.start_date | |
1461 assert_equal '2012-10-23'.to_date, issue.due_date | |
1462 | |
1463 issue = Issue.new(:start_date => '2012-10-09', :due_date => '2012-10-19') | |
1464 issue.reschedule_on '2012-10-13'.to_date | |
1465 assert_equal '2012-10-15'.to_date, issue.start_date | |
1466 assert_equal '2012-10-25'.to_date, issue.due_date | |
1467 end | |
1468 end | |
1469 | |
1470 def test_rescheduling_an_issue_to_a_later_due_date_should_reschedule_following_issue | |
1471 issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17') | |
1472 issue2 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17') | |
1473 IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, | |
1474 :relation_type => IssueRelation::TYPE_PRECEDES) | |
1475 assert_equal Date.parse('2012-10-18'), issue2.reload.start_date | |
1476 | |
1477 issue1.due_date = '2012-10-23' | |
1478 issue1.save! | |
1479 issue2.reload | |
1480 assert_equal Date.parse('2012-10-24'), issue2.start_date | |
1481 assert_equal Date.parse('2012-10-26'), issue2.due_date | |
1482 end | |
1483 | |
1484 def test_rescheduling_an_issue_to_an_earlier_due_date_should_reschedule_following_issue | |
1485 issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17') | |
1486 issue2 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17') | |
1487 IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, | |
1488 :relation_type => IssueRelation::TYPE_PRECEDES) | |
1489 assert_equal Date.parse('2012-10-18'), issue2.reload.start_date | |
1490 | |
1491 issue1.start_date = '2012-09-17' | |
1492 issue1.due_date = '2012-09-18' | |
1493 issue1.save! | |
1494 issue2.reload | |
1495 assert_equal Date.parse('2012-09-19'), issue2.start_date | |
1496 assert_equal Date.parse('2012-09-21'), issue2.due_date | |
1497 end | |
1498 | |
1499 def test_rescheduling_reschedule_following_issue_earlier_should_consider_other_preceding_issues | |
1500 issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17') | |
1501 issue2 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17') | |
1502 issue3 = Issue.generate!(:start_date => '2012-10-01', :due_date => '2012-10-02') | |
1503 IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, | |
1504 :relation_type => IssueRelation::TYPE_PRECEDES) | |
1505 IssueRelation.create!(:issue_from => issue3, :issue_to => issue2, | |
1506 :relation_type => IssueRelation::TYPE_PRECEDES) | |
1507 assert_equal Date.parse('2012-10-18'), issue2.reload.start_date | |
1508 | |
1509 issue1.start_date = '2012-09-17' | |
1510 issue1.due_date = '2012-09-18' | |
1511 issue1.save! | |
1512 issue2.reload | |
1513 # Issue 2 must start after Issue 3 | |
1514 assert_equal Date.parse('2012-10-03'), issue2.start_date | |
1515 assert_equal Date.parse('2012-10-05'), issue2.due_date | |
1516 end | |
1517 | |
1518 def test_rescheduling_a_stale_issue_should_not_raise_an_error | |
1519 with_settings :non_working_week_days => [] do | |
1520 stale = Issue.find(1) | |
1521 issue = Issue.find(1) | |
1522 issue.subject = "Updated" | |
1523 issue.save! | |
1524 date = 10.days.from_now.to_date | |
1525 assert_nothing_raised do | |
1526 stale.reschedule_on!(date) | |
1527 end | |
1528 assert_equal date, stale.reload.start_date | |
1529 end | |
1530 end | |
1531 | |
1532 def test_child_issue_should_consider_parent_soonest_start_on_create | |
1533 set_language_if_valid 'en' | |
1534 issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17') | |
1535 issue2 = Issue.generate!(:start_date => '2012-10-18', :due_date => '2012-10-20') | |
1536 IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, | |
1537 :relation_type => IssueRelation::TYPE_PRECEDES) | |
1538 issue1.reload | |
1539 issue2.reload | |
1540 assert_equal Date.parse('2012-10-18'), issue2.start_date | |
1541 | |
1542 child = Issue.new(:parent_issue_id => issue2.id, :start_date => '2012-10-16', | |
1543 :project_id => 1, :tracker_id => 1, :status_id => 1, :subject => 'Child', :author_id => 1) | |
1544 assert !child.valid? | |
1545 assert_include 'Start date is invalid', child.errors.full_messages | |
1546 assert_equal Date.parse('2012-10-18'), child.soonest_start | |
1547 child.start_date = '2012-10-18' | |
1548 assert child.save | |
1549 end | |
1550 | |
1551 def test_setting_parent_to_a_dependent_issue_should_not_validate | |
1552 set_language_if_valid 'en' | |
1553 issue1 = Issue.generate! | |
1554 issue2 = Issue.generate! | |
1555 issue3 = Issue.generate! | |
1556 IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_PRECEDES) | |
1557 IssueRelation.create!(:issue_from => issue3, :issue_to => issue1, :relation_type => IssueRelation::TYPE_PRECEDES) | |
1558 issue3.reload | |
1559 issue3.parent_issue_id = issue2.id | |
1560 assert !issue3.valid? | |
1561 assert_include 'Parent task is invalid', issue3.errors.full_messages | |
1562 end | |
1563 | |
1564 def test_setting_parent_should_not_allow_circular_dependency | |
1565 set_language_if_valid 'en' | |
1566 issue1 = Issue.generate! | |
1567 issue2 = Issue.generate! | |
1568 IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_PRECEDES) | |
1569 issue3 = Issue.generate! | |
1570 issue2.reload | |
1571 issue2.parent_issue_id = issue3.id | |
1572 issue2.save! | |
1573 issue4 = Issue.generate! | |
1574 IssueRelation.create!(:issue_from => issue3, :issue_to => issue4, :relation_type => IssueRelation::TYPE_PRECEDES) | |
1575 issue4.reload | |
1576 issue4.parent_issue_id = issue1.id | |
1577 assert !issue4.valid? | |
1578 assert_include 'Parent task is invalid', issue4.errors.full_messages | |
1579 end | |
1580 | |
1581 def test_overdue | |
1582 assert Issue.new(:due_date => 1.day.ago.to_date).overdue? | |
1583 assert !Issue.new(:due_date => Date.today).overdue? | |
1584 assert !Issue.new(:due_date => 1.day.from_now.to_date).overdue? | |
1585 assert !Issue.new(:due_date => nil).overdue? | |
1586 assert !Issue.new(:due_date => 1.day.ago.to_date, | |
1587 :status => IssueStatus.where(:is_closed => true).first | |
1588 ).overdue? | |
1589 end | |
1590 | |
1591 test "#behind_schedule? should be false if the issue has no start_date" do | |
1592 assert !Issue.new(:start_date => nil, | |
1593 :due_date => 1.day.from_now.to_date, | |
1594 :done_ratio => 0).behind_schedule? | |
1595 end | |
1596 | |
1597 test "#behind_schedule? should be false if the issue has no end_date" do | |
1598 assert !Issue.new(:start_date => 1.day.from_now.to_date, | |
1599 :due_date => nil, | |
1600 :done_ratio => 0).behind_schedule? | |
1601 end | |
1602 | |
1603 test "#behind_schedule? should be false if the issue has more done than it's calendar time" do | |
1604 assert !Issue.new(:start_date => 50.days.ago.to_date, | |
1605 :due_date => 50.days.from_now.to_date, | |
1606 :done_ratio => 90).behind_schedule? | |
1607 end | |
1608 | |
1609 test "#behind_schedule? should be true if the issue hasn't been started at all" do | |
1610 assert Issue.new(:start_date => 1.day.ago.to_date, | |
1611 :due_date => 1.day.from_now.to_date, | |
1612 :done_ratio => 0).behind_schedule? | |
1613 end | |
1614 | |
1615 test "#behind_schedule? should be true if the issue has used more calendar time than it's done ratio" do | |
1616 assert Issue.new(:start_date => 100.days.ago.to_date, | |
1617 :due_date => Date.today, | |
1618 :done_ratio => 90).behind_schedule? | |
1619 end | |
1620 | |
1621 test "#assignable_users should be Users" do | |
1622 assert_kind_of User, Issue.find(1).assignable_users.first | |
1623 end | |
1624 | |
1625 test "#assignable_users should include the issue author" do | |
1626 non_project_member = User.generate! | |
1627 issue = Issue.generate!(:author => non_project_member) | |
1628 | |
1629 assert issue.assignable_users.include?(non_project_member) | |
1630 end | |
1631 | |
1632 test "#assignable_users should include the current assignee" do | |
1633 user = User.generate! | |
1634 issue = Issue.generate!(:assigned_to => user) | |
1635 user.lock! | |
1636 | |
1637 assert Issue.find(issue.id).assignable_users.include?(user) | |
1638 end | |
1639 | |
1640 test "#assignable_users should not show the issue author twice" do | |
1641 assignable_user_ids = Issue.find(1).assignable_users.collect(&:id) | |
1642 assert_equal 2, assignable_user_ids.length | |
1643 | |
1644 assignable_user_ids.each do |user_id| | |
1645 assert_equal 1, assignable_user_ids.select {|i| i == user_id}.length, | |
1646 "User #{user_id} appears more or less than once" | |
1647 end | |
1648 end | |
1649 | |
1650 test "#assignable_users with issue_group_assignment should include groups" do | |
1651 issue = Issue.new(:project => Project.find(2)) | |
1652 | |
1653 with_settings :issue_group_assignment => '1' do | |
1654 assert_equal %w(Group User), issue.assignable_users.map {|a| a.class.name}.uniq.sort | |
1655 assert issue.assignable_users.include?(Group.find(11)) | |
1656 end | |
1657 end | |
1658 | |
1659 test "#assignable_users without issue_group_assignment should not include groups" do | |
1660 issue = Issue.new(:project => Project.find(2)) | |
1661 | |
1662 with_settings :issue_group_assignment => '0' do | |
1663 assert_equal %w(User), issue.assignable_users.map {|a| a.class.name}.uniq.sort | |
1664 assert !issue.assignable_users.include?(Group.find(11)) | |
1665 end | |
1666 end | |
1667 | |
1668 def test_create_should_send_email_notification | |
1669 ActionMailer::Base.deliveries.clear | |
1670 issue = Issue.new(:project_id => 1, :tracker_id => 1, | |
1671 :author_id => 3, :status_id => 1, | |
1672 :priority => IssuePriority.all.first, | |
1673 :subject => 'test_create', :estimated_hours => '1:30') | |
1674 | |
1675 assert issue.save | |
1676 assert_equal 1, ActionMailer::Base.deliveries.size | |
1677 end | |
1678 | |
1679 def test_stale_issue_should_not_send_email_notification | |
1680 ActionMailer::Base.deliveries.clear | |
1681 issue = Issue.find(1) | |
1682 stale = Issue.find(1) | |
1683 | |
1684 issue.init_journal(User.find(1)) | |
1685 issue.subject = 'Subjet update' | |
1686 assert issue.save | |
1687 assert_equal 1, ActionMailer::Base.deliveries.size | |
1688 ActionMailer::Base.deliveries.clear | |
1689 | |
1690 stale.init_journal(User.find(1)) | |
1691 stale.subject = 'Another subjet update' | |
1692 assert_raise ActiveRecord::StaleObjectError do | |
1693 stale.save | |
1694 end | |
1695 assert ActionMailer::Base.deliveries.empty? | |
1696 end | |
1697 | |
1698 def test_journalized_description | |
1699 IssueCustomField.delete_all | |
1700 | |
1701 i = Issue.first | |
1702 old_description = i.description | |
1703 new_description = "This is the new description" | |
1704 | |
1705 i.init_journal(User.find(2)) | |
1706 i.description = new_description | |
1707 assert_difference 'Journal.count', 1 do | |
1708 assert_difference 'JournalDetail.count', 1 do | |
1709 i.save! | |
1710 end | |
1711 end | |
1712 | |
1713 detail = JournalDetail.first(:order => 'id DESC') | |
1714 assert_equal i, detail.journal.journalized | |
1715 assert_equal 'attr', detail.property | |
1716 assert_equal 'description', detail.prop_key | |
1717 assert_equal old_description, detail.old_value | |
1718 assert_equal new_description, detail.value | |
1719 end | |
1720 | |
1721 def test_blank_descriptions_should_not_be_journalized | |
1722 IssueCustomField.delete_all | |
1723 Issue.update_all("description = NULL", "id=1") | |
1724 | |
1725 i = Issue.find(1) | |
1726 i.init_journal(User.find(2)) | |
1727 i.subject = "blank description" | |
1728 i.description = "\r\n" | |
1729 | |
1730 assert_difference 'Journal.count', 1 do | |
1731 assert_difference 'JournalDetail.count', 1 do | |
1732 i.save! | |
1733 end | |
1734 end | |
1735 end | |
1736 | |
1737 def test_journalized_multi_custom_field | |
1738 field = IssueCustomField.create!(:name => 'filter', :field_format => 'list', | |
1739 :is_filter => true, :is_for_all => true, | |
1740 :tracker_ids => [1], | |
1741 :possible_values => ['value1', 'value2', 'value3'], | |
1742 :multiple => true) | |
1743 | |
1744 issue = Issue.create!(:project_id => 1, :tracker_id => 1, | |
1745 :subject => 'Test', :author_id => 1) | |
1746 | |
1747 assert_difference 'Journal.count' do | |
1748 assert_difference 'JournalDetail.count' do | |
1749 issue.init_journal(User.first) | |
1750 issue.custom_field_values = {field.id => ['value1']} | |
1751 issue.save! | |
1752 end | |
1753 assert_difference 'JournalDetail.count' do | |
1754 issue.init_journal(User.first) | |
1755 issue.custom_field_values = {field.id => ['value1', 'value2']} | |
1756 issue.save! | |
1757 end | |
1758 assert_difference 'JournalDetail.count', 2 do | |
1759 issue.init_journal(User.first) | |
1760 issue.custom_field_values = {field.id => ['value3', 'value2']} | |
1761 issue.save! | |
1762 end | |
1763 assert_difference 'JournalDetail.count', 2 do | |
1764 issue.init_journal(User.first) | |
1765 issue.custom_field_values = {field.id => nil} | |
1766 issue.save! | |
1767 end | |
1768 end | |
1769 end | |
1770 | |
1771 def test_description_eol_should_be_normalized | |
1772 i = Issue.new(:description => "CR \r LF \n CRLF \r\n") | |
1773 assert_equal "CR \r\n LF \r\n CRLF \r\n", i.description | |
1774 end | |
1775 | |
1776 def test_saving_twice_should_not_duplicate_journal_details | |
1777 i = Issue.first | |
1778 i.init_journal(User.find(2), 'Some notes') | |
1779 # initial changes | |
1780 i.subject = 'New subject' | |
1781 i.done_ratio = i.done_ratio + 10 | |
1782 assert_difference 'Journal.count' do | |
1783 assert i.save | |
1784 end | |
1785 # 1 more change | |
1786 i.priority = IssuePriority.where("id <> ?", i.priority_id).first | |
1787 assert_no_difference 'Journal.count' do | |
1788 assert_difference 'JournalDetail.count', 1 do | |
1789 i.save | |
1790 end | |
1791 end | |
1792 # no more change | |
1793 assert_no_difference 'Journal.count' do | |
1794 assert_no_difference 'JournalDetail.count' do | |
1795 i.save | |
1796 end | |
1797 end | |
1798 end | |
1799 | |
1800 def test_all_dependent_issues | |
1801 IssueRelation.delete_all | |
1802 assert IssueRelation.create!(:issue_from => Issue.find(1), | |
1803 :issue_to => Issue.find(2), | |
1804 :relation_type => IssueRelation::TYPE_PRECEDES) | |
1805 assert IssueRelation.create!(:issue_from => Issue.find(2), | |
1806 :issue_to => Issue.find(3), | |
1807 :relation_type => IssueRelation::TYPE_PRECEDES) | |
1808 assert IssueRelation.create!(:issue_from => Issue.find(3), | |
1809 :issue_to => Issue.find(8), | |
1810 :relation_type => IssueRelation::TYPE_PRECEDES) | |
1811 | |
1812 assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort | |
1813 end | |
1814 | |
1815 def test_all_dependent_issues_with_subtask | |
1816 IssueRelation.delete_all | |
1817 | |
1818 project = Project.generate!(:name => "testproject") | |
1819 | |
1820 parentIssue = Issue.generate!(:project => project) | |
1821 childIssue1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue.id) | |
1822 childIssue2 = Issue.generate!(:project => project, :parent_issue_id => parentIssue.id) | |
1823 | |
1824 assert_equal [childIssue1.id, childIssue2.id].sort, parentIssue.all_dependent_issues.collect(&:id).uniq.sort | |
1825 end | |
1826 | |
1827 def test_all_dependent_issues_does_not_include_self | |
1828 IssueRelation.delete_all | |
1829 | |
1830 project = Project.generate!(:name => "testproject") | |
1831 | |
1832 parentIssue = Issue.generate!(:project => project) | |
1833 childIssue = Issue.generate!(:project => project, :parent_issue_id => parentIssue.id) | |
1834 | |
1835 assert_equal [childIssue.id], parentIssue.all_dependent_issues.collect(&:id) | |
1836 end | |
1837 | |
1838 def test_all_dependent_issues_with_parenttask_and_sibling | |
1839 IssueRelation.delete_all | |
1840 | |
1841 project = Project.generate!(:name => "testproject") | |
1842 | |
1843 parentIssue = Issue.generate!(:project => project) | |
1844 childIssue1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue.id) | |
1845 childIssue2 = Issue.generate!(:project => project, :parent_issue_id => parentIssue.id) | |
1846 | |
1847 assert_equal [parentIssue.id].sort, childIssue1.all_dependent_issues.collect(&:id) | |
1848 end | |
1849 | |
1850 def test_all_dependent_issues_with_relation_to_leaf_in_other_tree | |
1851 IssueRelation.delete_all | |
1852 | |
1853 project = Project.generate!(:name => "testproject") | |
1854 | |
1855 parentIssue1 = Issue.generate!(:project => project) | |
1856 childIssue1_1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue1.id) | |
1857 childIssue1_2 = Issue.generate!(:project => project, :parent_issue_id => parentIssue1.id) | |
1858 | |
1859 parentIssue2 = Issue.generate!(:project => project) | |
1860 childIssue2_1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue2.id) | |
1861 childIssue2_2 = Issue.generate!(:project => project, :parent_issue_id => parentIssue2.id) | |
1862 | |
1863 | |
1864 assert IssueRelation.create(:issue_from => parentIssue1, | |
1865 :issue_to => childIssue2_2, | |
1866 :relation_type => IssueRelation::TYPE_BLOCKS) | |
1867 | |
1868 assert_equal [childIssue1_1.id, childIssue1_2.id, parentIssue2.id, childIssue2_2.id].sort, | |
1869 parentIssue1.all_dependent_issues.collect(&:id).uniq.sort | |
1870 end | |
1871 | |
1872 def test_all_dependent_issues_with_relation_to_parent_in_other_tree | |
1873 IssueRelation.delete_all | |
1874 | |
1875 project = Project.generate!(:name => "testproject") | |
1876 | |
1877 parentIssue1 = Issue.generate!(:project => project) | |
1878 childIssue1_1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue1.id) | |
1879 childIssue1_2 = Issue.generate!(:project => project, :parent_issue_id => parentIssue1.id) | |
1880 | |
1881 parentIssue2 = Issue.generate!(:project => project) | |
1882 childIssue2_1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue2.id) | |
1883 childIssue2_2 = Issue.generate!(:project => project, :parent_issue_id => parentIssue2.id) | |
1884 | |
1885 | |
1886 assert IssueRelation.create(:issue_from => parentIssue1, | |
1887 :issue_to => parentIssue2, | |
1888 :relation_type => IssueRelation::TYPE_BLOCKS) | |
1889 | |
1890 assert_equal [childIssue1_1.id, childIssue1_2.id, parentIssue2.id, childIssue2_1.id, childIssue2_2.id].sort, | |
1891 parentIssue1.all_dependent_issues.collect(&:id).uniq.sort | |
1892 end | |
1893 | |
1894 def test_all_dependent_issues_with_transitive_relation | |
1895 IssueRelation.delete_all | |
1896 | |
1897 project = Project.generate!(:name => "testproject") | |
1898 | |
1899 parentIssue1 = Issue.generate!(:project => project) | |
1900 childIssue1_1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue1.id) | |
1901 | |
1902 parentIssue2 = Issue.generate!(:project => project) | |
1903 childIssue2_1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue2.id) | |
1904 | |
1905 independentIssue = Issue.generate!(:project => project) | |
1906 | |
1907 assert IssueRelation.create(:issue_from => parentIssue1, | |
1908 :issue_to => childIssue2_1, | |
1909 :relation_type => IssueRelation::TYPE_RELATES) | |
1910 | |
1911 assert IssueRelation.create(:issue_from => childIssue2_1, | |
1912 :issue_to => independentIssue, | |
1913 :relation_type => IssueRelation::TYPE_RELATES) | |
1914 | |
1915 assert_equal [childIssue1_1.id, parentIssue2.id, childIssue2_1.id, independentIssue.id].sort, | |
1916 parentIssue1.all_dependent_issues.collect(&:id).uniq.sort | |
1917 end | |
1918 | |
1919 def test_all_dependent_issues_with_transitive_relation2 | |
1920 IssueRelation.delete_all | |
1921 | |
1922 project = Project.generate!(:name => "testproject") | |
1923 | |
1924 parentIssue1 = Issue.generate!(:project => project) | |
1925 childIssue1_1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue1.id) | |
1926 | |
1927 parentIssue2 = Issue.generate!(:project => project) | |
1928 childIssue2_1 = Issue.generate!(:project => project, :parent_issue_id => parentIssue2.id) | |
1929 | |
1930 independentIssue = Issue.generate!(:project => project) | |
1931 | |
1932 assert IssueRelation.create(:issue_from => parentIssue1, | |
1933 :issue_to => independentIssue, | |
1934 :relation_type => IssueRelation::TYPE_RELATES) | |
1935 | |
1936 assert IssueRelation.create(:issue_from => independentIssue, | |
1937 :issue_to => childIssue2_1, | |
1938 :relation_type => IssueRelation::TYPE_RELATES) | |
1939 | |
1940 assert_equal [childIssue1_1.id, parentIssue2.id, childIssue2_1.id, independentIssue.id].sort, | |
1941 parentIssue1.all_dependent_issues.collect(&:id).uniq.sort | |
1942 | |
1943 end | |
1944 | |
1945 def test_all_dependent_issues_with_persistent_circular_dependency | |
1946 IssueRelation.delete_all | |
1947 assert IssueRelation.create!(:issue_from => Issue.find(1), | |
1948 :issue_to => Issue.find(2), | |
1949 :relation_type => IssueRelation::TYPE_PRECEDES) | |
1950 assert IssueRelation.create!(:issue_from => Issue.find(2), | |
1951 :issue_to => Issue.find(3), | |
1952 :relation_type => IssueRelation::TYPE_PRECEDES) | |
1953 | |
1954 r = IssueRelation.create!(:issue_from => Issue.find(3), | |
1955 :issue_to => Issue.find(7), | |
1956 :relation_type => IssueRelation::TYPE_PRECEDES) | |
1957 IssueRelation.update_all("issue_to_id = 1", ["id = ?", r.id]) | |
1958 | |
1959 assert_equal [2, 3], Issue.find(1).all_dependent_issues.collect(&:id).sort | |
1960 end | |
1961 | |
1962 def test_all_dependent_issues_with_persistent_multiple_circular_dependencies | |
1963 IssueRelation.delete_all | |
1964 assert IssueRelation.create!(:issue_from => Issue.find(1), | |
1965 :issue_to => Issue.find(2), | |
1966 :relation_type => IssueRelation::TYPE_RELATES) | |
1967 assert IssueRelation.create!(:issue_from => Issue.find(2), | |
1968 :issue_to => Issue.find(3), | |
1969 :relation_type => IssueRelation::TYPE_RELATES) | |
1970 assert IssueRelation.create!(:issue_from => Issue.find(3), | |
1971 :issue_to => Issue.find(8), | |
1972 :relation_type => IssueRelation::TYPE_RELATES) | |
1973 | |
1974 r = IssueRelation.create!(:issue_from => Issue.find(8), | |
1975 :issue_to => Issue.find(7), | |
1976 :relation_type => IssueRelation::TYPE_RELATES) | |
1977 IssueRelation.update_all("issue_to_id = 2", ["id = ?", r.id]) | |
1978 | |
1979 r = IssueRelation.create!(:issue_from => Issue.find(3), | |
1980 :issue_to => Issue.find(7), | |
1981 :relation_type => IssueRelation::TYPE_RELATES) | |
1982 IssueRelation.update_all("issue_to_id = 1", ["id = ?", r.id]) | |
1983 | |
1984 assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort | |
1985 end | |
1986 | |
1987 test "#done_ratio should use the issue_status according to Setting.issue_done_ratio" do | |
1988 @issue = Issue.find(1) | |
1989 @issue_status = IssueStatus.find(1) | |
1990 @issue_status.update_attribute(:default_done_ratio, 50) | |
1991 @issue2 = Issue.find(2) | |
1992 @issue_status2 = IssueStatus.find(2) | |
1993 @issue_status2.update_attribute(:default_done_ratio, 0) | |
1994 | |
1995 with_settings :issue_done_ratio => 'issue_field' do | |
1996 assert_equal 0, @issue.done_ratio | |
1997 assert_equal 30, @issue2.done_ratio | |
1998 end | |
1999 | |
2000 with_settings :issue_done_ratio => 'issue_status' do | |
2001 assert_equal 50, @issue.done_ratio | |
2002 assert_equal 0, @issue2.done_ratio | |
2003 end | |
2004 end | |
2005 | |
2006 test "#update_done_ratio_from_issue_status should update done_ratio according to Setting.issue_done_ratio" do | |
2007 @issue = Issue.find(1) | |
2008 @issue_status = IssueStatus.find(1) | |
2009 @issue_status.update_attribute(:default_done_ratio, 50) | |
2010 @issue2 = Issue.find(2) | |
2011 @issue_status2 = IssueStatus.find(2) | |
2012 @issue_status2.update_attribute(:default_done_ratio, 0) | |
2013 | |
2014 with_settings :issue_done_ratio => 'issue_field' do | |
2015 @issue.update_done_ratio_from_issue_status | |
2016 @issue2.update_done_ratio_from_issue_status | |
2017 | |
2018 assert_equal 0, @issue.read_attribute(:done_ratio) | |
2019 assert_equal 30, @issue2.read_attribute(:done_ratio) | |
2020 end | |
2021 | |
2022 with_settings :issue_done_ratio => 'issue_status' do | |
2023 @issue.update_done_ratio_from_issue_status | |
2024 @issue2.update_done_ratio_from_issue_status | |
2025 | |
2026 assert_equal 50, @issue.read_attribute(:done_ratio) | |
2027 assert_equal 0, @issue2.read_attribute(:done_ratio) | |
2028 end | |
2029 end | |
2030 | |
2031 test "#by_tracker" do | |
2032 User.current = User.anonymous | |
2033 groups = Issue.by_tracker(Project.find(1)) | |
2034 assert_equal 3, groups.size | |
2035 assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i} | |
2036 end | |
2037 | |
2038 test "#by_version" do | |
2039 User.current = User.anonymous | |
2040 groups = Issue.by_version(Project.find(1)) | |
2041 assert_equal 3, groups.size | |
2042 assert_equal 3, groups.inject(0) {|sum, group| sum + group['total'].to_i} | |
2043 end | |
2044 | |
2045 test "#by_priority" do | |
2046 User.current = User.anonymous | |
2047 groups = Issue.by_priority(Project.find(1)) | |
2048 assert_equal 4, groups.size | |
2049 assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i} | |
2050 end | |
2051 | |
2052 test "#by_category" do | |
2053 User.current = User.anonymous | |
2054 groups = Issue.by_category(Project.find(1)) | |
2055 assert_equal 2, groups.size | |
2056 assert_equal 3, groups.inject(0) {|sum, group| sum + group['total'].to_i} | |
2057 end | |
2058 | |
2059 test "#by_assigned_to" do | |
2060 User.current = User.anonymous | |
2061 groups = Issue.by_assigned_to(Project.find(1)) | |
2062 assert_equal 2, groups.size | |
2063 assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i} | |
2064 end | |
2065 | |
2066 test "#by_author" do | |
2067 User.current = User.anonymous | |
2068 groups = Issue.by_author(Project.find(1)) | |
2069 assert_equal 4, groups.size | |
2070 assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i} | |
2071 end | |
2072 | |
2073 test "#by_subproject" do | |
2074 User.current = User.anonymous | |
2075 groups = Issue.by_subproject(Project.find(1)) | |
2076 # Private descendant not visible | |
2077 assert_equal 1, groups.size | |
2078 assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i} | |
2079 end | |
2080 | |
2081 def test_recently_updated_scope | |
2082 #should return the last updated issue | |
2083 assert_equal Issue.reorder("updated_on DESC").first, Issue.recently_updated.limit(1).first | |
2084 end | |
2085 | |
2086 def test_on_active_projects_scope | |
2087 assert Project.find(2).archive | |
2088 | |
2089 before = Issue.on_active_project.length | |
2090 # test inclusion to results | |
2091 issue = Issue.generate!(:tracker => Project.find(2).trackers.first) | |
2092 assert_equal before + 1, Issue.on_active_project.length | |
2093 | |
2094 # Move to an archived project | |
2095 issue.project = Project.find(2) | |
2096 assert issue.save | |
2097 assert_equal before, Issue.on_active_project.length | |
2098 end | |
2099 | |
2100 test "Issue#recipients should include project recipients" do | |
2101 issue = Issue.generate! | |
2102 assert issue.project.recipients.present? | |
2103 issue.project.recipients.each do |project_recipient| | |
2104 assert issue.recipients.include?(project_recipient) | |
2105 end | |
2106 end | |
2107 | |
2108 test "Issue#recipients should include the author if the author is active" do | |
2109 issue = Issue.generate!(:author => User.generate!) | |
2110 assert issue.author, "No author set for Issue" | |
2111 assert issue.recipients.include?(issue.author.mail) | |
2112 end | |
2113 | |
2114 test "Issue#recipients should include the assigned to user if the assigned to user is active" do | |
2115 issue = Issue.generate!(:assigned_to => User.generate!) | |
2116 assert issue.assigned_to, "No assigned_to set for Issue" | |
2117 assert issue.recipients.include?(issue.assigned_to.mail) | |
2118 end | |
2119 | |
2120 test "Issue#recipients should not include users who opt out of all email" do | |
2121 issue = Issue.generate!(:author => User.generate!) | |
2122 issue.author.update_attribute(:mail_notification, :none) | |
2123 assert !issue.recipients.include?(issue.author.mail) | |
2124 end | |
2125 | |
2126 test "Issue#recipients should not include the issue author if they are only notified of assigned issues" do | |
2127 issue = Issue.generate!(:author => User.generate!) | |
2128 issue.author.update_attribute(:mail_notification, :only_assigned) | |
2129 assert !issue.recipients.include?(issue.author.mail) | |
2130 end | |
2131 | |
2132 test "Issue#recipients should not include the assigned user if they are only notified of owned issues" do | |
2133 issue = Issue.generate!(:assigned_to => User.generate!) | |
2134 issue.assigned_to.update_attribute(:mail_notification, :only_owner) | |
2135 assert !issue.recipients.include?(issue.assigned_to.mail) | |
2136 end | |
2137 | |
2138 def test_last_journal_id_with_journals_should_return_the_journal_id | |
2139 assert_equal 2, Issue.find(1).last_journal_id | |
2140 end | |
2141 | |
2142 def test_last_journal_id_without_journals_should_return_nil | |
2143 assert_nil Issue.find(3).last_journal_id | |
2144 end | |
2145 | |
2146 def test_journals_after_should_return_journals_with_greater_id | |
2147 assert_equal [Journal.find(2)], Issue.find(1).journals_after('1') | |
2148 assert_equal [], Issue.find(1).journals_after('2') | |
2149 end | |
2150 | |
2151 def test_journals_after_with_blank_arg_should_return_all_journals | |
2152 assert_equal [Journal.find(1), Journal.find(2)], Issue.find(1).journals_after('') | |
2153 end | |
2154 | |
2155 def test_css_classes_should_include_tracker | |
2156 issue = Issue.new(:tracker => Tracker.find(2)) | |
2157 classes = issue.css_classes.split(' ') | |
2158 assert_include 'tracker-2', classes | |
2159 end | |
2160 | |
2161 def test_css_classes_should_include_priority | |
2162 issue = Issue.new(:priority => IssuePriority.find(8)) | |
2163 classes = issue.css_classes.split(' ') | |
2164 assert_include 'priority-8', classes | |
2165 assert_include 'priority-highest', classes | |
2166 end | |
2167 | |
2168 def test_save_attachments_with_hash_should_save_attachments_in_keys_order | |
2169 set_tmp_attachments_directory | |
2170 issue = Issue.generate! | |
2171 issue.save_attachments({ | |
2172 'p0' => {'file' => mock_file_with_options(:original_filename => 'upload')}, | |
2173 '3' => {'file' => mock_file_with_options(:original_filename => 'bar')}, | |
2174 '1' => {'file' => mock_file_with_options(:original_filename => 'foo')} | |
2175 }) | |
2176 issue.attach_saved_attachments | |
2177 | |
2178 assert_equal 3, issue.reload.attachments.count | |
2179 assert_equal %w(upload foo bar), issue.attachments.map(&:filename) | |
2180 end | |
2181 | |
2182 def test_closed_on_should_be_nil_when_creating_an_open_issue | |
2183 issue = Issue.generate!(:status_id => 1).reload | |
2184 assert !issue.closed? | |
2185 assert_nil issue.closed_on | |
2186 end | |
2187 | |
2188 def test_closed_on_should_be_set_when_creating_a_closed_issue | |
2189 issue = Issue.generate!(:status_id => 5).reload | |
2190 assert issue.closed? | |
2191 assert_not_nil issue.closed_on | |
2192 assert_equal issue.updated_on, issue.closed_on | |
2193 assert_equal issue.created_on, issue.closed_on | |
2194 end | |
2195 | |
2196 def test_closed_on_should_be_nil_when_updating_an_open_issue | |
2197 issue = Issue.find(1) | |
2198 issue.subject = 'Not closed yet' | |
2199 issue.save! | |
2200 issue.reload | |
2201 assert_nil issue.closed_on | |
2202 end | |
2203 | |
2204 def test_closed_on_should_be_set_when_closing_an_open_issue | |
2205 issue = Issue.find(1) | |
2206 issue.subject = 'Now closed' | |
2207 issue.status_id = 5 | |
2208 issue.save! | |
2209 issue.reload | |
2210 assert_not_nil issue.closed_on | |
2211 assert_equal issue.updated_on, issue.closed_on | |
2212 end | |
2213 | |
2214 def test_closed_on_should_not_be_updated_when_updating_a_closed_issue | |
2215 issue = Issue.open(false).first | |
2216 was_closed_on = issue.closed_on | |
2217 assert_not_nil was_closed_on | |
2218 issue.subject = 'Updating a closed issue' | |
2219 issue.save! | |
2220 issue.reload | |
2221 assert_equal was_closed_on, issue.closed_on | |
2222 end | |
2223 | |
2224 def test_closed_on_should_be_preserved_when_reopening_a_closed_issue | |
2225 issue = Issue.open(false).first | |
2226 was_closed_on = issue.closed_on | |
2227 assert_not_nil was_closed_on | |
2228 issue.subject = 'Reopening a closed issue' | |
2229 issue.status_id = 1 | |
2230 issue.save! | |
2231 issue.reload | |
2232 assert !issue.closed? | |
2233 assert_equal was_closed_on, issue.closed_on | |
2234 end | |
2235 | |
2236 def test_status_was_should_return_nil_for_new_issue | |
2237 issue = Issue.new | |
2238 assert_nil issue.status_was | |
2239 end | |
2240 | |
2241 def test_status_was_should_return_status_before_change | |
2242 issue = Issue.find(1) | |
2243 issue.status = IssueStatus.find(2) | |
2244 assert_equal IssueStatus.find(1), issue.status_was | |
2245 end | |
2246 | |
2247 def test_status_was_should_be_reset_on_save | |
2248 issue = Issue.find(1) | |
2249 issue.status = IssueStatus.find(2) | |
2250 assert_equal IssueStatus.find(1), issue.status_was | |
2251 assert issue.save! | |
2252 assert_equal IssueStatus.find(2), issue.status_was | |
2253 end | |
2254 end |