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