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