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