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