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