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