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