##// END OF EJS Templates
Added a test to ensure 'Project' column can be removed on issues list (#8411)...
Jean-Baptiste Barth -
r5979:8a5015178069
parent child
Show More
@@ -1,1484 +1,1490
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'issues_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class IssuesController; def rescue_action(e) raise e end; end
23 23
24 24 class IssuesControllerTest < ActionController::TestCase
25 25 fixtures :projects,
26 26 :users,
27 27 :roles,
28 28 :members,
29 29 :member_roles,
30 30 :issues,
31 31 :issue_statuses,
32 32 :versions,
33 33 :trackers,
34 34 :projects_trackers,
35 35 :issue_categories,
36 36 :enabled_modules,
37 37 :enumerations,
38 38 :attachments,
39 39 :workflows,
40 40 :custom_fields,
41 41 :custom_values,
42 42 :custom_fields_projects,
43 43 :custom_fields_trackers,
44 44 :time_entries,
45 45 :journals,
46 46 :journal_details,
47 47 :queries
48 48
49 49 def setup
50 50 @controller = IssuesController.new
51 51 @request = ActionController::TestRequest.new
52 52 @response = ActionController::TestResponse.new
53 53 User.current = nil
54 54 end
55 55
56 56 def test_index
57 57 Setting.default_language = 'en'
58 58
59 59 get :index
60 60 assert_response :success
61 61 assert_template 'index.rhtml'
62 62 assert_not_nil assigns(:issues)
63 63 assert_nil assigns(:project)
64 64 assert_tag :tag => 'a', :content => /Can't print recipes/
65 65 assert_tag :tag => 'a', :content => /Subproject issue/
66 66 # private projects hidden
67 67 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
68 68 assert_no_tag :tag => 'a', :content => /Issue on project 2/
69 69 # project column
70 70 assert_tag :tag => 'th', :content => /Project/
71 71 end
72 72
73 73 def test_index_should_not_list_issues_when_module_disabled
74 74 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
75 75 get :index
76 76 assert_response :success
77 77 assert_template 'index.rhtml'
78 78 assert_not_nil assigns(:issues)
79 79 assert_nil assigns(:project)
80 80 assert_no_tag :tag => 'a', :content => /Can't print recipes/
81 81 assert_tag :tag => 'a', :content => /Subproject issue/
82 82 end
83 83
84 84 def test_index_should_not_list_issues_when_module_disabled
85 85 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
86 86 get :index
87 87 assert_response :success
88 88 assert_template 'index.rhtml'
89 89 assert_not_nil assigns(:issues)
90 90 assert_nil assigns(:project)
91 91 assert_no_tag :tag => 'a', :content => /Can't print recipes/
92 92 assert_tag :tag => 'a', :content => /Subproject issue/
93 93 end
94 94
95 95 def test_index_should_list_visible_issues_only
96 96 get :index, :per_page => 100
97 97 assert_response :success
98 98 assert_not_nil assigns(:issues)
99 99 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
100 100 end
101 101
102 102 def test_index_with_project
103 103 Setting.display_subprojects_issues = 0
104 104 get :index, :project_id => 1
105 105 assert_response :success
106 106 assert_template 'index.rhtml'
107 107 assert_not_nil assigns(:issues)
108 108 assert_tag :tag => 'a', :content => /Can't print recipes/
109 109 assert_no_tag :tag => 'a', :content => /Subproject issue/
110 110 end
111 111
112 112 def test_index_with_project_and_subprojects
113 113 Setting.display_subprojects_issues = 1
114 114 get :index, :project_id => 1
115 115 assert_response :success
116 116 assert_template 'index.rhtml'
117 117 assert_not_nil assigns(:issues)
118 118 assert_tag :tag => 'a', :content => /Can't print recipes/
119 119 assert_tag :tag => 'a', :content => /Subproject issue/
120 120 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
121 121 end
122 122
123 123 def test_index_with_project_and_subprojects_should_show_private_subprojects
124 124 @request.session[:user_id] = 2
125 125 Setting.display_subprojects_issues = 1
126 126 get :index, :project_id => 1
127 127 assert_response :success
128 128 assert_template 'index.rhtml'
129 129 assert_not_nil assigns(:issues)
130 130 assert_tag :tag => 'a', :content => /Can't print recipes/
131 131 assert_tag :tag => 'a', :content => /Subproject issue/
132 132 assert_tag :tag => 'a', :content => /Issue of a private subproject/
133 133 end
134 134
135 135 def test_index_with_project_and_default_filter
136 136 get :index, :project_id => 1, :set_filter => 1
137 137 assert_response :success
138 138 assert_template 'index.rhtml'
139 139 assert_not_nil assigns(:issues)
140 140
141 141 query = assigns(:query)
142 142 assert_not_nil query
143 143 # default filter
144 144 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
145 145 end
146 146
147 147 def test_index_with_project_and_filter
148 148 get :index, :project_id => 1, :set_filter => 1,
149 149 :f => ['tracker_id'],
150 150 :op => {'tracker_id' => '='},
151 151 :v => {'tracker_id' => ['1']}
152 152 assert_response :success
153 153 assert_template 'index.rhtml'
154 154 assert_not_nil assigns(:issues)
155 155
156 156 query = assigns(:query)
157 157 assert_not_nil query
158 158 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
159 159 end
160 160
161 161 def test_index_with_project_and_empty_filters
162 162 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
163 163 assert_response :success
164 164 assert_template 'index.rhtml'
165 165 assert_not_nil assigns(:issues)
166 166
167 167 query = assigns(:query)
168 168 assert_not_nil query
169 169 # no filter
170 170 assert_equal({}, query.filters)
171 171 end
172 172
173 173 def test_index_with_query
174 174 get :index, :project_id => 1, :query_id => 5
175 175 assert_response :success
176 176 assert_template 'index.rhtml'
177 177 assert_not_nil assigns(:issues)
178 178 assert_nil assigns(:issue_count_by_group)
179 179 end
180 180
181 181 def test_index_with_query_grouped_by_tracker
182 182 get :index, :project_id => 1, :query_id => 6
183 183 assert_response :success
184 184 assert_template 'index.rhtml'
185 185 assert_not_nil assigns(:issues)
186 186 assert_not_nil assigns(:issue_count_by_group)
187 187 end
188 188
189 189 def test_index_with_query_grouped_by_list_custom_field
190 190 get :index, :project_id => 1, :query_id => 9
191 191 assert_response :success
192 192 assert_template 'index.rhtml'
193 193 assert_not_nil assigns(:issues)
194 194 assert_not_nil assigns(:issue_count_by_group)
195 195 end
196 196
197 197 def test_index_sort_by_field_not_included_in_columns
198 198 Setting.issue_list_default_columns = %w(subject author)
199 199 get :index, :sort => 'tracker'
200 200 end
201 201
202 202 def test_index_csv_with_project
203 203 Setting.default_language = 'en'
204 204
205 205 get :index, :format => 'csv'
206 206 assert_response :success
207 207 assert_not_nil assigns(:issues)
208 208 assert_equal 'text/csv', @response.content_type
209 209 assert @response.body.starts_with?("#,")
210 210
211 211 get :index, :project_id => 1, :format => 'csv'
212 212 assert_response :success
213 213 assert_not_nil assigns(:issues)
214 214 assert_equal 'text/csv', @response.content_type
215 215 end
216 216
217 217 def test_index_pdf
218 218 get :index, :format => 'pdf'
219 219 assert_response :success
220 220 assert_not_nil assigns(:issues)
221 221 assert_equal 'application/pdf', @response.content_type
222 222
223 223 get :index, :project_id => 1, :format => 'pdf'
224 224 assert_response :success
225 225 assert_not_nil assigns(:issues)
226 226 assert_equal 'application/pdf', @response.content_type
227 227
228 228 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
229 229 assert_response :success
230 230 assert_not_nil assigns(:issues)
231 231 assert_equal 'application/pdf', @response.content_type
232 232 end
233 233
234 234 def test_index_pdf_with_query_grouped_by_list_custom_field
235 235 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
236 236 assert_response :success
237 237 assert_not_nil assigns(:issues)
238 238 assert_not_nil assigns(:issue_count_by_group)
239 239 assert_equal 'application/pdf', @response.content_type
240 240 end
241 241
242 242 def test_index_sort
243 243 get :index, :sort => 'tracker,id:desc'
244 244 assert_response :success
245 245
246 246 sort_params = @request.session['issues_index_sort']
247 247 assert sort_params.is_a?(String)
248 248 assert_equal 'tracker,id:desc', sort_params
249 249
250 250 issues = assigns(:issues)
251 251 assert_not_nil issues
252 252 assert !issues.empty?
253 253 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
254 254 end
255 255
256 256 def test_index_with_columns
257 257 columns = ['tracker', 'subject', 'assigned_to']
258 258 get :index, :set_filter => 1, :c => columns
259 259 assert_response :success
260 260
261 261 # query should use specified columns
262 262 query = assigns(:query)
263 263 assert_kind_of Query, query
264 264 assert_equal columns, query.column_names.map(&:to_s)
265 265
266 266 # columns should be stored in session
267 267 assert_kind_of Hash, session[:query]
268 268 assert_kind_of Array, session[:query][:column_names]
269 269 assert_equal columns, session[:query][:column_names].map(&:to_s)
270
271 # ensure only these columns are kept in the selected columns list
272 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
273 :children => { :count => 3 }
274 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
275 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
270 276 end
271 277
272 278 def test_index_with_custom_field_column
273 279 columns = %w(tracker subject cf_2)
274 280 get :index, :set_filter => 1, :c => columns
275 281 assert_response :success
276 282
277 283 # query should use specified columns
278 284 query = assigns(:query)
279 285 assert_kind_of Query, query
280 286 assert_equal columns, query.column_names.map(&:to_s)
281 287
282 288 assert_tag :td,
283 289 :attributes => {:class => 'cf_2 string'},
284 290 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
285 291 end
286 292
287 293 def test_show_by_anonymous
288 294 get :show, :id => 1
289 295 assert_response :success
290 296 assert_template 'show.rhtml'
291 297 assert_not_nil assigns(:issue)
292 298 assert_equal Issue.find(1), assigns(:issue)
293 299
294 300 # anonymous role is allowed to add a note
295 301 assert_tag :tag => 'form',
296 302 :descendant => { :tag => 'fieldset',
297 303 :child => { :tag => 'legend',
298 304 :content => /Notes/ } }
299 305 end
300 306
301 307 def test_show_by_manager
302 308 @request.session[:user_id] = 2
303 309 get :show, :id => 1
304 310 assert_response :success
305 311
306 312 assert_tag :tag => 'a',
307 313 :content => /Quote/
308 314
309 315 assert_tag :tag => 'form',
310 316 :descendant => { :tag => 'fieldset',
311 317 :child => { :tag => 'legend',
312 318 :content => /Change properties/ } },
313 319 :descendant => { :tag => 'fieldset',
314 320 :child => { :tag => 'legend',
315 321 :content => /Log time/ } },
316 322 :descendant => { :tag => 'fieldset',
317 323 :child => { :tag => 'legend',
318 324 :content => /Notes/ } }
319 325 end
320 326
321 327 def test_update_form_should_not_display_inactive_enumerations
322 328 @request.session[:user_id] = 2
323 329 get :show, :id => 1
324 330 assert_response :success
325 331
326 332 assert ! IssuePriority.find(15).active?
327 333 assert_no_tag :option, :attributes => {:value => '15'},
328 334 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
329 335 end
330 336
331 337 def test_show_should_deny_anonymous_access_without_permission
332 338 Role.anonymous.remove_permission!(:view_issues)
333 339 get :show, :id => 1
334 340 assert_response :redirect
335 341 end
336 342
337 343 def test_show_should_deny_anonymous_access_to_private_issue
338 344 Issue.update_all(["is_private = ?", true], "id = 1")
339 345 get :show, :id => 1
340 346 assert_response :redirect
341 347 end
342 348
343 349 def test_show_should_deny_non_member_access_without_permission
344 350 Role.non_member.remove_permission!(:view_issues)
345 351 @request.session[:user_id] = 9
346 352 get :show, :id => 1
347 353 assert_response 403
348 354 end
349 355
350 356 def test_show_should_deny_non_member_access_to_private_issue
351 357 Issue.update_all(["is_private = ?", true], "id = 1")
352 358 @request.session[:user_id] = 9
353 359 get :show, :id => 1
354 360 assert_response 403
355 361 end
356 362
357 363 def test_show_should_deny_member_access_without_permission
358 364 Role.find(1).remove_permission!(:view_issues)
359 365 @request.session[:user_id] = 2
360 366 get :show, :id => 1
361 367 assert_response 403
362 368 end
363 369
364 370 def test_show_should_deny_member_access_to_private_issue_without_permission
365 371 Issue.update_all(["is_private = ?", true], "id = 1")
366 372 @request.session[:user_id] = 3
367 373 get :show, :id => 1
368 374 assert_response 403
369 375 end
370 376
371 377 def test_show_should_allow_author_access_to_private_issue
372 378 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
373 379 @request.session[:user_id] = 3
374 380 get :show, :id => 1
375 381 assert_response :success
376 382 end
377 383
378 384 def test_show_should_allow_assignee_access_to_private_issue
379 385 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
380 386 @request.session[:user_id] = 3
381 387 get :show, :id => 1
382 388 assert_response :success
383 389 end
384 390
385 391 def test_show_should_allow_member_access_to_private_issue_with_permission
386 392 Issue.update_all(["is_private = ?", true], "id = 1")
387 393 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
388 394 @request.session[:user_id] = 3
389 395 get :show, :id => 1
390 396 assert_response :success
391 397 end
392 398
393 399 def test_show_should_not_disclose_relations_to_invisible_issues
394 400 Setting.cross_project_issue_relations = '1'
395 401 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
396 402 # Relation to a private project issue
397 403 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
398 404
399 405 get :show, :id => 1
400 406 assert_response :success
401 407
402 408 assert_tag :div, :attributes => { :id => 'relations' },
403 409 :descendant => { :tag => 'a', :content => /#2$/ }
404 410 assert_no_tag :div, :attributes => { :id => 'relations' },
405 411 :descendant => { :tag => 'a', :content => /#4$/ }
406 412 end
407 413
408 414 def test_show_atom
409 415 get :show, :id => 2, :format => 'atom'
410 416 assert_response :success
411 417 assert_template 'journals/index.rxml'
412 418 # Inline image
413 419 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
414 420 end
415 421
416 422 def test_show_export_to_pdf
417 423 get :show, :id => 3, :format => 'pdf'
418 424 assert_response :success
419 425 assert_equal 'application/pdf', @response.content_type
420 426 assert @response.body.starts_with?('%PDF')
421 427 assert_not_nil assigns(:issue)
422 428 end
423 429
424 430 def test_get_new
425 431 @request.session[:user_id] = 2
426 432 get :new, :project_id => 1, :tracker_id => 1
427 433 assert_response :success
428 434 assert_template 'new'
429 435
430 436 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
431 437 :value => 'Default string' }
432 438
433 439 # Be sure we don't display inactive IssuePriorities
434 440 assert ! IssuePriority.find(15).active?
435 441 assert_no_tag :option, :attributes => {:value => '15'},
436 442 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
437 443 end
438 444
439 445 def test_get_new_without_tracker_id
440 446 @request.session[:user_id] = 2
441 447 get :new, :project_id => 1
442 448 assert_response :success
443 449 assert_template 'new'
444 450
445 451 issue = assigns(:issue)
446 452 assert_not_nil issue
447 453 assert_equal Project.find(1).trackers.first, issue.tracker
448 454 end
449 455
450 456 def test_get_new_with_no_default_status_should_display_an_error
451 457 @request.session[:user_id] = 2
452 458 IssueStatus.delete_all
453 459
454 460 get :new, :project_id => 1
455 461 assert_response 500
456 462 assert_error_tag :content => /No default issue/
457 463 end
458 464
459 465 def test_get_new_with_no_tracker_should_display_an_error
460 466 @request.session[:user_id] = 2
461 467 Tracker.delete_all
462 468
463 469 get :new, :project_id => 1
464 470 assert_response 500
465 471 assert_error_tag :content => /No tracker/
466 472 end
467 473
468 474 def test_update_new_form
469 475 @request.session[:user_id] = 2
470 476 xhr :post, :new, :project_id => 1,
471 477 :issue => {:tracker_id => 2,
472 478 :subject => 'This is the test_new issue',
473 479 :description => 'This is the description',
474 480 :priority_id => 5}
475 481 assert_response :success
476 482 assert_template 'attributes'
477 483
478 484 issue = assigns(:issue)
479 485 assert_kind_of Issue, issue
480 486 assert_equal 1, issue.project_id
481 487 assert_equal 2, issue.tracker_id
482 488 assert_equal 'This is the test_new issue', issue.subject
483 489 end
484 490
485 491 def test_post_create
486 492 @request.session[:user_id] = 2
487 493 assert_difference 'Issue.count' do
488 494 post :create, :project_id => 1,
489 495 :issue => {:tracker_id => 3,
490 496 :status_id => 2,
491 497 :subject => 'This is the test_new issue',
492 498 :description => 'This is the description',
493 499 :priority_id => 5,
494 500 :start_date => '2010-11-07',
495 501 :estimated_hours => '',
496 502 :custom_field_values => {'2' => 'Value for field 2'}}
497 503 end
498 504 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
499 505
500 506 issue = Issue.find_by_subject('This is the test_new issue')
501 507 assert_not_nil issue
502 508 assert_equal 2, issue.author_id
503 509 assert_equal 3, issue.tracker_id
504 510 assert_equal 2, issue.status_id
505 511 assert_equal Date.parse('2010-11-07'), issue.start_date
506 512 assert_nil issue.estimated_hours
507 513 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
508 514 assert_not_nil v
509 515 assert_equal 'Value for field 2', v.value
510 516 end
511 517
512 518 def test_post_create_without_start_date
513 519 @request.session[:user_id] = 2
514 520 assert_difference 'Issue.count' do
515 521 post :create, :project_id => 1,
516 522 :issue => {:tracker_id => 3,
517 523 :status_id => 2,
518 524 :subject => 'This is the test_new issue',
519 525 :description => 'This is the description',
520 526 :priority_id => 5,
521 527 :start_date => '',
522 528 :estimated_hours => '',
523 529 :custom_field_values => {'2' => 'Value for field 2'}}
524 530 end
525 531 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
526 532
527 533 issue = Issue.find_by_subject('This is the test_new issue')
528 534 assert_not_nil issue
529 535 assert_nil issue.start_date
530 536 end
531 537
532 538 def test_post_create_and_continue
533 539 @request.session[:user_id] = 2
534 540 post :create, :project_id => 1,
535 541 :issue => {:tracker_id => 3,
536 542 :subject => 'This is first issue',
537 543 :priority_id => 5},
538 544 :continue => ''
539 545 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook',
540 546 :issue => {:tracker_id => 3}
541 547 end
542 548
543 549 def test_post_create_without_custom_fields_param
544 550 @request.session[:user_id] = 2
545 551 assert_difference 'Issue.count' do
546 552 post :create, :project_id => 1,
547 553 :issue => {:tracker_id => 1,
548 554 :subject => 'This is the test_new issue',
549 555 :description => 'This is the description',
550 556 :priority_id => 5}
551 557 end
552 558 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
553 559 end
554 560
555 561 def test_post_create_with_required_custom_field_and_without_custom_fields_param
556 562 field = IssueCustomField.find_by_name('Database')
557 563 field.update_attribute(:is_required, true)
558 564
559 565 @request.session[:user_id] = 2
560 566 post :create, :project_id => 1,
561 567 :issue => {:tracker_id => 1,
562 568 :subject => 'This is the test_new issue',
563 569 :description => 'This is the description',
564 570 :priority_id => 5}
565 571 assert_response :success
566 572 assert_template 'new'
567 573 issue = assigns(:issue)
568 574 assert_not_nil issue
569 575 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
570 576 end
571 577
572 578 def test_post_create_with_watchers
573 579 @request.session[:user_id] = 2
574 580 ActionMailer::Base.deliveries.clear
575 581
576 582 assert_difference 'Watcher.count', 2 do
577 583 post :create, :project_id => 1,
578 584 :issue => {:tracker_id => 1,
579 585 :subject => 'This is a new issue with watchers',
580 586 :description => 'This is the description',
581 587 :priority_id => 5,
582 588 :watcher_user_ids => ['2', '3']}
583 589 end
584 590 issue = Issue.find_by_subject('This is a new issue with watchers')
585 591 assert_not_nil issue
586 592 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
587 593
588 594 # Watchers added
589 595 assert_equal [2, 3], issue.watcher_user_ids.sort
590 596 assert issue.watched_by?(User.find(3))
591 597 # Watchers notified
592 598 mail = ActionMailer::Base.deliveries.last
593 599 assert_kind_of TMail::Mail, mail
594 600 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
595 601 end
596 602
597 603 def test_post_create_subissue
598 604 @request.session[:user_id] = 2
599 605
600 606 assert_difference 'Issue.count' do
601 607 post :create, :project_id => 1,
602 608 :issue => {:tracker_id => 1,
603 609 :subject => 'This is a child issue',
604 610 :parent_issue_id => 2}
605 611 end
606 612 issue = Issue.find_by_subject('This is a child issue')
607 613 assert_not_nil issue
608 614 assert_equal Issue.find(2), issue.parent
609 615 end
610 616
611 617 def test_post_create_subissue_with_non_numeric_parent_id
612 618 @request.session[:user_id] = 2
613 619
614 620 assert_difference 'Issue.count' do
615 621 post :create, :project_id => 1,
616 622 :issue => {:tracker_id => 1,
617 623 :subject => 'This is a child issue',
618 624 :parent_issue_id => 'ABC'}
619 625 end
620 626 issue = Issue.find_by_subject('This is a child issue')
621 627 assert_not_nil issue
622 628 assert_nil issue.parent
623 629 end
624 630
625 631 def test_post_create_private
626 632 @request.session[:user_id] = 2
627 633
628 634 assert_difference 'Issue.count' do
629 635 post :create, :project_id => 1,
630 636 :issue => {:tracker_id => 1,
631 637 :subject => 'This is a private issue',
632 638 :is_private => '1'}
633 639 end
634 640 issue = Issue.first(:order => 'id DESC')
635 641 assert issue.is_private?
636 642 end
637 643
638 644 def test_post_create_private_with_set_own_issues_private_permission
639 645 role = Role.find(1)
640 646 role.remove_permission! :set_issues_private
641 647 role.add_permission! :set_own_issues_private
642 648
643 649 @request.session[:user_id] = 2
644 650
645 651 assert_difference 'Issue.count' do
646 652 post :create, :project_id => 1,
647 653 :issue => {:tracker_id => 1,
648 654 :subject => 'This is a private issue',
649 655 :is_private => '1'}
650 656 end
651 657 issue = Issue.first(:order => 'id DESC')
652 658 assert issue.is_private?
653 659 end
654 660
655 661 def test_post_create_should_send_a_notification
656 662 ActionMailer::Base.deliveries.clear
657 663 @request.session[:user_id] = 2
658 664 assert_difference 'Issue.count' do
659 665 post :create, :project_id => 1,
660 666 :issue => {:tracker_id => 3,
661 667 :subject => 'This is the test_new issue',
662 668 :description => 'This is the description',
663 669 :priority_id => 5,
664 670 :estimated_hours => '',
665 671 :custom_field_values => {'2' => 'Value for field 2'}}
666 672 end
667 673 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
668 674
669 675 assert_equal 1, ActionMailer::Base.deliveries.size
670 676 end
671 677
672 678 def test_post_create_should_preserve_fields_values_on_validation_failure
673 679 @request.session[:user_id] = 2
674 680 post :create, :project_id => 1,
675 681 :issue => {:tracker_id => 1,
676 682 # empty subject
677 683 :subject => '',
678 684 :description => 'This is a description',
679 685 :priority_id => 6,
680 686 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
681 687 assert_response :success
682 688 assert_template 'new'
683 689
684 690 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
685 691 :content => 'This is a description'
686 692 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
687 693 :child => { :tag => 'option', :attributes => { :selected => 'selected',
688 694 :value => '6' },
689 695 :content => 'High' }
690 696 # Custom fields
691 697 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
692 698 :child => { :tag => 'option', :attributes => { :selected => 'selected',
693 699 :value => 'Oracle' },
694 700 :content => 'Oracle' }
695 701 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
696 702 :value => 'Value for field 2'}
697 703 end
698 704
699 705 def test_post_create_should_ignore_non_safe_attributes
700 706 @request.session[:user_id] = 2
701 707 assert_nothing_raised do
702 708 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
703 709 end
704 710 end
705 711
706 712 context "without workflow privilege" do
707 713 setup do
708 714 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
709 715 Role.anonymous.add_permission! :add_issues, :add_issue_notes
710 716 end
711 717
712 718 context "#new" do
713 719 should "propose default status only" do
714 720 get :new, :project_id => 1
715 721 assert_response :success
716 722 assert_template 'new'
717 723 assert_tag :tag => 'select',
718 724 :attributes => {:name => 'issue[status_id]'},
719 725 :children => {:count => 1},
720 726 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
721 727 end
722 728
723 729 should "accept default status" do
724 730 assert_difference 'Issue.count' do
725 731 post :create, :project_id => 1,
726 732 :issue => {:tracker_id => 1,
727 733 :subject => 'This is an issue',
728 734 :status_id => 1}
729 735 end
730 736 issue = Issue.last(:order => 'id')
731 737 assert_equal IssueStatus.default, issue.status
732 738 end
733 739
734 740 should "ignore unauthorized status" do
735 741 assert_difference 'Issue.count' do
736 742 post :create, :project_id => 1,
737 743 :issue => {:tracker_id => 1,
738 744 :subject => 'This is an issue',
739 745 :status_id => 3}
740 746 end
741 747 issue = Issue.last(:order => 'id')
742 748 assert_equal IssueStatus.default, issue.status
743 749 end
744 750 end
745 751
746 752 context "#update" do
747 753 should "ignore status change" do
748 754 assert_difference 'Journal.count' do
749 755 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
750 756 end
751 757 assert_equal 1, Issue.find(1).status_id
752 758 end
753 759
754 760 should "ignore attributes changes" do
755 761 assert_difference 'Journal.count' do
756 762 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
757 763 end
758 764 issue = Issue.find(1)
759 765 assert_equal "Can't print recipes", issue.subject
760 766 assert_nil issue.assigned_to
761 767 end
762 768 end
763 769 end
764 770
765 771 context "with workflow privilege" do
766 772 setup do
767 773 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
768 774 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
769 775 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
770 776 Role.anonymous.add_permission! :add_issues, :add_issue_notes
771 777 end
772 778
773 779 context "#update" do
774 780 should "accept authorized status" do
775 781 assert_difference 'Journal.count' do
776 782 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
777 783 end
778 784 assert_equal 3, Issue.find(1).status_id
779 785 end
780 786
781 787 should "ignore unauthorized status" do
782 788 assert_difference 'Journal.count' do
783 789 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
784 790 end
785 791 assert_equal 1, Issue.find(1).status_id
786 792 end
787 793
788 794 should "accept authorized attributes changes" do
789 795 assert_difference 'Journal.count' do
790 796 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
791 797 end
792 798 issue = Issue.find(1)
793 799 assert_equal 2, issue.assigned_to_id
794 800 end
795 801
796 802 should "ignore unauthorized attributes changes" do
797 803 assert_difference 'Journal.count' do
798 804 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
799 805 end
800 806 issue = Issue.find(1)
801 807 assert_equal "Can't print recipes", issue.subject
802 808 end
803 809 end
804 810
805 811 context "and :edit_issues permission" do
806 812 setup do
807 813 Role.anonymous.add_permission! :add_issues, :edit_issues
808 814 end
809 815
810 816 should "accept authorized status" do
811 817 assert_difference 'Journal.count' do
812 818 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
813 819 end
814 820 assert_equal 3, Issue.find(1).status_id
815 821 end
816 822
817 823 should "ignore unauthorized status" do
818 824 assert_difference 'Journal.count' do
819 825 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
820 826 end
821 827 assert_equal 1, Issue.find(1).status_id
822 828 end
823 829
824 830 should "accept authorized attributes changes" do
825 831 assert_difference 'Journal.count' do
826 832 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
827 833 end
828 834 issue = Issue.find(1)
829 835 assert_equal "changed", issue.subject
830 836 assert_equal 2, issue.assigned_to_id
831 837 end
832 838 end
833 839 end
834 840
835 841 def test_copy_issue
836 842 @request.session[:user_id] = 2
837 843 get :new, :project_id => 1, :copy_from => 1
838 844 assert_template 'new'
839 845 assert_not_nil assigns(:issue)
840 846 orig = Issue.find(1)
841 847 assert_equal orig.subject, assigns(:issue).subject
842 848 end
843 849
844 850 def test_get_edit
845 851 @request.session[:user_id] = 2
846 852 get :edit, :id => 1
847 853 assert_response :success
848 854 assert_template 'edit'
849 855 assert_not_nil assigns(:issue)
850 856 assert_equal Issue.find(1), assigns(:issue)
851 857
852 858 # Be sure we don't display inactive IssuePriorities
853 859 assert ! IssuePriority.find(15).active?
854 860 assert_no_tag :option, :attributes => {:value => '15'},
855 861 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
856 862 end
857 863
858 864 def test_get_edit_with_params
859 865 @request.session[:user_id] = 2
860 866 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
861 867 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
862 868 assert_response :success
863 869 assert_template 'edit'
864 870
865 871 issue = assigns(:issue)
866 872 assert_not_nil issue
867 873
868 874 assert_equal 5, issue.status_id
869 875 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
870 876 :child => { :tag => 'option',
871 877 :content => 'Closed',
872 878 :attributes => { :selected => 'selected' } }
873 879
874 880 assert_equal 7, issue.priority_id
875 881 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
876 882 :child => { :tag => 'option',
877 883 :content => 'Urgent',
878 884 :attributes => { :selected => 'selected' } }
879 885
880 886 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
881 887 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
882 888 :child => { :tag => 'option',
883 889 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
884 890 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
885 891 end
886 892
887 893 def test_update_edit_form
888 894 @request.session[:user_id] = 2
889 895 xhr :post, :new, :project_id => 1,
890 896 :id => 1,
891 897 :issue => {:tracker_id => 2,
892 898 :subject => 'This is the test_new issue',
893 899 :description => 'This is the description',
894 900 :priority_id => 5}
895 901 assert_response :success
896 902 assert_template 'attributes'
897 903
898 904 issue = assigns(:issue)
899 905 assert_kind_of Issue, issue
900 906 assert_equal 1, issue.id
901 907 assert_equal 1, issue.project_id
902 908 assert_equal 2, issue.tracker_id
903 909 assert_equal 'This is the test_new issue', issue.subject
904 910 end
905 911
906 912 def test_update_using_invalid_http_verbs
907 913 @request.session[:user_id] = 2
908 914 subject = 'Updated by an invalid http verb'
909 915
910 916 get :update, :id => 1, :issue => {:subject => subject}
911 917 assert_not_equal subject, Issue.find(1).subject
912 918
913 919 post :update, :id => 1, :issue => {:subject => subject}
914 920 assert_not_equal subject, Issue.find(1).subject
915 921
916 922 delete :update, :id => 1, :issue => {:subject => subject}
917 923 assert_not_equal subject, Issue.find(1).subject
918 924 end
919 925
920 926 def test_put_update_without_custom_fields_param
921 927 @request.session[:user_id] = 2
922 928 ActionMailer::Base.deliveries.clear
923 929
924 930 issue = Issue.find(1)
925 931 assert_equal '125', issue.custom_value_for(2).value
926 932 old_subject = issue.subject
927 933 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
928 934
929 935 assert_difference('Journal.count') do
930 936 assert_difference('JournalDetail.count', 2) do
931 937 put :update, :id => 1, :issue => {:subject => new_subject,
932 938 :priority_id => '6',
933 939 :category_id => '1' # no change
934 940 }
935 941 end
936 942 end
937 943 assert_redirected_to :action => 'show', :id => '1'
938 944 issue.reload
939 945 assert_equal new_subject, issue.subject
940 946 # Make sure custom fields were not cleared
941 947 assert_equal '125', issue.custom_value_for(2).value
942 948
943 949 mail = ActionMailer::Base.deliveries.last
944 950 assert_kind_of TMail::Mail, mail
945 951 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
946 952 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
947 953 end
948 954
949 955 def test_put_update_with_custom_field_change
950 956 @request.session[:user_id] = 2
951 957 issue = Issue.find(1)
952 958 assert_equal '125', issue.custom_value_for(2).value
953 959
954 960 assert_difference('Journal.count') do
955 961 assert_difference('JournalDetail.count', 3) do
956 962 put :update, :id => 1, :issue => {:subject => 'Custom field change',
957 963 :priority_id => '6',
958 964 :category_id => '1', # no change
959 965 :custom_field_values => { '2' => 'New custom value' }
960 966 }
961 967 end
962 968 end
963 969 assert_redirected_to :action => 'show', :id => '1'
964 970 issue.reload
965 971 assert_equal 'New custom value', issue.custom_value_for(2).value
966 972
967 973 mail = ActionMailer::Base.deliveries.last
968 974 assert_kind_of TMail::Mail, mail
969 975 assert mail.body.include?("Searchable field changed from 125 to New custom value")
970 976 end
971 977
972 978 def test_put_update_with_status_and_assignee_change
973 979 issue = Issue.find(1)
974 980 assert_equal 1, issue.status_id
975 981 @request.session[:user_id] = 2
976 982 assert_difference('TimeEntry.count', 0) do
977 983 put :update,
978 984 :id => 1,
979 985 :issue => { :status_id => 2, :assigned_to_id => 3 },
980 986 :notes => 'Assigned to dlopper',
981 987 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
982 988 end
983 989 assert_redirected_to :action => 'show', :id => '1'
984 990 issue.reload
985 991 assert_equal 2, issue.status_id
986 992 j = Journal.find(:first, :order => 'id DESC')
987 993 assert_equal 'Assigned to dlopper', j.notes
988 994 assert_equal 2, j.details.size
989 995
990 996 mail = ActionMailer::Base.deliveries.last
991 997 assert mail.body.include?("Status changed from New to Assigned")
992 998 # subject should contain the new status
993 999 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
994 1000 end
995 1001
996 1002 def test_put_update_with_note_only
997 1003 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
998 1004 # anonymous user
999 1005 put :update,
1000 1006 :id => 1,
1001 1007 :notes => notes
1002 1008 assert_redirected_to :action => 'show', :id => '1'
1003 1009 j = Journal.find(:first, :order => 'id DESC')
1004 1010 assert_equal notes, j.notes
1005 1011 assert_equal 0, j.details.size
1006 1012 assert_equal User.anonymous, j.user
1007 1013
1008 1014 mail = ActionMailer::Base.deliveries.last
1009 1015 assert mail.body.include?(notes)
1010 1016 end
1011 1017
1012 1018 def test_put_update_with_note_and_spent_time
1013 1019 @request.session[:user_id] = 2
1014 1020 spent_hours_before = Issue.find(1).spent_hours
1015 1021 assert_difference('TimeEntry.count') do
1016 1022 put :update,
1017 1023 :id => 1,
1018 1024 :notes => '2.5 hours added',
1019 1025 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
1020 1026 end
1021 1027 assert_redirected_to :action => 'show', :id => '1'
1022 1028
1023 1029 issue = Issue.find(1)
1024 1030
1025 1031 j = Journal.find(:first, :order => 'id DESC')
1026 1032 assert_equal '2.5 hours added', j.notes
1027 1033 assert_equal 0, j.details.size
1028 1034
1029 1035 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
1030 1036 assert_not_nil t
1031 1037 assert_equal 2.5, t.hours
1032 1038 assert_equal spent_hours_before + 2.5, issue.spent_hours
1033 1039 end
1034 1040
1035 1041 def test_put_update_with_attachment_only
1036 1042 set_tmp_attachments_directory
1037 1043
1038 1044 # Delete all fixtured journals, a race condition can occur causing the wrong
1039 1045 # journal to get fetched in the next find.
1040 1046 Journal.delete_all
1041 1047
1042 1048 # anonymous user
1043 1049 put :update,
1044 1050 :id => 1,
1045 1051 :notes => '',
1046 1052 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
1047 1053 assert_redirected_to :action => 'show', :id => '1'
1048 1054 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
1049 1055 assert j.notes.blank?
1050 1056 assert_equal 1, j.details.size
1051 1057 assert_equal 'testfile.txt', j.details.first.value
1052 1058 assert_equal User.anonymous, j.user
1053 1059
1054 1060 mail = ActionMailer::Base.deliveries.last
1055 1061 assert mail.body.include?('testfile.txt')
1056 1062 end
1057 1063
1058 1064 def test_put_update_with_attachment_that_fails_to_save
1059 1065 set_tmp_attachments_directory
1060 1066
1061 1067 # Delete all fixtured journals, a race condition can occur causing the wrong
1062 1068 # journal to get fetched in the next find.
1063 1069 Journal.delete_all
1064 1070
1065 1071 # Mock out the unsaved attachment
1066 1072 Attachment.any_instance.stubs(:create).returns(Attachment.new)
1067 1073
1068 1074 # anonymous user
1069 1075 put :update,
1070 1076 :id => 1,
1071 1077 :notes => '',
1072 1078 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
1073 1079 assert_redirected_to :action => 'show', :id => '1'
1074 1080 assert_equal '1 file(s) could not be saved.', flash[:warning]
1075 1081
1076 1082 end if Object.const_defined?(:Mocha)
1077 1083
1078 1084 def test_put_update_with_no_change
1079 1085 issue = Issue.find(1)
1080 1086 issue.journals.clear
1081 1087 ActionMailer::Base.deliveries.clear
1082 1088
1083 1089 put :update,
1084 1090 :id => 1,
1085 1091 :notes => ''
1086 1092 assert_redirected_to :action => 'show', :id => '1'
1087 1093
1088 1094 issue.reload
1089 1095 assert issue.journals.empty?
1090 1096 # No email should be sent
1091 1097 assert ActionMailer::Base.deliveries.empty?
1092 1098 end
1093 1099
1094 1100 def test_put_update_should_send_a_notification
1095 1101 @request.session[:user_id] = 2
1096 1102 ActionMailer::Base.deliveries.clear
1097 1103 issue = Issue.find(1)
1098 1104 old_subject = issue.subject
1099 1105 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1100 1106
1101 1107 put :update, :id => 1, :issue => {:subject => new_subject,
1102 1108 :priority_id => '6',
1103 1109 :category_id => '1' # no change
1104 1110 }
1105 1111 assert_equal 1, ActionMailer::Base.deliveries.size
1106 1112 end
1107 1113
1108 1114 def test_put_update_with_invalid_spent_time_hours_only
1109 1115 @request.session[:user_id] = 2
1110 1116 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1111 1117
1112 1118 assert_no_difference('Journal.count') do
1113 1119 put :update,
1114 1120 :id => 1,
1115 1121 :notes => notes,
1116 1122 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
1117 1123 end
1118 1124 assert_response :success
1119 1125 assert_template 'edit'
1120 1126
1121 1127 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1122 1128 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1123 1129 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
1124 1130 end
1125 1131
1126 1132 def test_put_update_with_invalid_spent_time_comments_only
1127 1133 @request.session[:user_id] = 2
1128 1134 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1129 1135
1130 1136 assert_no_difference('Journal.count') do
1131 1137 put :update,
1132 1138 :id => 1,
1133 1139 :notes => notes,
1134 1140 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
1135 1141 end
1136 1142 assert_response :success
1137 1143 assert_template 'edit'
1138 1144
1139 1145 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1140 1146 assert_error_tag :descendant => {:content => /Hours can't be blank/}
1141 1147 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1142 1148 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
1143 1149 end
1144 1150
1145 1151 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
1146 1152 issue = Issue.find(2)
1147 1153 @request.session[:user_id] = 2
1148 1154
1149 1155 put :update,
1150 1156 :id => issue.id,
1151 1157 :issue => {
1152 1158 :fixed_version_id => 4
1153 1159 }
1154 1160
1155 1161 assert_response :redirect
1156 1162 issue.reload
1157 1163 assert_equal 4, issue.fixed_version_id
1158 1164 assert_not_equal issue.project_id, issue.fixed_version.project_id
1159 1165 end
1160 1166
1161 1167 def test_put_update_should_redirect_back_using_the_back_url_parameter
1162 1168 issue = Issue.find(2)
1163 1169 @request.session[:user_id] = 2
1164 1170
1165 1171 put :update,
1166 1172 :id => issue.id,
1167 1173 :issue => {
1168 1174 :fixed_version_id => 4
1169 1175 },
1170 1176 :back_url => '/issues'
1171 1177
1172 1178 assert_response :redirect
1173 1179 assert_redirected_to '/issues'
1174 1180 end
1175 1181
1176 1182 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1177 1183 issue = Issue.find(2)
1178 1184 @request.session[:user_id] = 2
1179 1185
1180 1186 put :update,
1181 1187 :id => issue.id,
1182 1188 :issue => {
1183 1189 :fixed_version_id => 4
1184 1190 },
1185 1191 :back_url => 'http://google.com'
1186 1192
1187 1193 assert_response :redirect
1188 1194 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
1189 1195 end
1190 1196
1191 1197 def test_get_bulk_edit
1192 1198 @request.session[:user_id] = 2
1193 1199 get :bulk_edit, :ids => [1, 2]
1194 1200 assert_response :success
1195 1201 assert_template 'bulk_edit'
1196 1202
1197 1203 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1198 1204
1199 1205 # Project specific custom field, date type
1200 1206 field = CustomField.find(9)
1201 1207 assert !field.is_for_all?
1202 1208 assert_equal 'date', field.field_format
1203 1209 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1204 1210
1205 1211 # System wide custom field
1206 1212 assert CustomField.find(1).is_for_all?
1207 1213 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
1208 1214
1209 1215 # Be sure we don't display inactive IssuePriorities
1210 1216 assert ! IssuePriority.find(15).active?
1211 1217 assert_no_tag :option, :attributes => {:value => '15'},
1212 1218 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1213 1219 end
1214 1220
1215 1221 def test_get_bulk_edit_on_different_projects
1216 1222 @request.session[:user_id] = 2
1217 1223 get :bulk_edit, :ids => [1, 2, 6]
1218 1224 assert_response :success
1219 1225 assert_template 'bulk_edit'
1220 1226
1221 1227 # Can not set issues from different projects as children of an issue
1222 1228 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1223 1229
1224 1230 # Project specific custom field, date type
1225 1231 field = CustomField.find(9)
1226 1232 assert !field.is_for_all?
1227 1233 assert !field.project_ids.include?(Issue.find(6).project_id)
1228 1234 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1229 1235 end
1230 1236
1231 1237 def test_get_bulk_edit_with_user_custom_field
1232 1238 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
1233 1239
1234 1240 @request.session[:user_id] = 2
1235 1241 get :bulk_edit, :ids => [1, 2]
1236 1242 assert_response :success
1237 1243 assert_template 'bulk_edit'
1238 1244
1239 1245 assert_tag :select,
1240 1246 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1241 1247 :children => {
1242 1248 :only => {:tag => 'option'},
1243 1249 :count => Project.find(1).users.count + 1
1244 1250 }
1245 1251 end
1246 1252
1247 1253 def test_get_bulk_edit_with_version_custom_field
1248 1254 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
1249 1255
1250 1256 @request.session[:user_id] = 2
1251 1257 get :bulk_edit, :ids => [1, 2]
1252 1258 assert_response :success
1253 1259 assert_template 'bulk_edit'
1254 1260
1255 1261 assert_tag :select,
1256 1262 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1257 1263 :children => {
1258 1264 :only => {:tag => 'option'},
1259 1265 :count => Project.find(1).versions.count + 1
1260 1266 }
1261 1267 end
1262 1268
1263 1269 def test_bulk_update
1264 1270 @request.session[:user_id] = 2
1265 1271 # update issues priority
1266 1272 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1267 1273 :issue => {:priority_id => 7,
1268 1274 :assigned_to_id => '',
1269 1275 :custom_field_values => {'2' => ''}}
1270 1276
1271 1277 assert_response 302
1272 1278 # check that the issues were updated
1273 1279 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
1274 1280
1275 1281 issue = Issue.find(1)
1276 1282 journal = issue.journals.find(:first, :order => 'created_on DESC')
1277 1283 assert_equal '125', issue.custom_value_for(2).value
1278 1284 assert_equal 'Bulk editing', journal.notes
1279 1285 assert_equal 1, journal.details.size
1280 1286 end
1281 1287
1282 1288 def test_bulk_update_on_different_projects
1283 1289 @request.session[:user_id] = 2
1284 1290 # update issues priority
1285 1291 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
1286 1292 :issue => {:priority_id => 7,
1287 1293 :assigned_to_id => '',
1288 1294 :custom_field_values => {'2' => ''}}
1289 1295
1290 1296 assert_response 302
1291 1297 # check that the issues were updated
1292 1298 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
1293 1299
1294 1300 issue = Issue.find(1)
1295 1301 journal = issue.journals.find(:first, :order => 'created_on DESC')
1296 1302 assert_equal '125', issue.custom_value_for(2).value
1297 1303 assert_equal 'Bulk editing', journal.notes
1298 1304 assert_equal 1, journal.details.size
1299 1305 end
1300 1306
1301 1307 def test_bulk_update_on_different_projects_without_rights
1302 1308 @request.session[:user_id] = 3
1303 1309 user = User.find(3)
1304 1310 action = { :controller => "issues", :action => "bulk_update" }
1305 1311 assert user.allowed_to?(action, Issue.find(1).project)
1306 1312 assert ! user.allowed_to?(action, Issue.find(6).project)
1307 1313 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
1308 1314 :issue => {:priority_id => 7,
1309 1315 :assigned_to_id => '',
1310 1316 :custom_field_values => {'2' => ''}}
1311 1317 assert_response 403
1312 1318 assert_not_equal "Bulk should fail", Journal.last.notes
1313 1319 end
1314 1320
1315 1321 def test_bullk_update_should_send_a_notification
1316 1322 @request.session[:user_id] = 2
1317 1323 ActionMailer::Base.deliveries.clear
1318 1324 post(:bulk_update,
1319 1325 {
1320 1326 :ids => [1, 2],
1321 1327 :notes => 'Bulk editing',
1322 1328 :issue => {
1323 1329 :priority_id => 7,
1324 1330 :assigned_to_id => '',
1325 1331 :custom_field_values => {'2' => ''}
1326 1332 }
1327 1333 })
1328 1334
1329 1335 assert_response 302
1330 1336 assert_equal 2, ActionMailer::Base.deliveries.size
1331 1337 end
1332 1338
1333 1339 def test_bulk_update_status
1334 1340 @request.session[:user_id] = 2
1335 1341 # update issues priority
1336 1342 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
1337 1343 :issue => {:priority_id => '',
1338 1344 :assigned_to_id => '',
1339 1345 :status_id => '5'}
1340 1346
1341 1347 assert_response 302
1342 1348 issue = Issue.find(1)
1343 1349 assert issue.closed?
1344 1350 end
1345 1351
1346 1352 def test_bulk_update_parent_id
1347 1353 @request.session[:user_id] = 2
1348 1354 post :bulk_update, :ids => [1, 3],
1349 1355 :notes => 'Bulk editing parent',
1350 1356 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
1351 1357
1352 1358 assert_response 302
1353 1359 parent = Issue.find(2)
1354 1360 assert_equal parent.id, Issue.find(1).parent_id
1355 1361 assert_equal parent.id, Issue.find(3).parent_id
1356 1362 assert_equal [1, 3], parent.children.collect(&:id).sort
1357 1363 end
1358 1364
1359 1365 def test_bulk_update_custom_field
1360 1366 @request.session[:user_id] = 2
1361 1367 # update issues priority
1362 1368 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
1363 1369 :issue => {:priority_id => '',
1364 1370 :assigned_to_id => '',
1365 1371 :custom_field_values => {'2' => '777'}}
1366 1372
1367 1373 assert_response 302
1368 1374
1369 1375 issue = Issue.find(1)
1370 1376 journal = issue.journals.find(:first, :order => 'created_on DESC')
1371 1377 assert_equal '777', issue.custom_value_for(2).value
1372 1378 assert_equal 1, journal.details.size
1373 1379 assert_equal '125', journal.details.first.old_value
1374 1380 assert_equal '777', journal.details.first.value
1375 1381 end
1376 1382
1377 1383 def test_bulk_update_unassign
1378 1384 assert_not_nil Issue.find(2).assigned_to
1379 1385 @request.session[:user_id] = 2
1380 1386 # unassign issues
1381 1387 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
1382 1388 assert_response 302
1383 1389 # check that the issues were updated
1384 1390 assert_nil Issue.find(2).assigned_to
1385 1391 end
1386 1392
1387 1393 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
1388 1394 @request.session[:user_id] = 2
1389 1395
1390 1396 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
1391 1397
1392 1398 assert_response :redirect
1393 1399 issues = Issue.find([1,2])
1394 1400 issues.each do |issue|
1395 1401 assert_equal 4, issue.fixed_version_id
1396 1402 assert_not_equal issue.project_id, issue.fixed_version.project_id
1397 1403 end
1398 1404 end
1399 1405
1400 1406 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
1401 1407 @request.session[:user_id] = 2
1402 1408 post :bulk_update, :ids => [1,2], :back_url => '/issues'
1403 1409
1404 1410 assert_response :redirect
1405 1411 assert_redirected_to '/issues'
1406 1412 end
1407 1413
1408 1414 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1409 1415 @request.session[:user_id] = 2
1410 1416 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
1411 1417
1412 1418 assert_response :redirect
1413 1419 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
1414 1420 end
1415 1421
1416 1422 def test_destroy_issue_with_no_time_entries
1417 1423 assert_nil TimeEntry.find_by_issue_id(2)
1418 1424 @request.session[:user_id] = 2
1419 1425 post :destroy, :id => 2
1420 1426 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1421 1427 assert_nil Issue.find_by_id(2)
1422 1428 end
1423 1429
1424 1430 def test_destroy_issues_with_time_entries
1425 1431 @request.session[:user_id] = 2
1426 1432 post :destroy, :ids => [1, 3]
1427 1433 assert_response :success
1428 1434 assert_template 'destroy'
1429 1435 assert_not_nil assigns(:hours)
1430 1436 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1431 1437 end
1432 1438
1433 1439 def test_destroy_issues_and_destroy_time_entries
1434 1440 @request.session[:user_id] = 2
1435 1441 post :destroy, :ids => [1, 3], :todo => 'destroy'
1436 1442 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1437 1443 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1438 1444 assert_nil TimeEntry.find_by_id([1, 2])
1439 1445 end
1440 1446
1441 1447 def test_destroy_issues_and_assign_time_entries_to_project
1442 1448 @request.session[:user_id] = 2
1443 1449 post :destroy, :ids => [1, 3], :todo => 'nullify'
1444 1450 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1445 1451 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1446 1452 assert_nil TimeEntry.find(1).issue_id
1447 1453 assert_nil TimeEntry.find(2).issue_id
1448 1454 end
1449 1455
1450 1456 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1451 1457 @request.session[:user_id] = 2
1452 1458 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1453 1459 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1454 1460 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1455 1461 assert_equal 2, TimeEntry.find(1).issue_id
1456 1462 assert_equal 2, TimeEntry.find(2).issue_id
1457 1463 end
1458 1464
1459 1465 def test_destroy_issues_from_different_projects
1460 1466 @request.session[:user_id] = 2
1461 1467 post :destroy, :ids => [1, 2, 6], :todo => 'destroy'
1462 1468 assert_redirected_to :controller => 'issues', :action => 'index'
1463 1469 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
1464 1470 end
1465 1471
1466 1472 def test_destroy_parent_and_child_issues
1467 1473 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
1468 1474 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
1469 1475 assert child.is_descendant_of?(parent.reload)
1470 1476
1471 1477 @request.session[:user_id] = 2
1472 1478 assert_difference 'Issue.count', -2 do
1473 1479 post :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
1474 1480 end
1475 1481 assert_response 302
1476 1482 end
1477 1483
1478 1484 def test_default_search_scope
1479 1485 get :index
1480 1486 assert_tag :div, :attributes => {:id => 'quick-search'},
1481 1487 :child => {:tag => 'form',
1482 1488 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
1483 1489 end
1484 1490 end
General Comments 0
You need to be logged in to leave comments. Login now