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