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