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