##// END OF EJS Templates
Adds a test for #9076....
Jean-Philippe Lang -
r9054:934dd07fa738
parent child
Show More
@@ -1,3110 +1,3129
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 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 :repositories,
46 46 :changesets
47 47
48 48 include Redmine::I18n
49 49
50 50 def setup
51 51 @controller = IssuesController.new
52 52 @request = ActionController::TestRequest.new
53 53 @response = ActionController::TestResponse.new
54 54 User.current = nil
55 55 end
56 56
57 57 def test_index
58 58 with_settings :default_language => "en" do
59 59 get :index
60 60 assert_response :success
61 61 assert_template 'index'
62 62 assert_not_nil assigns(:issues)
63 63 assert_nil assigns(:project)
64 64 assert_tag :tag => 'a', :content => /Can't print recipes/
65 65 assert_tag :tag => 'a', :content => /Subproject issue/
66 66 # private projects hidden
67 67 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
68 68 assert_no_tag :tag => 'a', :content => /Issue on project 2/
69 69 # project column
70 70 assert_tag :tag => 'th', :content => /Project/
71 71 end
72 72 end
73 73
74 74 def test_index_should_not_list_issues_when_module_disabled
75 75 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
76 76 get :index
77 77 assert_response :success
78 78 assert_template 'index'
79 79 assert_not_nil assigns(:issues)
80 80 assert_nil assigns(:project)
81 81 assert_no_tag :tag => 'a', :content => /Can't print recipes/
82 82 assert_tag :tag => 'a', :content => /Subproject issue/
83 83 end
84 84
85 85 def test_index_should_list_visible_issues_only
86 86 get :index, :per_page => 100
87 87 assert_response :success
88 88 assert_not_nil assigns(:issues)
89 89 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
90 90 end
91 91
92 92 def test_index_with_project
93 93 Setting.display_subprojects_issues = 0
94 94 get :index, :project_id => 1
95 95 assert_response :success
96 96 assert_template 'index'
97 97 assert_not_nil assigns(:issues)
98 98 assert_tag :tag => 'a', :content => /Can't print recipes/
99 99 assert_no_tag :tag => 'a', :content => /Subproject issue/
100 100 end
101 101
102 102 def test_index_with_project_and_subprojects
103 103 Setting.display_subprojects_issues = 1
104 104 get :index, :project_id => 1
105 105 assert_response :success
106 106 assert_template 'index'
107 107 assert_not_nil assigns(:issues)
108 108 assert_tag :tag => 'a', :content => /Can't print recipes/
109 109 assert_tag :tag => 'a', :content => /Subproject issue/
110 110 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
111 111 end
112 112
113 113 def test_index_with_project_and_subprojects_should_show_private_subprojects
114 114 @request.session[:user_id] = 2
115 115 Setting.display_subprojects_issues = 1
116 116 get :index, :project_id => 1
117 117 assert_response :success
118 118 assert_template 'index'
119 119 assert_not_nil assigns(:issues)
120 120 assert_tag :tag => 'a', :content => /Can't print recipes/
121 121 assert_tag :tag => 'a', :content => /Subproject issue/
122 122 assert_tag :tag => 'a', :content => /Issue of a private subproject/
123 123 end
124 124
125 125 def test_index_with_project_and_default_filter
126 126 get :index, :project_id => 1, :set_filter => 1
127 127 assert_response :success
128 128 assert_template 'index'
129 129 assert_not_nil assigns(:issues)
130 130
131 131 query = assigns(:query)
132 132 assert_not_nil query
133 133 # default filter
134 134 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
135 135 end
136 136
137 137 def test_index_with_project_and_filter
138 138 get :index, :project_id => 1, :set_filter => 1,
139 139 :f => ['tracker_id'],
140 140 :op => {'tracker_id' => '='},
141 141 :v => {'tracker_id' => ['1']}
142 142 assert_response :success
143 143 assert_template 'index'
144 144 assert_not_nil assigns(:issues)
145 145
146 146 query = assigns(:query)
147 147 assert_not_nil query
148 148 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
149 149 end
150 150
151 151 def test_index_with_short_filters
152 152 to_test = {
153 153 'status_id' => {
154 154 'o' => { :op => 'o', :values => [''] },
155 155 'c' => { :op => 'c', :values => [''] },
156 156 '7' => { :op => '=', :values => ['7'] },
157 157 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
158 158 '=7' => { :op => '=', :values => ['7'] },
159 159 '!3' => { :op => '!', :values => ['3'] },
160 160 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
161 161 'subject' => {
162 162 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
163 163 'o' => { :op => '=', :values => ['o'] },
164 164 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
165 165 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
166 166 'tracker_id' => {
167 167 '3' => { :op => '=', :values => ['3'] },
168 168 '=3' => { :op => '=', :values => ['3'] }},
169 169 'start_date' => {
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-12' => { :op => '<=', :values => ['2011-10-12'] },
174 174 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
175 175 '<t+2' => { :op => '<t+', :values => ['2'] },
176 176 '>t+2' => { :op => '>t+', :values => ['2'] },
177 177 't+2' => { :op => 't+', :values => ['2'] },
178 178 't' => { :op => 't', :values => [''] },
179 179 'w' => { :op => 'w', :values => [''] },
180 180 '>t-2' => { :op => '>t-', :values => ['2'] },
181 181 '<t-2' => { :op => '<t-', :values => ['2'] },
182 182 't-2' => { :op => 't-', :values => ['2'] }},
183 183 'created_on' => {
184 184 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
185 185 '<t-2' => { :op => '<t-', :values => ['2'] },
186 186 '>t-2' => { :op => '>t-', :values => ['2'] },
187 187 't-2' => { :op => 't-', :values => ['2'] }},
188 188 'cf_1' => {
189 189 'c' => { :op => '=', :values => ['c'] },
190 190 '!c' => { :op => '!', :values => ['c'] },
191 191 '!*' => { :op => '!*', :values => [''] },
192 192 '*' => { :op => '*', :values => [''] }},
193 193 'estimated_hours' => {
194 194 '=13.4' => { :op => '=', :values => ['13.4'] },
195 195 '>=45' => { :op => '>=', :values => ['45'] },
196 196 '<=125' => { :op => '<=', :values => ['125'] },
197 197 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
198 198 '!*' => { :op => '!*', :values => [''] },
199 199 '*' => { :op => '*', :values => [''] }}
200 200 }
201 201
202 202 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
203 203
204 204 to_test.each do |field, expression_and_expected|
205 205 expression_and_expected.each do |filter_expression, expected|
206 206
207 207 get :index, :set_filter => 1, field => filter_expression
208 208
209 209 assert_response :success
210 210 assert_template 'index'
211 211 assert_not_nil assigns(:issues)
212 212
213 213 query = assigns(:query)
214 214 assert_not_nil query
215 215 assert query.has_filter?(field)
216 216 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
217 217 end
218 218 end
219 219 end
220 220
221 221 def test_index_with_project_and_empty_filters
222 222 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
223 223 assert_response :success
224 224 assert_template 'index'
225 225 assert_not_nil assigns(:issues)
226 226
227 227 query = assigns(:query)
228 228 assert_not_nil query
229 229 # no filter
230 230 assert_equal({}, query.filters)
231 231 end
232 232
233 233 def test_index_with_query
234 234 get :index, :project_id => 1, :query_id => 5
235 235 assert_response :success
236 236 assert_template 'index'
237 237 assert_not_nil assigns(:issues)
238 238 assert_nil assigns(:issue_count_by_group)
239 239 end
240 240
241 241 def test_index_with_query_grouped_by_tracker
242 242 get :index, :project_id => 1, :query_id => 6
243 243 assert_response :success
244 244 assert_template 'index'
245 245 assert_not_nil assigns(:issues)
246 246 assert_not_nil assigns(:issue_count_by_group)
247 247 end
248 248
249 249 def test_index_with_query_grouped_by_list_custom_field
250 250 get :index, :project_id => 1, :query_id => 9
251 251 assert_response :success
252 252 assert_template 'index'
253 253 assert_not_nil assigns(:issues)
254 254 assert_not_nil assigns(:issue_count_by_group)
255 255 end
256 256
257 257 def test_index_with_query_id_and_project_id_should_set_session_query
258 258 get :index, :project_id => 1, :query_id => 4
259 259 assert_response :success
260 260 assert_kind_of Hash, session[:query]
261 261 assert_equal 4, session[:query][:id]
262 262 assert_equal 1, session[:query][:project_id]
263 263 end
264 264
265 265 def test_index_with_invalid_query_id_should_respond_404
266 266 get :index, :project_id => 1, :query_id => 999
267 267 assert_response 404
268 268 end
269 269
270 270 def test_index_with_cross_project_query_in_session_should_show_project_issues
271 271 q = Query.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil)
272 272 @request.session[:query] = {:id => q.id, :project_id => 1}
273 273
274 274 with_settings :display_subprojects_issues => '0' do
275 275 get :index, :project_id => 1
276 276 end
277 277 assert_response :success
278 278 assert_not_nil assigns(:query)
279 279 assert_equal q.id, assigns(:query).id
280 280 assert_equal 1, assigns(:query).project_id
281 281 assert_equal [1], assigns(:issues).map(&:project_id).uniq
282 282 end
283 283
284 284 def test_private_query_should_not_be_available_to_other_users
285 285 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
286 286 @request.session[:user_id] = 3
287 287
288 288 get :index, :query_id => q.id
289 289 assert_response 403
290 290 end
291 291
292 292 def test_private_query_should_be_available_to_its_user
293 293 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
294 294 @request.session[:user_id] = 2
295 295
296 296 get :index, :query_id => q.id
297 297 assert_response :success
298 298 end
299 299
300 300 def test_public_query_should_be_available_to_other_users
301 301 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
302 302 @request.session[:user_id] = 3
303 303
304 304 get :index, :query_id => q.id
305 305 assert_response :success
306 306 end
307 307
308 308 def test_index_csv
309 309 get :index, :format => 'csv'
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).columns.size + 1, lines[0].split(',').size
316 316 end
317 317
318 318 def test_index_csv_with_project
319 319 get :index, :project_id => 1, :format => 'csv'
320 320 assert_response :success
321 321 assert_not_nil assigns(:issues)
322 322 assert_equal 'text/csv', @response.content_type
323 323 end
324 324
325 325 def test_index_csv_with_description
326 326 get :index, :format => 'csv', :description => '1'
327 327 assert_response :success
328 328 assert_not_nil assigns(:issues)
329 329 assert_equal 'text/csv', @response.content_type
330 330 assert @response.body.starts_with?("#,")
331 331 lines = @response.body.chomp.split("\n")
332 332 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
333 333 end
334 334
335 335 def test_index_csv_with_spent_time_column
336 336 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2)
337 337 TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today)
338 338
339 339 get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours)
340 340 assert_response :success
341 341 assert_equal 'text/csv', @response.content_type
342 342 lines = @response.body.chomp.split("\n")
343 343 assert_include "#{issue.id},#{issue.subject},7.33", lines
344 344 end
345 345
346 346 def test_index_csv_with_all_columns
347 347 get :index, :format => 'csv', :columns => 'all'
348 348 assert_response :success
349 349 assert_not_nil assigns(:issues)
350 350 assert_equal 'text/csv', @response.content_type
351 351 assert @response.body.starts_with?("#,")
352 352 lines = @response.body.chomp.split("\n")
353 353 assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size
354 354 end
355 355
356 356 def test_index_csv_with_multi_column_field
357 357 CustomField.find(1).update_attribute :multiple, true
358 358 issue = Issue.find(1)
359 359 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
360 360 issue.save!
361 361
362 362 get :index, :format => 'csv', :columns => 'all'
363 363 assert_response :success
364 364 lines = @response.body.chomp.split("\n")
365 365 assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
366 366 end
367 367
368 368 def test_index_csv_big_5
369 369 with_settings :default_language => "zh-TW" do
370 370 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
371 371 str_big5 = "\xa4@\xa4\xeb"
372 372 if str_utf8.respond_to?(:force_encoding)
373 373 str_utf8.force_encoding('UTF-8')
374 374 str_big5.force_encoding('Big5')
375 375 end
376 376 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
377 377 :status_id => 1, :priority => IssuePriority.all.first,
378 378 :subject => str_utf8)
379 379 assert issue.save
380 380
381 381 get :index, :project_id => 1,
382 382 :f => ['subject'],
383 383 :op => '=', :values => [str_utf8],
384 384 :format => 'csv'
385 385 assert_equal 'text/csv', @response.content_type
386 386 lines = @response.body.chomp.split("\n")
387 387 s1 = "\xaa\xac\xbaA"
388 388 if str_utf8.respond_to?(:force_encoding)
389 389 s1.force_encoding('Big5')
390 390 end
391 391 assert lines[0].include?(s1)
392 392 assert lines[1].include?(str_big5)
393 393 end
394 394 end
395 395
396 396 def test_index_csv_cannot_convert_should_be_replaced_big_5
397 397 with_settings :default_language => "zh-TW" do
398 398 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
399 399 if str_utf8.respond_to?(:force_encoding)
400 400 str_utf8.force_encoding('UTF-8')
401 401 end
402 402 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
403 403 :status_id => 1, :priority => IssuePriority.all.first,
404 404 :subject => str_utf8)
405 405 assert issue.save
406 406
407 407 get :index, :project_id => 1,
408 408 :f => ['subject'],
409 409 :op => '=', :values => [str_utf8],
410 410 :c => ['status', 'subject'],
411 411 :format => 'csv',
412 412 :set_filter => 1
413 413 assert_equal 'text/csv', @response.content_type
414 414 lines = @response.body.chomp.split("\n")
415 415 s1 = "\xaa\xac\xbaA" # status
416 416 if str_utf8.respond_to?(:force_encoding)
417 417 s1.force_encoding('Big5')
418 418 end
419 419 assert lines[0].include?(s1)
420 420 s2 = lines[1].split(",")[2]
421 421 if s1.respond_to?(:force_encoding)
422 422 s3 = "\xa5H?" # subject
423 423 s3.force_encoding('Big5')
424 424 assert_equal s3, s2
425 425 elsif RUBY_PLATFORM == 'java'
426 426 assert_equal "??", s2
427 427 else
428 428 assert_equal "\xa5H???", s2
429 429 end
430 430 end
431 431 end
432 432
433 433 def test_index_csv_tw
434 434 with_settings :default_language => "zh-TW" do
435 435 str1 = "test_index_csv_tw"
436 436 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
437 437 :status_id => 1, :priority => IssuePriority.all.first,
438 438 :subject => str1, :estimated_hours => '1234.5')
439 439 assert issue.save
440 440 assert_equal 1234.5, issue.estimated_hours
441 441
442 442 get :index, :project_id => 1,
443 443 :f => ['subject'],
444 444 :op => '=', :values => [str1],
445 445 :c => ['estimated_hours', 'subject'],
446 446 :format => 'csv',
447 447 :set_filter => 1
448 448 assert_equal 'text/csv', @response.content_type
449 449 lines = @response.body.chomp.split("\n")
450 450 assert_equal "#{issue.id},1234.50,#{str1}", lines[1]
451 451
452 452 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
453 453 if str_tw.respond_to?(:force_encoding)
454 454 str_tw.force_encoding('UTF-8')
455 455 end
456 456 assert_equal str_tw, l(:general_lang_name)
457 457 assert_equal ',', l(:general_csv_separator)
458 458 assert_equal '.', l(:general_csv_decimal_separator)
459 459 end
460 460 end
461 461
462 462 def test_index_csv_fr
463 463 with_settings :default_language => "fr" do
464 464 str1 = "test_index_csv_fr"
465 465 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
466 466 :status_id => 1, :priority => IssuePriority.all.first,
467 467 :subject => str1, :estimated_hours => '1234.5')
468 468 assert issue.save
469 469 assert_equal 1234.5, issue.estimated_hours
470 470
471 471 get :index, :project_id => 1,
472 472 :f => ['subject'],
473 473 :op => '=', :values => [str1],
474 474 :c => ['estimated_hours', 'subject'],
475 475 :format => 'csv',
476 476 :set_filter => 1
477 477 assert_equal 'text/csv', @response.content_type
478 478 lines = @response.body.chomp.split("\n")
479 479 assert_equal "#{issue.id};1234,50;#{str1}", lines[1]
480 480
481 481 str_fr = "Fran\xc3\xa7ais"
482 482 if str_fr.respond_to?(:force_encoding)
483 483 str_fr.force_encoding('UTF-8')
484 484 end
485 485 assert_equal str_fr, l(:general_lang_name)
486 486 assert_equal ';', l(:general_csv_separator)
487 487 assert_equal ',', l(:general_csv_decimal_separator)
488 488 end
489 489 end
490 490
491 491 def test_index_pdf
492 492 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
493 493 with_settings :default_language => lang do
494 494
495 495 get :index
496 496 assert_response :success
497 497 assert_template 'index'
498 498
499 499 if lang == "ja"
500 500 if RUBY_PLATFORM != 'java'
501 501 assert_equal "CP932", l(:general_pdf_encoding)
502 502 end
503 503 if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932"
504 504 next
505 505 end
506 506 end
507 507
508 508 get :index, :format => 'pdf'
509 509 assert_response :success
510 510 assert_not_nil assigns(:issues)
511 511 assert_equal 'application/pdf', @response.content_type
512 512
513 513 get :index, :project_id => 1, :format => 'pdf'
514 514 assert_response :success
515 515 assert_not_nil assigns(:issues)
516 516 assert_equal 'application/pdf', @response.content_type
517 517
518 518 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
519 519 assert_response :success
520 520 assert_not_nil assigns(:issues)
521 521 assert_equal 'application/pdf', @response.content_type
522 522 end
523 523 end
524 524 end
525 525
526 526 def test_index_pdf_with_query_grouped_by_list_custom_field
527 527 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
528 528 assert_response :success
529 529 assert_not_nil assigns(:issues)
530 530 assert_not_nil assigns(:issue_count_by_group)
531 531 assert_equal 'application/pdf', @response.content_type
532 532 end
533 533
534 534 def test_index_sort
535 535 get :index, :sort => 'tracker,id:desc'
536 536 assert_response :success
537 537
538 538 sort_params = @request.session['issues_index_sort']
539 539 assert sort_params.is_a?(String)
540 540 assert_equal 'tracker,id:desc', sort_params
541 541
542 542 issues = assigns(:issues)
543 543 assert_not_nil issues
544 544 assert !issues.empty?
545 545 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
546 546 end
547 547
548 548 def test_index_sort_by_field_not_included_in_columns
549 549 Setting.issue_list_default_columns = %w(subject author)
550 550 get :index, :sort => 'tracker'
551 551 end
552 552
553 553 def test_index_sort_by_assigned_to
554 554 get :index, :sort => 'assigned_to'
555 555 assert_response :success
556 556 assignees = assigns(:issues).collect(&:assigned_to).compact
557 557 assert_equal assignees.sort, assignees
558 558 end
559 559
560 560 def test_index_sort_by_assigned_to_desc
561 561 get :index, :sort => 'assigned_to:desc'
562 562 assert_response :success
563 563 assignees = assigns(:issues).collect(&:assigned_to).compact
564 564 assert_equal assignees.sort.reverse, assignees
565 565 end
566 566
567 567 def test_index_group_by_assigned_to
568 568 get :index, :group_by => 'assigned_to', :sort => 'priority'
569 569 assert_response :success
570 570 end
571 571
572 572 def test_index_sort_by_author
573 573 get :index, :sort => 'author'
574 574 assert_response :success
575 575 authors = assigns(:issues).collect(&:author)
576 576 assert_equal authors.sort, authors
577 577 end
578 578
579 579 def test_index_sort_by_author_desc
580 580 get :index, :sort => 'author:desc'
581 581 assert_response :success
582 582 authors = assigns(:issues).collect(&:author)
583 583 assert_equal authors.sort.reverse, authors
584 584 end
585 585
586 586 def test_index_group_by_author
587 587 get :index, :group_by => 'author', :sort => 'priority'
588 588 assert_response :success
589 589 end
590 590
591 591 def test_index_sort_by_spent_hours
592 592 get :index, :sort => 'spent_hours:desc'
593 593 assert_response :success
594 594 hours = assigns(:issues).collect(&:spent_hours)
595 595 assert_equal hours.sort.reverse, hours
596 596 end
597 597
598 598 def test_index_with_columns
599 599 columns = ['tracker', 'subject', 'assigned_to']
600 600 get :index, :set_filter => 1, :c => columns
601 601 assert_response :success
602 602
603 603 # query should use specified columns
604 604 query = assigns(:query)
605 605 assert_kind_of Query, query
606 606 assert_equal columns, query.column_names.map(&:to_s)
607 607
608 608 # columns should be stored in session
609 609 assert_kind_of Hash, session[:query]
610 610 assert_kind_of Array, session[:query][:column_names]
611 611 assert_equal columns, session[:query][:column_names].map(&:to_s)
612 612
613 613 # ensure only these columns are kept in the selected columns list
614 614 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
615 615 :children => { :count => 3 }
616 616 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
617 617 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
618 618 end
619 619
620 620 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
621 621 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
622 622 get :index, :set_filter => 1
623 623
624 624 # query should use specified columns
625 625 query = assigns(:query)
626 626 assert_kind_of Query, query
627 627 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
628 628 end
629 629
630 630 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
631 631 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
632 632 columns = ['tracker', 'subject', 'assigned_to']
633 633 get :index, :set_filter => 1, :c => columns
634 634
635 635 # query should use specified columns
636 636 query = assigns(:query)
637 637 assert_kind_of Query, query
638 638 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
639 639 end
640 640
641 641 def test_index_with_custom_field_column
642 642 columns = %w(tracker subject cf_2)
643 643 get :index, :set_filter => 1, :c => columns
644 644 assert_response :success
645 645
646 646 # query should use specified columns
647 647 query = assigns(:query)
648 648 assert_kind_of Query, query
649 649 assert_equal columns, query.column_names.map(&:to_s)
650 650
651 651 assert_tag :td,
652 652 :attributes => {:class => 'cf_2 string'},
653 653 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
654 654 end
655 655
656 656 def test_index_with_multi_custom_field_column
657 657 field = CustomField.find(1)
658 658 field.update_attribute :multiple, true
659 659 issue = Issue.find(1)
660 660 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
661 661 issue.save!
662 662
663 663 get :index, :set_filter => 1, :c => %w(tracker subject cf_1)
664 664 assert_response :success
665 665
666 666 assert_tag :td,
667 667 :attributes => {:class => /cf_1/},
668 668 :content => 'MySQL, Oracle'
669 669 end
670 670
671 671 def test_index_with_multi_user_custom_field_column
672 672 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
673 673 :tracker_ids => [1], :is_for_all => true)
674 674 issue = Issue.find(1)
675 675 issue.custom_field_values = {field.id => ['2', '3']}
676 676 issue.save!
677 677
678 678 get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"]
679 679 assert_response :success
680 680
681 681 assert_tag :td,
682 682 :attributes => {:class => /cf_#{field.id}/},
683 683 :child => {:tag => 'a', :content => 'John Smith'}
684 684 end
685 685
686 686 def test_index_with_date_column
687 687 Issue.find(1).update_attribute :start_date, '1987-08-24'
688 688
689 689 with_settings :date_format => '%d/%m/%Y' do
690 690 get :index, :set_filter => 1, :c => %w(start_date)
691 691 assert_tag 'td', :attributes => {:class => /start_date/}, :content => '24/08/1987'
692 692 end
693 693 end
694 694
695 695 def test_index_with_done_ratio
696 696 Issue.find(1).update_attribute :done_ratio, 40
697 697
698 698 get :index, :set_filter => 1, :c => %w(done_ratio)
699 699 assert_tag 'td', :attributes => {:class => /done_ratio/},
700 700 :child => {:tag => 'table', :attributes => {:class => 'progress'},
701 701 :descendant => {:tag => 'td', :attributes => {:class => 'closed', :style => 'width: 40%;'}}
702 702 }
703 703 end
704 704
705 705 def test_index_with_spent_hours_column
706 706 get :index, :set_filter => 1, :c => %w(subject spent_hours)
707 707
708 708 assert_tag 'tr', :attributes => {:id => 'issue-3'},
709 709 :child => {
710 710 :tag => 'td', :attributes => {:class => /spent_hours/}, :content => '1.00'
711 711 }
712 712 end
713 713
714 714 def test_index_should_not_show_spent_hours_column_without_permission
715 715 Role.anonymous.remove_permission! :view_time_entries
716 716 get :index, :set_filter => 1, :c => %w(subject spent_hours)
717 717
718 718 assert_no_tag 'td', :attributes => {:class => /spent_hours/}
719 719 end
720 720
721 721 def test_index_with_fixed_version
722 722 get :index, :set_filter => 1, :c => %w(fixed_version)
723 723 assert_tag 'td', :attributes => {:class => /fixed_version/},
724 724 :child => {:tag => 'a', :content => '1.0', :attributes => {:href => '/versions/2'}}
725 725 end
726 726
727 727 def test_index_send_html_if_query_is_invalid
728 728 get :index, :f => ['start_date'], :op => {:start_date => '='}
729 729 assert_equal 'text/html', @response.content_type
730 730 assert_template 'index'
731 731 end
732 732
733 733 def test_index_send_nothing_if_query_is_invalid
734 734 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
735 735 assert_equal 'text/csv', @response.content_type
736 736 assert @response.body.blank?
737 737 end
738 738
739 739 def test_show_by_anonymous
740 740 get :show, :id => 1
741 741 assert_response :success
742 742 assert_template 'show'
743 743 assert_not_nil assigns(:issue)
744 744 assert_equal Issue.find(1), assigns(:issue)
745 745
746 746 # anonymous role is allowed to add a note
747 747 assert_tag :tag => 'form',
748 748 :descendant => { :tag => 'fieldset',
749 749 :child => { :tag => 'legend',
750 750 :content => /Notes/ } }
751 751 assert_tag :tag => 'title',
752 752 :content => "Bug #1: Can't print recipes - eCookbook - Redmine"
753 753 end
754 754
755 755 def test_show_by_manager
756 756 @request.session[:user_id] = 2
757 757 get :show, :id => 1
758 758 assert_response :success
759 759
760 760 assert_tag :tag => 'a',
761 761 :content => /Quote/
762 762
763 763 assert_tag :tag => 'form',
764 764 :descendant => { :tag => 'fieldset',
765 765 :child => { :tag => 'legend',
766 766 :content => /Change properties/ } },
767 767 :descendant => { :tag => 'fieldset',
768 768 :child => { :tag => 'legend',
769 769 :content => /Log time/ } },
770 770 :descendant => { :tag => 'fieldset',
771 771 :child => { :tag => 'legend',
772 772 :content => /Notes/ } }
773 773 end
774 774
775 775 def test_show_should_display_update_form
776 776 @request.session[:user_id] = 2
777 777 get :show, :id => 1
778 778 assert_response :success
779 779
780 780 assert_tag 'form', :attributes => {:id => 'issue-form'}
781 781 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
782 782 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
783 783 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
784 784 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
785 785 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
786 786 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
787 787 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
788 788 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
789 789 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
790 790 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
791 791 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
792 792 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
793 793 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
794 794 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
795 795 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
796 796 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
797 797 assert_tag 'textarea', :attributes => {:name => 'notes'}
798 798 end
799 799
800 800 def test_show_should_display_update_form_with_minimal_permissions
801 801 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
802 802 Workflow.delete_all :role_id => 1
803 803
804 804 @request.session[:user_id] = 2
805 805 get :show, :id => 1
806 806 assert_response :success
807 807
808 808 assert_tag 'form', :attributes => {:id => 'issue-form'}
809 809 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
810 810 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
811 811 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
812 812 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
813 813 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
814 814 assert_no_tag 'select', :attributes => {:name => 'issue[status_id]'}
815 815 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
816 816 assert_no_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
817 817 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
818 818 assert_no_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
819 819 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
820 820 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
821 821 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
822 822 assert_no_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
823 823 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
824 824 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
825 825 assert_tag 'textarea', :attributes => {:name => 'notes'}
826 826 end
827 827
828 828 def test_show_should_display_update_form_with_workflow_permissions
829 829 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
830 830
831 831 @request.session[:user_id] = 2
832 832 get :show, :id => 1
833 833 assert_response :success
834 834
835 835 assert_tag 'form', :attributes => {:id => 'issue-form'}
836 836 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
837 837 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
838 838 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
839 839 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
840 840 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
841 841 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
842 842 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
843 843 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
844 844 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
845 845 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
846 846 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
847 847 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
848 848 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
849 849 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
850 850 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
851 851 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
852 852 assert_tag 'textarea', :attributes => {:name => 'notes'}
853 853 end
854 854
855 855 def test_show_should_not_display_update_form_without_permissions
856 856 Role.find(1).update_attribute :permissions, [:view_issues]
857 857
858 858 @request.session[:user_id] = 2
859 859 get :show, :id => 1
860 860 assert_response :success
861 861
862 862 assert_no_tag 'form', :attributes => {:id => 'issue-form'}
863 863 end
864 864
865 865 def test_update_form_should_not_display_inactive_enumerations
866 866 @request.session[:user_id] = 2
867 867 get :show, :id => 1
868 868 assert_response :success
869 869
870 870 assert ! IssuePriority.find(15).active?
871 871 assert_no_tag :option, :attributes => {:value => '15'},
872 872 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
873 873 end
874 874
875 875 def test_update_form_should_allow_attachment_upload
876 876 @request.session[:user_id] = 2
877 877 get :show, :id => 1
878 878
879 879 assert_tag :tag => 'form',
880 880 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
881 881 :descendant => {
882 882 :tag => 'input',
883 883 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
884 884 }
885 885 end
886 886
887 887 def test_show_should_deny_anonymous_access_without_permission
888 888 Role.anonymous.remove_permission!(:view_issues)
889 889 get :show, :id => 1
890 890 assert_response :redirect
891 891 end
892 892
893 893 def test_show_should_deny_anonymous_access_to_private_issue
894 894 Issue.update_all(["is_private = ?", true], "id = 1")
895 895 get :show, :id => 1
896 896 assert_response :redirect
897 897 end
898 898
899 899 def test_show_should_deny_non_member_access_without_permission
900 900 Role.non_member.remove_permission!(:view_issues)
901 901 @request.session[:user_id] = 9
902 902 get :show, :id => 1
903 903 assert_response 403
904 904 end
905 905
906 906 def test_show_should_deny_non_member_access_to_private_issue
907 907 Issue.update_all(["is_private = ?", true], "id = 1")
908 908 @request.session[:user_id] = 9
909 909 get :show, :id => 1
910 910 assert_response 403
911 911 end
912 912
913 913 def test_show_should_deny_member_access_without_permission
914 914 Role.find(1).remove_permission!(:view_issues)
915 915 @request.session[:user_id] = 2
916 916 get :show, :id => 1
917 917 assert_response 403
918 918 end
919 919
920 920 def test_show_should_deny_member_access_to_private_issue_without_permission
921 921 Issue.update_all(["is_private = ?", true], "id = 1")
922 922 @request.session[:user_id] = 3
923 923 get :show, :id => 1
924 924 assert_response 403
925 925 end
926 926
927 927 def test_show_should_allow_author_access_to_private_issue
928 928 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
929 929 @request.session[:user_id] = 3
930 930 get :show, :id => 1
931 931 assert_response :success
932 932 end
933 933
934 934 def test_show_should_allow_assignee_access_to_private_issue
935 935 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
936 936 @request.session[:user_id] = 3
937 937 get :show, :id => 1
938 938 assert_response :success
939 939 end
940 940
941 941 def test_show_should_allow_member_access_to_private_issue_with_permission
942 942 Issue.update_all(["is_private = ?", true], "id = 1")
943 943 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
944 944 @request.session[:user_id] = 3
945 945 get :show, :id => 1
946 946 assert_response :success
947 947 end
948 948
949 949 def test_show_should_not_disclose_relations_to_invisible_issues
950 950 Setting.cross_project_issue_relations = '1'
951 951 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
952 952 # Relation to a private project issue
953 953 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
954 954
955 955 get :show, :id => 1
956 956 assert_response :success
957 957
958 958 assert_tag :div, :attributes => { :id => 'relations' },
959 959 :descendant => { :tag => 'a', :content => /#2$/ }
960 960 assert_no_tag :div, :attributes => { :id => 'relations' },
961 961 :descendant => { :tag => 'a', :content => /#4$/ }
962 962 end
963 963
964 964 def test_show_should_list_subtasks
965 965 Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
966 966
967 967 get :show, :id => 1
968 968 assert_response :success
969 969 assert_tag 'div', :attributes => {:id => 'issue_tree'},
970 970 :descendant => {:tag => 'td', :content => /Child Issue/, :attributes => {:class => /subject/}}
971 971 end
972 972
973 973 def test_show_should_list_parents
974 974 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
975 975
976 976 get :show, :id => issue.id
977 977 assert_response :success
978 978 assert_tag 'div', :attributes => {:class => 'subject'},
979 979 :descendant => {:tag => 'h3', :content => 'Child Issue'}
980 980 assert_tag 'div', :attributes => {:class => 'subject'},
981 981 :descendant => {:tag => 'a', :attributes => {:href => '/issues/1'}}
982 982 end
983 983
984 984 def test_show_should_not_display_prev_next_links_without_query_in_session
985 985 get :show, :id => 1
986 986 assert_response :success
987 987 assert_nil assigns(:prev_issue_id)
988 988 assert_nil assigns(:next_issue_id)
989 989
990 990 assert_no_tag 'div', :attributes => {:class => /next-prev-links/}
991 991 end
992 992
993 993 def test_show_should_display_prev_next_links_with_query_in_session
994 994 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
995 995 @request.session['issues_index_sort'] = 'id'
996 996
997 997 with_settings :display_subprojects_issues => '0' do
998 998 get :show, :id => 3
999 999 end
1000 1000
1001 1001 assert_response :success
1002 1002 # Previous and next issues for all projects
1003 1003 assert_equal 2, assigns(:prev_issue_id)
1004 1004 assert_equal 5, assigns(:next_issue_id)
1005 1005
1006 1006 assert_tag 'div', :attributes => {:class => /next-prev-links/}
1007 1007 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
1008 1008 assert_tag 'a', :attributes => {:href => '/issues/5'}, :content => /Next/
1009 1009
1010 1010 count = Issue.open.visible.count
1011 1011 assert_tag 'span', :attributes => {:class => 'position'}, :content => "3 of #{count}"
1012 1012 end
1013 1013
1014 1014 def test_show_should_display_prev_next_links_with_saved_query_in_session
1015 1015 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1,
1016 1016 :filters => {'status_id' => {:values => ['5'], :operator => '='}},
1017 1017 :sort_criteria => [['id', 'asc']])
1018 1018 @request.session[:query] = {:id => query.id, :project_id => nil}
1019 1019
1020 1020 get :show, :id => 11
1021 1021
1022 1022 assert_response :success
1023 1023 assert_equal query, assigns(:query)
1024 1024 # Previous and next issues for all projects
1025 1025 assert_equal 8, assigns(:prev_issue_id)
1026 1026 assert_equal 12, assigns(:next_issue_id)
1027 1027
1028 1028 assert_tag 'a', :attributes => {:href => '/issues/8'}, :content => /Previous/
1029 1029 assert_tag 'a', :attributes => {:href => '/issues/12'}, :content => /Next/
1030 1030 end
1031 1031
1032 1032 def test_show_should_display_prev_next_links_with_query_and_sort_on_association
1033 1033 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1034 1034
1035 1035 %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
1036 1036 @request.session['issues_index_sort'] = assoc_sort
1037 1037
1038 1038 get :show, :id => 3
1039 1039 assert_response :success, "Wrong response status for #{assoc_sort} sort"
1040 1040
1041 1041 assert_tag 'div', :attributes => {:class => /next-prev-links/}, :content => /Previous/
1042 1042 assert_tag 'div', :attributes => {:class => /next-prev-links/}, :content => /Next/
1043 1043 end
1044 1044 end
1045 1045
1046 1046 def test_show_should_display_prev_next_links_with_project_query_in_session
1047 1047 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1048 1048 @request.session['issues_index_sort'] = 'id'
1049 1049
1050 1050 with_settings :display_subprojects_issues => '0' do
1051 1051 get :show, :id => 3
1052 1052 end
1053 1053
1054 1054 assert_response :success
1055 1055 # Previous and next issues inside project
1056 1056 assert_equal 2, assigns(:prev_issue_id)
1057 1057 assert_equal 7, assigns(:next_issue_id)
1058 1058
1059 1059 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
1060 1060 assert_tag 'a', :attributes => {:href => '/issues/7'}, :content => /Next/
1061 1061 end
1062 1062
1063 1063 def test_show_should_not_display_prev_link_for_first_issue
1064 1064 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1065 1065 @request.session['issues_index_sort'] = 'id'
1066 1066
1067 1067 with_settings :display_subprojects_issues => '0' do
1068 1068 get :show, :id => 1
1069 1069 end
1070 1070
1071 1071 assert_response :success
1072 1072 assert_nil assigns(:prev_issue_id)
1073 1073 assert_equal 2, assigns(:next_issue_id)
1074 1074
1075 1075 assert_no_tag 'a', :content => /Previous/
1076 1076 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Next/
1077 1077 end
1078 1078
1079 1079 def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
1080 1080 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1}
1081 1081 @request.session['issues_index_sort'] = 'id'
1082 1082
1083 1083 get :show, :id => 1
1084 1084
1085 1085 assert_response :success
1086 1086 assert_nil assigns(:prev_issue_id)
1087 1087 assert_nil assigns(:next_issue_id)
1088 1088
1089 1089 assert_no_tag 'a', :content => /Previous/
1090 1090 assert_no_tag 'a', :content => /Next/
1091 1091 end
1092 1092
1093 1093 def test_show_should_display_visible_changesets_from_other_projects
1094 1094 project = Project.find(2)
1095 1095 issue = project.issues.first
1096 1096 issue.changeset_ids = [102]
1097 1097 issue.save!
1098 1098 project.disable_module! :repository
1099 1099
1100 1100 @request.session[:user_id] = 2
1101 1101 get :show, :id => issue.id
1102 1102 assert_tag 'a', :attributes => {:href => "/projects/ecookbook/repository/revisions/3"}
1103 1103 end
1104 1104
1105 1105 def test_show_with_multi_custom_field
1106 1106 field = CustomField.find(1)
1107 1107 field.update_attribute :multiple, true
1108 1108 issue = Issue.find(1)
1109 1109 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
1110 1110 issue.save!
1111 1111
1112 1112 get :show, :id => 1
1113 1113 assert_response :success
1114 1114
1115 1115 assert_tag :td, :content => 'MySQL, Oracle'
1116 1116 end
1117 1117
1118 1118 def test_show_with_multi_user_custom_field
1119 1119 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1120 1120 :tracker_ids => [1], :is_for_all => true)
1121 1121 issue = Issue.find(1)
1122 1122 issue.custom_field_values = {field.id => ['2', '3']}
1123 1123 issue.save!
1124 1124
1125 1125 get :show, :id => 1
1126 1126 assert_response :success
1127 1127
1128 1128 # TODO: should display links
1129 1129 assert_tag :td, :content => 'Dave Lopper, John Smith'
1130 1130 end
1131 1131
1132 1132 def test_show_atom
1133 1133 get :show, :id => 2, :format => 'atom'
1134 1134 assert_response :success
1135 1135 assert_template 'journals/index'
1136 1136 # Inline image
1137 1137 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
1138 1138 end
1139 1139
1140 1140 def test_show_export_to_pdf
1141 1141 get :show, :id => 3, :format => 'pdf'
1142 1142 assert_response :success
1143 1143 assert_equal 'application/pdf', @response.content_type
1144 1144 assert @response.body.starts_with?('%PDF')
1145 1145 assert_not_nil assigns(:issue)
1146 1146 end
1147 1147
1148 1148 def test_get_new
1149 1149 @request.session[:user_id] = 2
1150 1150 get :new, :project_id => 1, :tracker_id => 1
1151 1151 assert_response :success
1152 1152 assert_template 'new'
1153 1153
1154 1154 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
1155 1155 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1156 1156 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1157 1157 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1158 1158 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1159 1159 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1160 1160 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1161 1161 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1162 1162 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1163 1163 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1164 1164 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1165 1165 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1166 1166 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1167 1167 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1168 1168 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1169 1169 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1170 1170
1171 1171 # Be sure we don't display inactive IssuePriorities
1172 1172 assert ! IssuePriority.find(15).active?
1173 1173 assert_no_tag :option, :attributes => {:value => '15'},
1174 1174 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1175 1175 end
1176 1176
1177 1177 def test_get_new_with_minimal_permissions
1178 1178 Role.find(1).update_attribute :permissions, [:add_issues]
1179 1179 Workflow.delete_all :role_id => 1
1180 1180
1181 1181 @request.session[:user_id] = 2
1182 1182 get :new, :project_id => 1, :tracker_id => 1
1183 1183 assert_response :success
1184 1184 assert_template 'new'
1185 1185
1186 1186 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
1187 1187 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1188 1188 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1189 1189 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1190 1190 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1191 1191 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1192 1192 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1193 1193 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1194 1194 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1195 1195 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1196 1196 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1197 1197 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1198 1198 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1199 1199 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1200 1200 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1201 1201 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1202 1202 end
1203 1203
1204 1204 def test_get_new_with_list_custom_field
1205 1205 @request.session[:user_id] = 2
1206 1206 get :new, :project_id => 1, :tracker_id => 1
1207 1207 assert_response :success
1208 1208 assert_template 'new'
1209 1209
1210 1210 assert_tag 'select',
1211 1211 :attributes => {:name => 'issue[custom_field_values][1]'},
1212 1212 :children => {:count => 4},
1213 1213 :child => {:tag => 'option', :attributes => {:value => 'MySQL'}, :content => 'MySQL'}
1214 1214 end
1215 1215
1216 1216 def test_get_new_with_multi_custom_field
1217 1217 field = IssueCustomField.find(1)
1218 1218 field.update_attribute :multiple, true
1219 1219
1220 1220 @request.session[:user_id] = 2
1221 1221 get :new, :project_id => 1, :tracker_id => 1
1222 1222 assert_response :success
1223 1223 assert_template 'new'
1224 1224
1225 1225 assert_tag 'select',
1226 1226 :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'},
1227 1227 :children => {:count => 3},
1228 1228 :child => {:tag => 'option', :attributes => {:value => 'MySQL'}, :content => 'MySQL'}
1229 1229 assert_tag 'input',
1230 1230 :attributes => {:name => 'issue[custom_field_values][1][]', :value => ''}
1231 1231 end
1232 1232
1233 1233 def test_get_new_with_multi_user_custom_field
1234 1234 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1235 1235 :tracker_ids => [1], :is_for_all => true)
1236 1236
1237 1237 @request.session[:user_id] = 2
1238 1238 get :new, :project_id => 1, :tracker_id => 1
1239 1239 assert_response :success
1240 1240 assert_template 'new'
1241 1241
1242 1242 assert_tag 'select',
1243 1243 :attributes => {:name => "issue[custom_field_values][#{field.id}][]", :multiple => 'multiple'},
1244 1244 :children => {:count => Project.find(1).users.count},
1245 1245 :child => {:tag => 'option', :attributes => {:value => '2'}, :content => 'John Smith'}
1246 1246 assert_tag 'input',
1247 1247 :attributes => {:name => "issue[custom_field_values][#{field.id}][]", :value => ''}
1248 1248 end
1249 1249
1250 1250 def test_get_new_without_default_start_date_is_creation_date
1251 1251 Setting.default_issue_start_date_to_creation_date = 0
1252 1252
1253 1253 @request.session[:user_id] = 2
1254 1254 get :new, :project_id => 1, :tracker_id => 1
1255 1255 assert_response :success
1256 1256 assert_template 'new'
1257 1257
1258 1258 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
1259 1259 :value => nil }
1260 1260 end
1261 1261
1262 1262 def test_get_new_with_default_start_date_is_creation_date
1263 1263 Setting.default_issue_start_date_to_creation_date = 1
1264 1264
1265 1265 @request.session[:user_id] = 2
1266 1266 get :new, :project_id => 1, :tracker_id => 1
1267 1267 assert_response :success
1268 1268 assert_template 'new'
1269 1269
1270 1270 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
1271 1271 :value => Date.today.to_s }
1272 1272 end
1273 1273
1274 1274 def test_get_new_form_should_allow_attachment_upload
1275 1275 @request.session[:user_id] = 2
1276 1276 get :new, :project_id => 1, :tracker_id => 1
1277 1277
1278 1278 assert_tag :tag => 'form',
1279 1279 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
1280 1280 :descendant => {
1281 1281 :tag => 'input',
1282 1282 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
1283 1283 }
1284 1284 end
1285 1285
1286 def test_get_new_should_prefill_the_form_from_params
1287 @request.session[:user_id] = 2
1288 get :new, :project_id => 1,
1289 :issue => {:tracker_id => 3, :description => 'Prefilled', :custom_field_values => {'2' => 'Custom field value'}}
1290
1291 issue = assigns(:issue)
1292 assert_equal 3, issue.tracker_id
1293 assert_equal 'Prefilled', issue.description
1294 assert_equal 'Custom field value', issue.custom_field_value(2)
1295
1296 assert_tag 'select',
1297 :attributes => {:name => 'issue[tracker_id]'},
1298 :child => {:tag => 'option', :attributes => {:value => '3', :selected => 'selected'}}
1299 assert_tag 'textarea',
1300 :attributes => {:name => 'issue[description]'}, :content => 'Prefilled'
1301 assert_tag 'input',
1302 :attributes => {:name => 'issue[custom_field_values][2]', :value => 'Custom field value'}
1303 end
1304
1286 1305 def test_get_new_without_tracker_id
1287 1306 @request.session[:user_id] = 2
1288 1307 get :new, :project_id => 1
1289 1308 assert_response :success
1290 1309 assert_template 'new'
1291 1310
1292 1311 issue = assigns(:issue)
1293 1312 assert_not_nil issue
1294 1313 assert_equal Project.find(1).trackers.first, issue.tracker
1295 1314 end
1296 1315
1297 1316 def test_get_new_with_no_default_status_should_display_an_error
1298 1317 @request.session[:user_id] = 2
1299 1318 IssueStatus.delete_all
1300 1319
1301 1320 get :new, :project_id => 1
1302 1321 assert_response 500
1303 1322 assert_error_tag :content => /No default issue/
1304 1323 end
1305 1324
1306 1325 def test_get_new_with_no_tracker_should_display_an_error
1307 1326 @request.session[:user_id] = 2
1308 1327 Tracker.delete_all
1309 1328
1310 1329 get :new, :project_id => 1
1311 1330 assert_response 500
1312 1331 assert_error_tag :content => /No tracker/
1313 1332 end
1314 1333
1315 1334 def test_update_new_form
1316 1335 @request.session[:user_id] = 2
1317 1336 xhr :post, :new, :project_id => 1,
1318 1337 :issue => {:tracker_id => 2,
1319 1338 :subject => 'This is the test_new issue',
1320 1339 :description => 'This is the description',
1321 1340 :priority_id => 5}
1322 1341 assert_response :success
1323 1342 assert_template 'attributes'
1324 1343
1325 1344 issue = assigns(:issue)
1326 1345 assert_kind_of Issue, issue
1327 1346 assert_equal 1, issue.project_id
1328 1347 assert_equal 2, issue.tracker_id
1329 1348 assert_equal 'This is the test_new issue', issue.subject
1330 1349 end
1331 1350
1332 1351 def test_post_create
1333 1352 @request.session[:user_id] = 2
1334 1353 assert_difference 'Issue.count' do
1335 1354 post :create, :project_id => 1,
1336 1355 :issue => {:tracker_id => 3,
1337 1356 :status_id => 2,
1338 1357 :subject => 'This is the test_new issue',
1339 1358 :description => 'This is the description',
1340 1359 :priority_id => 5,
1341 1360 :start_date => '2010-11-07',
1342 1361 :estimated_hours => '',
1343 1362 :custom_field_values => {'2' => 'Value for field 2'}}
1344 1363 end
1345 1364 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1346 1365
1347 1366 issue = Issue.find_by_subject('This is the test_new issue')
1348 1367 assert_not_nil issue
1349 1368 assert_equal 2, issue.author_id
1350 1369 assert_equal 3, issue.tracker_id
1351 1370 assert_equal 2, issue.status_id
1352 1371 assert_equal Date.parse('2010-11-07'), issue.start_date
1353 1372 assert_nil issue.estimated_hours
1354 1373 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
1355 1374 assert_not_nil v
1356 1375 assert_equal 'Value for field 2', v.value
1357 1376 end
1358 1377
1359 1378 def test_post_new_with_group_assignment
1360 1379 group = Group.find(11)
1361 1380 project = Project.find(1)
1362 1381 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
1363 1382
1364 1383 with_settings :issue_group_assignment => '1' do
1365 1384 @request.session[:user_id] = 2
1366 1385 assert_difference 'Issue.count' do
1367 1386 post :create, :project_id => project.id,
1368 1387 :issue => {:tracker_id => 3,
1369 1388 :status_id => 1,
1370 1389 :subject => 'This is the test_new_with_group_assignment issue',
1371 1390 :assigned_to_id => group.id}
1372 1391 end
1373 1392 end
1374 1393 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1375 1394
1376 1395 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
1377 1396 assert_not_nil issue
1378 1397 assert_equal group, issue.assigned_to
1379 1398 end
1380 1399
1381 1400 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
1382 1401 Setting.default_issue_start_date_to_creation_date = 0
1383 1402
1384 1403 @request.session[:user_id] = 2
1385 1404 assert_difference 'Issue.count' do
1386 1405 post :create, :project_id => 1,
1387 1406 :issue => {:tracker_id => 3,
1388 1407 :status_id => 2,
1389 1408 :subject => 'This is the test_new issue',
1390 1409 :description => 'This is the description',
1391 1410 :priority_id => 5,
1392 1411 :estimated_hours => '',
1393 1412 :custom_field_values => {'2' => 'Value for field 2'}}
1394 1413 end
1395 1414 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1396 1415
1397 1416 issue = Issue.find_by_subject('This is the test_new issue')
1398 1417 assert_not_nil issue
1399 1418 assert_nil issue.start_date
1400 1419 end
1401 1420
1402 1421 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1403 1422 Setting.default_issue_start_date_to_creation_date = 1
1404 1423
1405 1424 @request.session[:user_id] = 2
1406 1425 assert_difference 'Issue.count' do
1407 1426 post :create, :project_id => 1,
1408 1427 :issue => {:tracker_id => 3,
1409 1428 :status_id => 2,
1410 1429 :subject => 'This is the test_new issue',
1411 1430 :description => 'This is the description',
1412 1431 :priority_id => 5,
1413 1432 :estimated_hours => '',
1414 1433 :custom_field_values => {'2' => 'Value for field 2'}}
1415 1434 end
1416 1435 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1417 1436
1418 1437 issue = Issue.find_by_subject('This is the test_new issue')
1419 1438 assert_not_nil issue
1420 1439 assert_equal Date.today, issue.start_date
1421 1440 end
1422 1441
1423 1442 def test_post_create_and_continue
1424 1443 @request.session[:user_id] = 2
1425 1444 assert_difference 'Issue.count' do
1426 1445 post :create, :project_id => 1,
1427 1446 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1428 1447 :continue => ''
1429 1448 end
1430 1449
1431 1450 issue = Issue.first(:order => 'id DESC')
1432 1451 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1433 1452 assert_not_nil flash[:notice], "flash was not set"
1434 1453 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
1435 1454 end
1436 1455
1437 1456 def test_post_create_without_custom_fields_param
1438 1457 @request.session[:user_id] = 2
1439 1458 assert_difference 'Issue.count' do
1440 1459 post :create, :project_id => 1,
1441 1460 :issue => {:tracker_id => 1,
1442 1461 :subject => 'This is the test_new issue',
1443 1462 :description => 'This is the description',
1444 1463 :priority_id => 5}
1445 1464 end
1446 1465 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1447 1466 end
1448 1467
1449 1468 def test_post_create_with_multi_custom_field
1450 1469 field = IssueCustomField.find_by_name('Database')
1451 1470 field.update_attribute(:multiple, true)
1452 1471
1453 1472 @request.session[:user_id] = 2
1454 1473 assert_difference 'Issue.count' do
1455 1474 post :create, :project_id => 1,
1456 1475 :issue => {:tracker_id => 1,
1457 1476 :subject => 'This is the test_new issue',
1458 1477 :description => 'This is the description',
1459 1478 :priority_id => 5,
1460 1479 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}}
1461 1480 end
1462 1481 assert_response 302
1463 1482 issue = Issue.first(:order => 'id DESC')
1464 1483 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
1465 1484 end
1466 1485
1467 1486 def test_post_create_with_empty_multi_custom_field
1468 1487 field = IssueCustomField.find_by_name('Database')
1469 1488 field.update_attribute(:multiple, true)
1470 1489
1471 1490 @request.session[:user_id] = 2
1472 1491 assert_difference 'Issue.count' do
1473 1492 post :create, :project_id => 1,
1474 1493 :issue => {:tracker_id => 1,
1475 1494 :subject => 'This is the test_new issue',
1476 1495 :description => 'This is the description',
1477 1496 :priority_id => 5,
1478 1497 :custom_field_values => {'1' => ['']}}
1479 1498 end
1480 1499 assert_response 302
1481 1500 issue = Issue.first(:order => 'id DESC')
1482 1501 assert_equal [''], issue.custom_field_value(1).sort
1483 1502 end
1484 1503
1485 1504 def test_post_create_with_multi_user_custom_field
1486 1505 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1487 1506 :tracker_ids => [1], :is_for_all => true)
1488 1507
1489 1508 @request.session[:user_id] = 2
1490 1509 assert_difference 'Issue.count' do
1491 1510 post :create, :project_id => 1,
1492 1511 :issue => {:tracker_id => 1,
1493 1512 :subject => 'This is the test_new issue',
1494 1513 :description => 'This is the description',
1495 1514 :priority_id => 5,
1496 1515 :custom_field_values => {field.id.to_s => ['', '2', '3']}}
1497 1516 end
1498 1517 assert_response 302
1499 1518 issue = Issue.first(:order => 'id DESC')
1500 1519 assert_equal ['2', '3'], issue.custom_field_value(field).sort
1501 1520 end
1502 1521
1503 1522 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1504 1523 field = IssueCustomField.find_by_name('Database')
1505 1524 field.update_attribute(:is_required, true)
1506 1525
1507 1526 @request.session[:user_id] = 2
1508 1527 assert_no_difference 'Issue.count' do
1509 1528 post :create, :project_id => 1,
1510 1529 :issue => {:tracker_id => 1,
1511 1530 :subject => 'This is the test_new issue',
1512 1531 :description => 'This is the description',
1513 1532 :priority_id => 5}
1514 1533 end
1515 1534 assert_response :success
1516 1535 assert_template 'new'
1517 1536 issue = assigns(:issue)
1518 1537 assert_not_nil issue
1519 1538 assert_error_tag :content => /Database can't be blank/
1520 1539 end
1521 1540
1522 1541 def test_post_create_with_watchers
1523 1542 @request.session[:user_id] = 2
1524 1543 ActionMailer::Base.deliveries.clear
1525 1544
1526 1545 assert_difference 'Watcher.count', 2 do
1527 1546 post :create, :project_id => 1,
1528 1547 :issue => {:tracker_id => 1,
1529 1548 :subject => 'This is a new issue with watchers',
1530 1549 :description => 'This is the description',
1531 1550 :priority_id => 5,
1532 1551 :watcher_user_ids => ['2', '3']}
1533 1552 end
1534 1553 issue = Issue.find_by_subject('This is a new issue with watchers')
1535 1554 assert_not_nil issue
1536 1555 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1537 1556
1538 1557 # Watchers added
1539 1558 assert_equal [2, 3], issue.watcher_user_ids.sort
1540 1559 assert issue.watched_by?(User.find(3))
1541 1560 # Watchers notified
1542 1561 mail = ActionMailer::Base.deliveries.last
1543 1562 assert_not_nil mail
1544 1563 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
1545 1564 end
1546 1565
1547 1566 def test_post_create_subissue
1548 1567 @request.session[:user_id] = 2
1549 1568
1550 1569 assert_difference 'Issue.count' do
1551 1570 post :create, :project_id => 1,
1552 1571 :issue => {:tracker_id => 1,
1553 1572 :subject => 'This is a child issue',
1554 1573 :parent_issue_id => 2}
1555 1574 end
1556 1575 issue = Issue.find_by_subject('This is a child issue')
1557 1576 assert_not_nil issue
1558 1577 assert_equal Issue.find(2), issue.parent
1559 1578 end
1560 1579
1561 1580 def test_post_create_subissue_with_non_numeric_parent_id
1562 1581 @request.session[:user_id] = 2
1563 1582
1564 1583 assert_difference 'Issue.count' do
1565 1584 post :create, :project_id => 1,
1566 1585 :issue => {:tracker_id => 1,
1567 1586 :subject => 'This is a child issue',
1568 1587 :parent_issue_id => 'ABC'}
1569 1588 end
1570 1589 issue = Issue.find_by_subject('This is a child issue')
1571 1590 assert_not_nil issue
1572 1591 assert_nil issue.parent
1573 1592 end
1574 1593
1575 1594 def test_post_create_private
1576 1595 @request.session[:user_id] = 2
1577 1596
1578 1597 assert_difference 'Issue.count' do
1579 1598 post :create, :project_id => 1,
1580 1599 :issue => {:tracker_id => 1,
1581 1600 :subject => 'This is a private issue',
1582 1601 :is_private => '1'}
1583 1602 end
1584 1603 issue = Issue.first(:order => 'id DESC')
1585 1604 assert issue.is_private?
1586 1605 end
1587 1606
1588 1607 def test_post_create_private_with_set_own_issues_private_permission
1589 1608 role = Role.find(1)
1590 1609 role.remove_permission! :set_issues_private
1591 1610 role.add_permission! :set_own_issues_private
1592 1611
1593 1612 @request.session[:user_id] = 2
1594 1613
1595 1614 assert_difference 'Issue.count' do
1596 1615 post :create, :project_id => 1,
1597 1616 :issue => {:tracker_id => 1,
1598 1617 :subject => 'This is a private issue',
1599 1618 :is_private => '1'}
1600 1619 end
1601 1620 issue = Issue.first(:order => 'id DESC')
1602 1621 assert issue.is_private?
1603 1622 end
1604 1623
1605 1624 def test_post_create_should_send_a_notification
1606 1625 ActionMailer::Base.deliveries.clear
1607 1626 @request.session[:user_id] = 2
1608 1627 assert_difference 'Issue.count' do
1609 1628 post :create, :project_id => 1,
1610 1629 :issue => {:tracker_id => 3,
1611 1630 :subject => 'This is the test_new issue',
1612 1631 :description => 'This is the description',
1613 1632 :priority_id => 5,
1614 1633 :estimated_hours => '',
1615 1634 :custom_field_values => {'2' => 'Value for field 2'}}
1616 1635 end
1617 1636 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1618 1637
1619 1638 assert_equal 1, ActionMailer::Base.deliveries.size
1620 1639 end
1621 1640
1622 1641 def test_post_create_should_preserve_fields_values_on_validation_failure
1623 1642 @request.session[:user_id] = 2
1624 1643 post :create, :project_id => 1,
1625 1644 :issue => {:tracker_id => 1,
1626 1645 # empty subject
1627 1646 :subject => '',
1628 1647 :description => 'This is a description',
1629 1648 :priority_id => 6,
1630 1649 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
1631 1650 assert_response :success
1632 1651 assert_template 'new'
1633 1652
1634 1653 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
1635 1654 :content => 'This is a description'
1636 1655 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1637 1656 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1638 1657 :value => '6' },
1639 1658 :content => 'High' }
1640 1659 # Custom fields
1641 1660 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
1642 1661 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1643 1662 :value => 'Oracle' },
1644 1663 :content => 'Oracle' }
1645 1664 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
1646 1665 :value => 'Value for field 2'}
1647 1666 end
1648 1667
1649 1668 def test_post_create_should_ignore_non_safe_attributes
1650 1669 @request.session[:user_id] = 2
1651 1670 assert_nothing_raised do
1652 1671 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
1653 1672 end
1654 1673 end
1655 1674
1656 1675 def test_post_create_with_attachment
1657 1676 set_tmp_attachments_directory
1658 1677 @request.session[:user_id] = 2
1659 1678
1660 1679 assert_difference 'Issue.count' do
1661 1680 assert_difference 'Attachment.count' do
1662 1681 post :create, :project_id => 1,
1663 1682 :issue => { :tracker_id => '1', :subject => 'With attachment' },
1664 1683 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1665 1684 end
1666 1685 end
1667 1686
1668 1687 issue = Issue.first(:order => 'id DESC')
1669 1688 attachment = Attachment.first(:order => 'id DESC')
1670 1689
1671 1690 assert_equal issue, attachment.container
1672 1691 assert_equal 2, attachment.author_id
1673 1692 assert_equal 'testfile.txt', attachment.filename
1674 1693 assert_equal 'text/plain', attachment.content_type
1675 1694 assert_equal 'test file', attachment.description
1676 1695 assert_equal 59, attachment.filesize
1677 1696 assert File.exists?(attachment.diskfile)
1678 1697 assert_equal 59, File.size(attachment.diskfile)
1679 1698 end
1680 1699
1681 1700 def test_post_create_with_failure_should_save_attachments
1682 1701 set_tmp_attachments_directory
1683 1702 @request.session[:user_id] = 2
1684 1703
1685 1704 assert_no_difference 'Issue.count' do
1686 1705 assert_difference 'Attachment.count' do
1687 1706 post :create, :project_id => 1,
1688 1707 :issue => { :tracker_id => '1', :subject => '' },
1689 1708 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1690 1709 assert_response :success
1691 1710 assert_template 'new'
1692 1711 end
1693 1712 end
1694 1713
1695 1714 attachment = Attachment.first(:order => 'id DESC')
1696 1715 assert_equal 'testfile.txt', attachment.filename
1697 1716 assert File.exists?(attachment.diskfile)
1698 1717 assert_nil attachment.container
1699 1718
1700 1719 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
1701 1720 assert_tag 'span', :content => /testfile.txt/
1702 1721 end
1703 1722
1704 1723 def test_post_create_with_failure_should_keep_saved_attachments
1705 1724 set_tmp_attachments_directory
1706 1725 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
1707 1726 @request.session[:user_id] = 2
1708 1727
1709 1728 assert_no_difference 'Issue.count' do
1710 1729 assert_no_difference 'Attachment.count' do
1711 1730 post :create, :project_id => 1,
1712 1731 :issue => { :tracker_id => '1', :subject => '' },
1713 1732 :attachments => {'p0' => {'token' => attachment.token}}
1714 1733 assert_response :success
1715 1734 assert_template 'new'
1716 1735 end
1717 1736 end
1718 1737
1719 1738 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
1720 1739 assert_tag 'span', :content => /testfile.txt/
1721 1740 end
1722 1741
1723 1742 def test_post_create_should_attach_saved_attachments
1724 1743 set_tmp_attachments_directory
1725 1744 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
1726 1745 @request.session[:user_id] = 2
1727 1746
1728 1747 assert_difference 'Issue.count' do
1729 1748 assert_no_difference 'Attachment.count' do
1730 1749 post :create, :project_id => 1,
1731 1750 :issue => { :tracker_id => '1', :subject => 'Saved attachments' },
1732 1751 :attachments => {'p0' => {'token' => attachment.token}}
1733 1752 assert_response 302
1734 1753 end
1735 1754 end
1736 1755
1737 1756 issue = Issue.first(:order => 'id DESC')
1738 1757 assert_equal 1, issue.attachments.count
1739 1758
1740 1759 attachment.reload
1741 1760 assert_equal issue, attachment.container
1742 1761 end
1743 1762
1744 1763 context "without workflow privilege" do
1745 1764 setup do
1746 1765 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1747 1766 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1748 1767 end
1749 1768
1750 1769 context "#new" do
1751 1770 should "propose default status only" do
1752 1771 get :new, :project_id => 1
1753 1772 assert_response :success
1754 1773 assert_template 'new'
1755 1774 assert_tag :tag => 'select',
1756 1775 :attributes => {:name => 'issue[status_id]'},
1757 1776 :children => {:count => 1},
1758 1777 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
1759 1778 end
1760 1779
1761 1780 should "accept default status" do
1762 1781 assert_difference 'Issue.count' do
1763 1782 post :create, :project_id => 1,
1764 1783 :issue => {:tracker_id => 1,
1765 1784 :subject => 'This is an issue',
1766 1785 :status_id => 1}
1767 1786 end
1768 1787 issue = Issue.last(:order => 'id')
1769 1788 assert_equal IssueStatus.default, issue.status
1770 1789 end
1771 1790
1772 1791 should "ignore unauthorized status" do
1773 1792 assert_difference 'Issue.count' do
1774 1793 post :create, :project_id => 1,
1775 1794 :issue => {:tracker_id => 1,
1776 1795 :subject => 'This is an issue',
1777 1796 :status_id => 3}
1778 1797 end
1779 1798 issue = Issue.last(:order => 'id')
1780 1799 assert_equal IssueStatus.default, issue.status
1781 1800 end
1782 1801 end
1783 1802
1784 1803 context "#update" do
1785 1804 should "ignore status change" do
1786 1805 assert_difference 'Journal.count' do
1787 1806 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1788 1807 end
1789 1808 assert_equal 1, Issue.find(1).status_id
1790 1809 end
1791 1810
1792 1811 should "ignore attributes changes" do
1793 1812 assert_difference 'Journal.count' do
1794 1813 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1795 1814 end
1796 1815 issue = Issue.find(1)
1797 1816 assert_equal "Can't print recipes", issue.subject
1798 1817 assert_nil issue.assigned_to
1799 1818 end
1800 1819 end
1801 1820 end
1802 1821
1803 1822 context "with workflow privilege" do
1804 1823 setup do
1805 1824 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1806 1825 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
1807 1826 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
1808 1827 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1809 1828 end
1810 1829
1811 1830 context "#update" do
1812 1831 should "accept authorized status" do
1813 1832 assert_difference 'Journal.count' do
1814 1833 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1815 1834 end
1816 1835 assert_equal 3, Issue.find(1).status_id
1817 1836 end
1818 1837
1819 1838 should "ignore unauthorized status" do
1820 1839 assert_difference 'Journal.count' do
1821 1840 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1822 1841 end
1823 1842 assert_equal 1, Issue.find(1).status_id
1824 1843 end
1825 1844
1826 1845 should "accept authorized attributes changes" do
1827 1846 assert_difference 'Journal.count' do
1828 1847 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
1829 1848 end
1830 1849 issue = Issue.find(1)
1831 1850 assert_equal 2, issue.assigned_to_id
1832 1851 end
1833 1852
1834 1853 should "ignore unauthorized attributes changes" do
1835 1854 assert_difference 'Journal.count' do
1836 1855 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
1837 1856 end
1838 1857 issue = Issue.find(1)
1839 1858 assert_equal "Can't print recipes", issue.subject
1840 1859 end
1841 1860 end
1842 1861
1843 1862 context "and :edit_issues permission" do
1844 1863 setup do
1845 1864 Role.anonymous.add_permission! :add_issues, :edit_issues
1846 1865 end
1847 1866
1848 1867 should "accept authorized status" do
1849 1868 assert_difference 'Journal.count' do
1850 1869 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1851 1870 end
1852 1871 assert_equal 3, Issue.find(1).status_id
1853 1872 end
1854 1873
1855 1874 should "ignore unauthorized status" do
1856 1875 assert_difference 'Journal.count' do
1857 1876 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1858 1877 end
1859 1878 assert_equal 1, Issue.find(1).status_id
1860 1879 end
1861 1880
1862 1881 should "accept authorized attributes changes" do
1863 1882 assert_difference 'Journal.count' do
1864 1883 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1865 1884 end
1866 1885 issue = Issue.find(1)
1867 1886 assert_equal "changed", issue.subject
1868 1887 assert_equal 2, issue.assigned_to_id
1869 1888 end
1870 1889 end
1871 1890 end
1872 1891
1873 1892 def test_new_as_copy
1874 1893 @request.session[:user_id] = 2
1875 1894 get :new, :project_id => 1, :copy_from => 1
1876 1895
1877 1896 assert_response :success
1878 1897 assert_template 'new'
1879 1898
1880 1899 assert_not_nil assigns(:issue)
1881 1900 orig = Issue.find(1)
1882 1901 assert_equal 1, assigns(:issue).project_id
1883 1902 assert_equal orig.subject, assigns(:issue).subject
1884 1903 assert assigns(:issue).copy?
1885 1904
1886 1905 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
1887 1906 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
1888 1907 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1889 1908 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'}
1890 1909 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1891 1910 :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'}
1892 1911 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
1893 1912 end
1894 1913
1895 1914 def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
1896 1915 @request.session[:user_id] = 2
1897 1916 issue = Issue.find(3)
1898 1917 assert issue.attachments.count > 0
1899 1918 get :new, :project_id => 1, :copy_from => 3
1900 1919
1901 1920 assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
1902 1921 end
1903 1922
1904 1923 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
1905 1924 @request.session[:user_id] = 2
1906 1925 issue = Issue.find(3)
1907 1926 issue.attachments.delete_all
1908 1927 get :new, :project_id => 1, :copy_from => 3
1909 1928
1910 1929 assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
1911 1930 end
1912 1931
1913 1932 def test_new_as_copy_with_invalid_issue_should_respond_with_404
1914 1933 @request.session[:user_id] = 2
1915 1934 get :new, :project_id => 1, :copy_from => 99999
1916 1935 assert_response 404
1917 1936 end
1918 1937
1919 1938 def test_create_as_copy_on_different_project
1920 1939 @request.session[:user_id] = 2
1921 1940 assert_difference 'Issue.count' do
1922 1941 post :create, :project_id => 1, :copy_from => 1,
1923 1942 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
1924 1943
1925 1944 assert_not_nil assigns(:issue)
1926 1945 assert assigns(:issue).copy?
1927 1946 end
1928 1947 issue = Issue.first(:order => 'id DESC')
1929 1948 assert_redirected_to "/issues/#{issue.id}"
1930 1949
1931 1950 assert_equal 2, issue.project_id
1932 1951 assert_equal 3, issue.tracker_id
1933 1952 assert_equal 'Copy', issue.subject
1934 1953 end
1935 1954
1936 1955 def test_create_as_copy_should_copy_attachments
1937 1956 @request.session[:user_id] = 2
1938 1957 issue = Issue.find(3)
1939 1958 count = issue.attachments.count
1940 1959 assert count > 0
1941 1960
1942 1961 assert_difference 'Issue.count' do
1943 1962 assert_difference 'Attachment.count', count do
1944 1963 assert_no_difference 'Journal.count' do
1945 1964 post :create, :project_id => 1, :copy_from => 3,
1946 1965 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
1947 1966 :copy_attachments => '1'
1948 1967 end
1949 1968 end
1950 1969 end
1951 1970 copy = Issue.first(:order => 'id DESC')
1952 1971 assert_equal count, copy.attachments.count
1953 1972 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
1954 1973 end
1955 1974
1956 1975 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
1957 1976 @request.session[:user_id] = 2
1958 1977 issue = Issue.find(3)
1959 1978 count = issue.attachments.count
1960 1979 assert count > 0
1961 1980
1962 1981 assert_difference 'Issue.count' do
1963 1982 assert_no_difference 'Attachment.count' do
1964 1983 assert_no_difference 'Journal.count' do
1965 1984 post :create, :project_id => 1, :copy_from => 3,
1966 1985 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}
1967 1986 end
1968 1987 end
1969 1988 end
1970 1989 copy = Issue.first(:order => 'id DESC')
1971 1990 assert_equal 0, copy.attachments.count
1972 1991 end
1973 1992
1974 1993 def test_create_as_copy_with_attachments_should_add_new_files
1975 1994 @request.session[:user_id] = 2
1976 1995 issue = Issue.find(3)
1977 1996 count = issue.attachments.count
1978 1997 assert count > 0
1979 1998
1980 1999 assert_difference 'Issue.count' do
1981 2000 assert_difference 'Attachment.count', count + 1 do
1982 2001 assert_no_difference 'Journal.count' do
1983 2002 post :create, :project_id => 1, :copy_from => 3,
1984 2003 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
1985 2004 :copy_attachments => '1',
1986 2005 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1987 2006 end
1988 2007 end
1989 2008 end
1990 2009 copy = Issue.first(:order => 'id DESC')
1991 2010 assert_equal count + 1, copy.attachments.count
1992 2011 end
1993 2012
1994 2013 def test_create_as_copy_with_failure
1995 2014 @request.session[:user_id] = 2
1996 2015 post :create, :project_id => 1, :copy_from => 1,
1997 2016 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
1998 2017
1999 2018 assert_response :success
2000 2019 assert_template 'new'
2001 2020
2002 2021 assert_not_nil assigns(:issue)
2003 2022 assert assigns(:issue).copy?
2004 2023
2005 2024 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
2006 2025 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
2007 2026 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2008 2027 :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'}
2009 2028 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2010 2029 :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'}
2011 2030 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
2012 2031 end
2013 2032
2014 2033 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
2015 2034 @request.session[:user_id] = 2
2016 2035 assert !User.find(2).member_of?(Project.find(4))
2017 2036
2018 2037 assert_difference 'Issue.count' do
2019 2038 post :create, :project_id => 1, :copy_from => 1,
2020 2039 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2021 2040 end
2022 2041 issue = Issue.first(:order => 'id DESC')
2023 2042 assert_equal 1, issue.project_id
2024 2043 end
2025 2044
2026 2045 def test_get_edit
2027 2046 @request.session[:user_id] = 2
2028 2047 get :edit, :id => 1
2029 2048 assert_response :success
2030 2049 assert_template 'edit'
2031 2050 assert_not_nil assigns(:issue)
2032 2051 assert_equal Issue.find(1), assigns(:issue)
2033 2052
2034 2053 # Be sure we don't display inactive IssuePriorities
2035 2054 assert ! IssuePriority.find(15).active?
2036 2055 assert_no_tag :option, :attributes => {:value => '15'},
2037 2056 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2038 2057 end
2039 2058
2040 2059 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
2041 2060 @request.session[:user_id] = 2
2042 2061 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
2043 2062
2044 2063 get :edit, :id => 1
2045 2064 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2046 2065 end
2047 2066
2048 2067 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
2049 2068 @request.session[:user_id] = 2
2050 2069 Role.find_by_name('Manager').remove_permission! :log_time
2051 2070
2052 2071 get :edit, :id => 1
2053 2072 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2054 2073 end
2055 2074
2056 2075 def test_get_edit_with_params
2057 2076 @request.session[:user_id] = 2
2058 2077 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
2059 2078 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
2060 2079 assert_response :success
2061 2080 assert_template 'edit'
2062 2081
2063 2082 issue = assigns(:issue)
2064 2083 assert_not_nil issue
2065 2084
2066 2085 assert_equal 5, issue.status_id
2067 2086 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
2068 2087 :child => { :tag => 'option',
2069 2088 :content => 'Closed',
2070 2089 :attributes => { :selected => 'selected' } }
2071 2090
2072 2091 assert_equal 7, issue.priority_id
2073 2092 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
2074 2093 :child => { :tag => 'option',
2075 2094 :content => 'Urgent',
2076 2095 :attributes => { :selected => 'selected' } }
2077 2096
2078 2097 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
2079 2098 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
2080 2099 :child => { :tag => 'option',
2081 2100 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
2082 2101 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
2083 2102 end
2084 2103
2085 2104 def test_get_edit_with_multi_custom_field
2086 2105 field = CustomField.find(1)
2087 2106 field.update_attribute :multiple, true
2088 2107 issue = Issue.find(1)
2089 2108 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2090 2109 issue.save!
2091 2110
2092 2111 @request.session[:user_id] = 2
2093 2112 get :edit, :id => 1
2094 2113 assert_response :success
2095 2114 assert_template 'edit'
2096 2115
2097 2116 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'}
2098 2117 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2099 2118 :child => {:tag => 'option', :attributes => {:value => 'MySQL', :selected => 'selected'}}
2100 2119 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2101 2120 :child => {:tag => 'option', :attributes => {:value => 'PostgreSQL', :selected => nil}}
2102 2121 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2103 2122 :child => {:tag => 'option', :attributes => {:value => 'Oracle', :selected => 'selected'}}
2104 2123 end
2105 2124
2106 2125 def test_update_edit_form
2107 2126 @request.session[:user_id] = 2
2108 2127 xhr :put, :new, :project_id => 1,
2109 2128 :id => 1,
2110 2129 :issue => {:tracker_id => 2,
2111 2130 :subject => 'This is the test_new issue',
2112 2131 :description => 'This is the description',
2113 2132 :priority_id => 5}
2114 2133 assert_response :success
2115 2134 assert_template 'attributes'
2116 2135
2117 2136 issue = assigns(:issue)
2118 2137 assert_kind_of Issue, issue
2119 2138 assert_equal 1, issue.id
2120 2139 assert_equal 1, issue.project_id
2121 2140 assert_equal 2, issue.tracker_id
2122 2141 assert_equal 'This is the test_new issue', issue.subject
2123 2142 end
2124 2143
2125 2144 def test_update_edit_form_with_project_change
2126 2145 @request.session[:user_id] = 2
2127 2146 xhr :put, :new, :project_id => 1,
2128 2147 :id => 1,
2129 2148 :project_change => '1',
2130 2149 :issue => {:project_id => 2,
2131 2150 :tracker_id => 2,
2132 2151 :subject => 'This is the test_new issue',
2133 2152 :description => 'This is the description',
2134 2153 :priority_id => 5}
2135 2154 assert_response :success
2136 2155 assert_template 'form'
2137 2156
2138 2157 issue = assigns(:issue)
2139 2158 assert_kind_of Issue, issue
2140 2159 assert_equal 1, issue.id
2141 2160 assert_equal 2, issue.project_id
2142 2161 assert_equal 2, issue.tracker_id
2143 2162 assert_equal 'This is the test_new issue', issue.subject
2144 2163 end
2145 2164
2146 2165 def test_put_update_without_custom_fields_param
2147 2166 @request.session[:user_id] = 2
2148 2167 ActionMailer::Base.deliveries.clear
2149 2168
2150 2169 issue = Issue.find(1)
2151 2170 assert_equal '125', issue.custom_value_for(2).value
2152 2171 old_subject = issue.subject
2153 2172 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2154 2173
2155 2174 assert_difference('Journal.count') do
2156 2175 assert_difference('JournalDetail.count', 2) do
2157 2176 put :update, :id => 1, :issue => {:subject => new_subject,
2158 2177 :priority_id => '6',
2159 2178 :category_id => '1' # no change
2160 2179 }
2161 2180 end
2162 2181 end
2163 2182 assert_redirected_to :action => 'show', :id => '1'
2164 2183 issue.reload
2165 2184 assert_equal new_subject, issue.subject
2166 2185 # Make sure custom fields were not cleared
2167 2186 assert_equal '125', issue.custom_value_for(2).value
2168 2187
2169 2188 mail = ActionMailer::Base.deliveries.last
2170 2189 assert_not_nil mail
2171 2190 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2172 2191 assert_mail_body_match "Subject changed from #{old_subject} to #{new_subject}", mail
2173 2192 end
2174 2193
2175 2194 def test_put_update_with_project_change
2176 2195 @request.session[:user_id] = 2
2177 2196 ActionMailer::Base.deliveries.clear
2178 2197
2179 2198 assert_difference('Journal.count') do
2180 2199 assert_difference('JournalDetail.count', 3) do
2181 2200 put :update, :id => 1, :issue => {:project_id => '2',
2182 2201 :tracker_id => '1', # no change
2183 2202 :priority_id => '6',
2184 2203 :category_id => '3'
2185 2204 }
2186 2205 end
2187 2206 end
2188 2207 assert_redirected_to :action => 'show', :id => '1'
2189 2208 issue = Issue.find(1)
2190 2209 assert_equal 2, issue.project_id
2191 2210 assert_equal 1, issue.tracker_id
2192 2211 assert_equal 6, issue.priority_id
2193 2212 assert_equal 3, issue.category_id
2194 2213
2195 2214 mail = ActionMailer::Base.deliveries.last
2196 2215 assert_not_nil mail
2197 2216 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2198 2217 assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail
2199 2218 end
2200 2219
2201 2220 def test_put_update_with_tracker_change
2202 2221 @request.session[:user_id] = 2
2203 2222 ActionMailer::Base.deliveries.clear
2204 2223
2205 2224 assert_difference('Journal.count') do
2206 2225 assert_difference('JournalDetail.count', 2) do
2207 2226 put :update, :id => 1, :issue => {:project_id => '1',
2208 2227 :tracker_id => '2',
2209 2228 :priority_id => '6'
2210 2229 }
2211 2230 end
2212 2231 end
2213 2232 assert_redirected_to :action => 'show', :id => '1'
2214 2233 issue = Issue.find(1)
2215 2234 assert_equal 1, issue.project_id
2216 2235 assert_equal 2, issue.tracker_id
2217 2236 assert_equal 6, issue.priority_id
2218 2237 assert_equal 1, issue.category_id
2219 2238
2220 2239 mail = ActionMailer::Base.deliveries.last
2221 2240 assert_not_nil mail
2222 2241 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2223 2242 assert_mail_body_match "Tracker changed from Bug to Feature request", mail
2224 2243 end
2225 2244
2226 2245 def test_put_update_with_custom_field_change
2227 2246 @request.session[:user_id] = 2
2228 2247 issue = Issue.find(1)
2229 2248 assert_equal '125', issue.custom_value_for(2).value
2230 2249
2231 2250 assert_difference('Journal.count') do
2232 2251 assert_difference('JournalDetail.count', 3) do
2233 2252 put :update, :id => 1, :issue => {:subject => 'Custom field change',
2234 2253 :priority_id => '6',
2235 2254 :category_id => '1', # no change
2236 2255 :custom_field_values => { '2' => 'New custom value' }
2237 2256 }
2238 2257 end
2239 2258 end
2240 2259 assert_redirected_to :action => 'show', :id => '1'
2241 2260 issue.reload
2242 2261 assert_equal 'New custom value', issue.custom_value_for(2).value
2243 2262
2244 2263 mail = ActionMailer::Base.deliveries.last
2245 2264 assert_not_nil mail
2246 2265 assert_mail_body_match "Searchable field changed from 125 to New custom value", mail
2247 2266 end
2248 2267
2249 2268 def test_put_update_with_multi_custom_field_change
2250 2269 field = CustomField.find(1)
2251 2270 field.update_attribute :multiple, true
2252 2271 issue = Issue.find(1)
2253 2272 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2254 2273 issue.save!
2255 2274
2256 2275 @request.session[:user_id] = 2
2257 2276 assert_difference('Journal.count') do
2258 2277 assert_difference('JournalDetail.count', 3) do
2259 2278 put :update, :id => 1,
2260 2279 :issue => {
2261 2280 :subject => 'Custom field change',
2262 2281 :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] }
2263 2282 }
2264 2283 end
2265 2284 end
2266 2285 assert_redirected_to :action => 'show', :id => '1'
2267 2286 assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort
2268 2287 end
2269 2288
2270 2289 def test_put_update_with_status_and_assignee_change
2271 2290 issue = Issue.find(1)
2272 2291 assert_equal 1, issue.status_id
2273 2292 @request.session[:user_id] = 2
2274 2293 assert_difference('TimeEntry.count', 0) do
2275 2294 put :update,
2276 2295 :id => 1,
2277 2296 :issue => { :status_id => 2, :assigned_to_id => 3 },
2278 2297 :notes => 'Assigned to dlopper',
2279 2298 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
2280 2299 end
2281 2300 assert_redirected_to :action => 'show', :id => '1'
2282 2301 issue.reload
2283 2302 assert_equal 2, issue.status_id
2284 2303 j = Journal.find(:first, :order => 'id DESC')
2285 2304 assert_equal 'Assigned to dlopper', j.notes
2286 2305 assert_equal 2, j.details.size
2287 2306
2288 2307 mail = ActionMailer::Base.deliveries.last
2289 2308 assert_mail_body_match "Status changed from New to Assigned", mail
2290 2309 # subject should contain the new status
2291 2310 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
2292 2311 end
2293 2312
2294 2313 def test_put_update_with_note_only
2295 2314 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
2296 2315 # anonymous user
2297 2316 put :update,
2298 2317 :id => 1,
2299 2318 :notes => notes
2300 2319 assert_redirected_to :action => 'show', :id => '1'
2301 2320 j = Journal.find(:first, :order => 'id DESC')
2302 2321 assert_equal notes, j.notes
2303 2322 assert_equal 0, j.details.size
2304 2323 assert_equal User.anonymous, j.user
2305 2324
2306 2325 mail = ActionMailer::Base.deliveries.last
2307 2326 assert_mail_body_match notes, mail
2308 2327 end
2309 2328
2310 2329 def test_put_update_with_note_and_spent_time
2311 2330 @request.session[:user_id] = 2
2312 2331 spent_hours_before = Issue.find(1).spent_hours
2313 2332 assert_difference('TimeEntry.count') do
2314 2333 put :update,
2315 2334 :id => 1,
2316 2335 :notes => '2.5 hours added',
2317 2336 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
2318 2337 end
2319 2338 assert_redirected_to :action => 'show', :id => '1'
2320 2339
2321 2340 issue = Issue.find(1)
2322 2341
2323 2342 j = Journal.find(:first, :order => 'id DESC')
2324 2343 assert_equal '2.5 hours added', j.notes
2325 2344 assert_equal 0, j.details.size
2326 2345
2327 2346 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
2328 2347 assert_not_nil t
2329 2348 assert_equal 2.5, t.hours
2330 2349 assert_equal spent_hours_before + 2.5, issue.spent_hours
2331 2350 end
2332 2351
2333 2352 def test_put_update_with_attachment_only
2334 2353 set_tmp_attachments_directory
2335 2354
2336 2355 # Delete all fixtured journals, a race condition can occur causing the wrong
2337 2356 # journal to get fetched in the next find.
2338 2357 Journal.delete_all
2339 2358
2340 2359 # anonymous user
2341 2360 assert_difference 'Attachment.count' do
2342 2361 put :update, :id => 1,
2343 2362 :notes => '',
2344 2363 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2345 2364 end
2346 2365
2347 2366 assert_redirected_to :action => 'show', :id => '1'
2348 2367 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
2349 2368 assert j.notes.blank?
2350 2369 assert_equal 1, j.details.size
2351 2370 assert_equal 'testfile.txt', j.details.first.value
2352 2371 assert_equal User.anonymous, j.user
2353 2372
2354 2373 attachment = Attachment.first(:order => 'id DESC')
2355 2374 assert_equal Issue.find(1), attachment.container
2356 2375 assert_equal User.anonymous, attachment.author
2357 2376 assert_equal 'testfile.txt', attachment.filename
2358 2377 assert_equal 'text/plain', attachment.content_type
2359 2378 assert_equal 'test file', attachment.description
2360 2379 assert_equal 59, attachment.filesize
2361 2380 assert File.exists?(attachment.diskfile)
2362 2381 assert_equal 59, File.size(attachment.diskfile)
2363 2382
2364 2383 mail = ActionMailer::Base.deliveries.last
2365 2384 assert_mail_body_match 'testfile.txt', mail
2366 2385 end
2367 2386
2368 2387 def test_put_update_with_failure_should_save_attachments
2369 2388 set_tmp_attachments_directory
2370 2389 @request.session[:user_id] = 2
2371 2390
2372 2391 assert_no_difference 'Journal.count' do
2373 2392 assert_difference 'Attachment.count' do
2374 2393 put :update, :id => 1,
2375 2394 :issue => { :subject => '' },
2376 2395 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2377 2396 assert_response :success
2378 2397 assert_template 'edit'
2379 2398 end
2380 2399 end
2381 2400
2382 2401 attachment = Attachment.first(:order => 'id DESC')
2383 2402 assert_equal 'testfile.txt', attachment.filename
2384 2403 assert File.exists?(attachment.diskfile)
2385 2404 assert_nil attachment.container
2386 2405
2387 2406 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2388 2407 assert_tag 'span', :content => /testfile.txt/
2389 2408 end
2390 2409
2391 2410 def test_put_update_with_failure_should_keep_saved_attachments
2392 2411 set_tmp_attachments_directory
2393 2412 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2394 2413 @request.session[:user_id] = 2
2395 2414
2396 2415 assert_no_difference 'Journal.count' do
2397 2416 assert_no_difference 'Attachment.count' do
2398 2417 put :update, :id => 1,
2399 2418 :issue => { :subject => '' },
2400 2419 :attachments => {'p0' => {'token' => attachment.token}}
2401 2420 assert_response :success
2402 2421 assert_template 'edit'
2403 2422 end
2404 2423 end
2405 2424
2406 2425 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2407 2426 assert_tag 'span', :content => /testfile.txt/
2408 2427 end
2409 2428
2410 2429 def test_put_update_should_attach_saved_attachments
2411 2430 set_tmp_attachments_directory
2412 2431 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2413 2432 @request.session[:user_id] = 2
2414 2433
2415 2434 assert_difference 'Journal.count' do
2416 2435 assert_difference 'JournalDetail.count' do
2417 2436 assert_no_difference 'Attachment.count' do
2418 2437 put :update, :id => 1,
2419 2438 :notes => 'Attachment added',
2420 2439 :attachments => {'p0' => {'token' => attachment.token}}
2421 2440 assert_redirected_to '/issues/1'
2422 2441 end
2423 2442 end
2424 2443 end
2425 2444
2426 2445 attachment.reload
2427 2446 assert_equal Issue.find(1), attachment.container
2428 2447
2429 2448 journal = Journal.first(:order => 'id DESC')
2430 2449 assert_equal 1, journal.details.size
2431 2450 assert_equal 'testfile.txt', journal.details.first.value
2432 2451 end
2433 2452
2434 2453 def test_put_update_with_attachment_that_fails_to_save
2435 2454 set_tmp_attachments_directory
2436 2455
2437 2456 # Delete all fixtured journals, a race condition can occur causing the wrong
2438 2457 # journal to get fetched in the next find.
2439 2458 Journal.delete_all
2440 2459
2441 2460 # Mock out the unsaved attachment
2442 2461 Attachment.any_instance.stubs(:create).returns(Attachment.new)
2443 2462
2444 2463 # anonymous user
2445 2464 put :update,
2446 2465 :id => 1,
2447 2466 :notes => '',
2448 2467 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
2449 2468 assert_redirected_to :action => 'show', :id => '1'
2450 2469 assert_equal '1 file(s) could not be saved.', flash[:warning]
2451 2470 end
2452 2471
2453 2472 def test_put_update_with_no_change
2454 2473 issue = Issue.find(1)
2455 2474 issue.journals.clear
2456 2475 ActionMailer::Base.deliveries.clear
2457 2476
2458 2477 put :update,
2459 2478 :id => 1,
2460 2479 :notes => ''
2461 2480 assert_redirected_to :action => 'show', :id => '1'
2462 2481
2463 2482 issue.reload
2464 2483 assert issue.journals.empty?
2465 2484 # No email should be sent
2466 2485 assert ActionMailer::Base.deliveries.empty?
2467 2486 end
2468 2487
2469 2488 def test_put_update_should_send_a_notification
2470 2489 @request.session[:user_id] = 2
2471 2490 ActionMailer::Base.deliveries.clear
2472 2491 issue = Issue.find(1)
2473 2492 old_subject = issue.subject
2474 2493 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2475 2494
2476 2495 put :update, :id => 1, :issue => {:subject => new_subject,
2477 2496 :priority_id => '6',
2478 2497 :category_id => '1' # no change
2479 2498 }
2480 2499 assert_equal 1, ActionMailer::Base.deliveries.size
2481 2500 end
2482 2501
2483 2502 def test_put_update_with_invalid_spent_time_hours_only
2484 2503 @request.session[:user_id] = 2
2485 2504 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2486 2505
2487 2506 assert_no_difference('Journal.count') do
2488 2507 put :update,
2489 2508 :id => 1,
2490 2509 :notes => notes,
2491 2510 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
2492 2511 end
2493 2512 assert_response :success
2494 2513 assert_template 'edit'
2495 2514
2496 2515 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2497 2516 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2498 2517 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
2499 2518 end
2500 2519
2501 2520 def test_put_update_with_invalid_spent_time_comments_only
2502 2521 @request.session[:user_id] = 2
2503 2522 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2504 2523
2505 2524 assert_no_difference('Journal.count') do
2506 2525 put :update,
2507 2526 :id => 1,
2508 2527 :notes => notes,
2509 2528 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
2510 2529 end
2511 2530 assert_response :success
2512 2531 assert_template 'edit'
2513 2532
2514 2533 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2515 2534 assert_error_tag :descendant => {:content => /Hours can't be blank/}
2516 2535 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2517 2536 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
2518 2537 end
2519 2538
2520 2539 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
2521 2540 issue = Issue.find(2)
2522 2541 @request.session[:user_id] = 2
2523 2542
2524 2543 put :update,
2525 2544 :id => issue.id,
2526 2545 :issue => {
2527 2546 :fixed_version_id => 4
2528 2547 }
2529 2548
2530 2549 assert_response :redirect
2531 2550 issue.reload
2532 2551 assert_equal 4, issue.fixed_version_id
2533 2552 assert_not_equal issue.project_id, issue.fixed_version.project_id
2534 2553 end
2535 2554
2536 2555 def test_put_update_should_redirect_back_using_the_back_url_parameter
2537 2556 issue = Issue.find(2)
2538 2557 @request.session[:user_id] = 2
2539 2558
2540 2559 put :update,
2541 2560 :id => issue.id,
2542 2561 :issue => {
2543 2562 :fixed_version_id => 4
2544 2563 },
2545 2564 :back_url => '/issues'
2546 2565
2547 2566 assert_response :redirect
2548 2567 assert_redirected_to '/issues'
2549 2568 end
2550 2569
2551 2570 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
2552 2571 issue = Issue.find(2)
2553 2572 @request.session[:user_id] = 2
2554 2573
2555 2574 put :update,
2556 2575 :id => issue.id,
2557 2576 :issue => {
2558 2577 :fixed_version_id => 4
2559 2578 },
2560 2579 :back_url => 'http://google.com'
2561 2580
2562 2581 assert_response :redirect
2563 2582 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
2564 2583 end
2565 2584
2566 2585 def test_get_bulk_edit
2567 2586 @request.session[:user_id] = 2
2568 2587 get :bulk_edit, :ids => [1, 2]
2569 2588 assert_response :success
2570 2589 assert_template 'bulk_edit'
2571 2590
2572 2591 assert_tag :select, :attributes => {:name => 'issue[project_id]'}
2573 2592 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2574 2593
2575 2594 # Project specific custom field, date type
2576 2595 field = CustomField.find(9)
2577 2596 assert !field.is_for_all?
2578 2597 assert_equal 'date', field.field_format
2579 2598 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2580 2599
2581 2600 # System wide custom field
2582 2601 assert CustomField.find(1).is_for_all?
2583 2602 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
2584 2603
2585 2604 # Be sure we don't display inactive IssuePriorities
2586 2605 assert ! IssuePriority.find(15).active?
2587 2606 assert_no_tag :option, :attributes => {:value => '15'},
2588 2607 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2589 2608 end
2590 2609
2591 2610 def test_get_bulk_edit_on_different_projects
2592 2611 @request.session[:user_id] = 2
2593 2612 get :bulk_edit, :ids => [1, 2, 6]
2594 2613 assert_response :success
2595 2614 assert_template 'bulk_edit'
2596 2615
2597 2616 # Can not set issues from different projects as children of an issue
2598 2617 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2599 2618
2600 2619 # Project specific custom field, date type
2601 2620 field = CustomField.find(9)
2602 2621 assert !field.is_for_all?
2603 2622 assert !field.project_ids.include?(Issue.find(6).project_id)
2604 2623 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2605 2624 end
2606 2625
2607 2626 def test_get_bulk_edit_with_user_custom_field
2608 2627 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
2609 2628
2610 2629 @request.session[:user_id] = 2
2611 2630 get :bulk_edit, :ids => [1, 2]
2612 2631 assert_response :success
2613 2632 assert_template 'bulk_edit'
2614 2633
2615 2634 assert_tag :select,
2616 2635 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2617 2636 :children => {
2618 2637 :only => {:tag => 'option'},
2619 2638 :count => Project.find(1).users.count + 1
2620 2639 }
2621 2640 end
2622 2641
2623 2642 def test_get_bulk_edit_with_version_custom_field
2624 2643 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
2625 2644
2626 2645 @request.session[:user_id] = 2
2627 2646 get :bulk_edit, :ids => [1, 2]
2628 2647 assert_response :success
2629 2648 assert_template 'bulk_edit'
2630 2649
2631 2650 assert_tag :select,
2632 2651 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2633 2652 :children => {
2634 2653 :only => {:tag => 'option'},
2635 2654 :count => Project.find(1).shared_versions.count + 1
2636 2655 }
2637 2656 end
2638 2657
2639 2658 def test_get_bulk_edit_with_multi_custom_field
2640 2659 field = CustomField.find(1)
2641 2660 field.update_attribute :multiple, true
2642 2661
2643 2662 @request.session[:user_id] = 2
2644 2663 get :bulk_edit, :ids => [1, 2]
2645 2664 assert_response :success
2646 2665 assert_template 'bulk_edit'
2647 2666
2648 2667 assert_tag :select,
2649 2668 :attributes => {:name => "issue[custom_field_values][1][]"},
2650 2669 :children => {
2651 2670 :only => {:tag => 'option'},
2652 2671 :count => 3
2653 2672 }
2654 2673 end
2655 2674
2656 2675 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
2657 2676 Workflow.delete_all
2658 2677 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1)
2659 2678 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
2660 2679 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
2661 2680 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
2662 2681 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
2663 2682 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
2664 2683 @request.session[:user_id] = 2
2665 2684 get :bulk_edit, :ids => [1, 2]
2666 2685
2667 2686 assert_response :success
2668 2687 statuses = assigns(:available_statuses)
2669 2688 assert_not_nil statuses
2670 2689 assert_equal [1, 3], statuses.map(&:id).sort
2671 2690
2672 2691 assert_tag 'select', :attributes => {:name => 'issue[status_id]'},
2673 2692 :children => {:count => 3} # 2 statuses + "no change" option
2674 2693 end
2675 2694
2676 2695 def test_bulk_edit_should_propose_target_project_open_shared_versions
2677 2696 @request.session[:user_id] = 2
2678 2697 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
2679 2698 assert_response :success
2680 2699 assert_template 'bulk_edit'
2681 2700 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort
2682 2701 assert_tag 'select',
2683 2702 :attributes => {:name => 'issue[fixed_version_id]'},
2684 2703 :descendant => {:tag => 'option', :content => '2.0'}
2685 2704 end
2686 2705
2687 2706 def test_bulk_edit_should_propose_target_project_categories
2688 2707 @request.session[:user_id] = 2
2689 2708 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
2690 2709 assert_response :success
2691 2710 assert_template 'bulk_edit'
2692 2711 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort
2693 2712 assert_tag 'select',
2694 2713 :attributes => {:name => 'issue[category_id]'},
2695 2714 :descendant => {:tag => 'option', :content => 'Recipes'}
2696 2715 end
2697 2716
2698 2717 def test_bulk_update
2699 2718 @request.session[:user_id] = 2
2700 2719 # update issues priority
2701 2720 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2702 2721 :issue => {:priority_id => 7,
2703 2722 :assigned_to_id => '',
2704 2723 :custom_field_values => {'2' => ''}}
2705 2724
2706 2725 assert_response 302
2707 2726 # check that the issues were updated
2708 2727 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
2709 2728
2710 2729 issue = Issue.find(1)
2711 2730 journal = issue.journals.find(:first, :order => 'created_on DESC')
2712 2731 assert_equal '125', issue.custom_value_for(2).value
2713 2732 assert_equal 'Bulk editing', journal.notes
2714 2733 assert_equal 1, journal.details.size
2715 2734 end
2716 2735
2717 2736 def test_bulk_update_with_group_assignee
2718 2737 group = Group.find(11)
2719 2738 project = Project.find(1)
2720 2739 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
2721 2740
2722 2741 @request.session[:user_id] = 2
2723 2742 # update issues assignee
2724 2743 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2725 2744 :issue => {:priority_id => '',
2726 2745 :assigned_to_id => group.id,
2727 2746 :custom_field_values => {'2' => ''}}
2728 2747
2729 2748 assert_response 302
2730 2749 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
2731 2750 end
2732 2751
2733 2752 def test_bulk_update_on_different_projects
2734 2753 @request.session[:user_id] = 2
2735 2754 # update issues priority
2736 2755 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
2737 2756 :issue => {:priority_id => 7,
2738 2757 :assigned_to_id => '',
2739 2758 :custom_field_values => {'2' => ''}}
2740 2759
2741 2760 assert_response 302
2742 2761 # check that the issues were updated
2743 2762 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
2744 2763
2745 2764 issue = Issue.find(1)
2746 2765 journal = issue.journals.find(:first, :order => 'created_on DESC')
2747 2766 assert_equal '125', issue.custom_value_for(2).value
2748 2767 assert_equal 'Bulk editing', journal.notes
2749 2768 assert_equal 1, journal.details.size
2750 2769 end
2751 2770
2752 2771 def test_bulk_update_on_different_projects_without_rights
2753 2772 @request.session[:user_id] = 3
2754 2773 user = User.find(3)
2755 2774 action = { :controller => "issues", :action => "bulk_update" }
2756 2775 assert user.allowed_to?(action, Issue.find(1).project)
2757 2776 assert ! user.allowed_to?(action, Issue.find(6).project)
2758 2777 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
2759 2778 :issue => {:priority_id => 7,
2760 2779 :assigned_to_id => '',
2761 2780 :custom_field_values => {'2' => ''}}
2762 2781 assert_response 403
2763 2782 assert_not_equal "Bulk should fail", Journal.last.notes
2764 2783 end
2765 2784
2766 2785 def test_bullk_update_should_send_a_notification
2767 2786 @request.session[:user_id] = 2
2768 2787 ActionMailer::Base.deliveries.clear
2769 2788 post(:bulk_update,
2770 2789 {
2771 2790 :ids => [1, 2],
2772 2791 :notes => 'Bulk editing',
2773 2792 :issue => {
2774 2793 :priority_id => 7,
2775 2794 :assigned_to_id => '',
2776 2795 :custom_field_values => {'2' => ''}
2777 2796 }
2778 2797 })
2779 2798
2780 2799 assert_response 302
2781 2800 assert_equal 2, ActionMailer::Base.deliveries.size
2782 2801 end
2783 2802
2784 2803 def test_bulk_update_project
2785 2804 @request.session[:user_id] = 2
2786 2805 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
2787 2806 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2788 2807 # Issues moved to project 2
2789 2808 assert_equal 2, Issue.find(1).project_id
2790 2809 assert_equal 2, Issue.find(2).project_id
2791 2810 # No tracker change
2792 2811 assert_equal 1, Issue.find(1).tracker_id
2793 2812 assert_equal 2, Issue.find(2).tracker_id
2794 2813 end
2795 2814
2796 2815 def test_bulk_update_project_on_single_issue_should_follow_when_needed
2797 2816 @request.session[:user_id] = 2
2798 2817 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
2799 2818 assert_redirected_to '/issues/1'
2800 2819 end
2801 2820
2802 2821 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
2803 2822 @request.session[:user_id] = 2
2804 2823 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
2805 2824 assert_redirected_to '/projects/onlinestore/issues'
2806 2825 end
2807 2826
2808 2827 def test_bulk_update_tracker
2809 2828 @request.session[:user_id] = 2
2810 2829 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
2811 2830 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2812 2831 assert_equal 2, Issue.find(1).tracker_id
2813 2832 assert_equal 2, Issue.find(2).tracker_id
2814 2833 end
2815 2834
2816 2835 def test_bulk_update_status
2817 2836 @request.session[:user_id] = 2
2818 2837 # update issues priority
2819 2838 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
2820 2839 :issue => {:priority_id => '',
2821 2840 :assigned_to_id => '',
2822 2841 :status_id => '5'}
2823 2842
2824 2843 assert_response 302
2825 2844 issue = Issue.find(1)
2826 2845 assert issue.closed?
2827 2846 end
2828 2847
2829 2848 def test_bulk_update_priority
2830 2849 @request.session[:user_id] = 2
2831 2850 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
2832 2851
2833 2852 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2834 2853 assert_equal 6, Issue.find(1).priority_id
2835 2854 assert_equal 6, Issue.find(2).priority_id
2836 2855 end
2837 2856
2838 2857 def test_bulk_update_with_notes
2839 2858 @request.session[:user_id] = 2
2840 2859 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
2841 2860
2842 2861 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2843 2862 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
2844 2863 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
2845 2864 end
2846 2865
2847 2866 def test_bulk_update_parent_id
2848 2867 @request.session[:user_id] = 2
2849 2868 post :bulk_update, :ids => [1, 3],
2850 2869 :notes => 'Bulk editing parent',
2851 2870 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
2852 2871
2853 2872 assert_response 302
2854 2873 parent = Issue.find(2)
2855 2874 assert_equal parent.id, Issue.find(1).parent_id
2856 2875 assert_equal parent.id, Issue.find(3).parent_id
2857 2876 assert_equal [1, 3], parent.children.collect(&:id).sort
2858 2877 end
2859 2878
2860 2879 def test_bulk_update_custom_field
2861 2880 @request.session[:user_id] = 2
2862 2881 # update issues priority
2863 2882 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
2864 2883 :issue => {:priority_id => '',
2865 2884 :assigned_to_id => '',
2866 2885 :custom_field_values => {'2' => '777'}}
2867 2886
2868 2887 assert_response 302
2869 2888
2870 2889 issue = Issue.find(1)
2871 2890 journal = issue.journals.find(:first, :order => 'created_on DESC')
2872 2891 assert_equal '777', issue.custom_value_for(2).value
2873 2892 assert_equal 1, journal.details.size
2874 2893 assert_equal '125', journal.details.first.old_value
2875 2894 assert_equal '777', journal.details.first.value
2876 2895 end
2877 2896
2878 2897 def test_bulk_update_multi_custom_field
2879 2898 field = CustomField.find(1)
2880 2899 field.update_attribute :multiple, true
2881 2900
2882 2901 @request.session[:user_id] = 2
2883 2902 post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field',
2884 2903 :issue => {:priority_id => '',
2885 2904 :assigned_to_id => '',
2886 2905 :custom_field_values => {'1' => ['MySQL', 'Oracle']}}
2887 2906
2888 2907 assert_response 302
2889 2908
2890 2909 assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort
2891 2910 assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort
2892 2911 # the custom field is not associated with the issue tracker
2893 2912 assert_nil Issue.find(2).custom_field_value(1)
2894 2913 end
2895 2914
2896 2915 def test_bulk_update_unassign
2897 2916 assert_not_nil Issue.find(2).assigned_to
2898 2917 @request.session[:user_id] = 2
2899 2918 # unassign issues
2900 2919 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
2901 2920 assert_response 302
2902 2921 # check that the issues were updated
2903 2922 assert_nil Issue.find(2).assigned_to
2904 2923 end
2905 2924
2906 2925 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
2907 2926 @request.session[:user_id] = 2
2908 2927
2909 2928 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
2910 2929
2911 2930 assert_response :redirect
2912 2931 issues = Issue.find([1,2])
2913 2932 issues.each do |issue|
2914 2933 assert_equal 4, issue.fixed_version_id
2915 2934 assert_not_equal issue.project_id, issue.fixed_version.project_id
2916 2935 end
2917 2936 end
2918 2937
2919 2938 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
2920 2939 @request.session[:user_id] = 2
2921 2940 post :bulk_update, :ids => [1,2], :back_url => '/issues'
2922 2941
2923 2942 assert_response :redirect
2924 2943 assert_redirected_to '/issues'
2925 2944 end
2926 2945
2927 2946 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
2928 2947 @request.session[:user_id] = 2
2929 2948 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
2930 2949
2931 2950 assert_response :redirect
2932 2951 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
2933 2952 end
2934 2953
2935 2954 def test_bulk_copy_to_another_project
2936 2955 @request.session[:user_id] = 2
2937 2956 assert_difference 'Issue.count', 2 do
2938 2957 assert_no_difference 'Project.find(1).issues.count' do
2939 2958 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
2940 2959 end
2941 2960 end
2942 2961 assert_redirected_to '/projects/ecookbook/issues'
2943 2962 end
2944 2963
2945 2964 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
2946 2965 @request.session[:user_id] = 2
2947 2966 issue_before_move = Issue.find(1)
2948 2967 assert_difference 'Issue.count', 1 do
2949 2968 assert_no_difference 'Project.find(1).issues.count' do
2950 2969 post :bulk_update, :ids => [1], :copy => '1',
2951 2970 :issue => {
2952 2971 :project_id => '2', :tracker_id => '', :assigned_to_id => '',
2953 2972 :status_id => '', :start_date => '', :due_date => ''
2954 2973 }
2955 2974 end
2956 2975 end
2957 2976 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
2958 2977 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
2959 2978 assert_equal issue_before_move.status_id, issue_after_move.status_id
2960 2979 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
2961 2980 end
2962 2981
2963 2982 def test_bulk_copy_should_allow_changing_the_issue_attributes
2964 2983 # Fixes random test failure with Mysql
2965 2984 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
2966 2985 # doesn't return the expected results
2967 2986 Issue.delete_all("project_id=2")
2968 2987
2969 2988 @request.session[:user_id] = 2
2970 2989 assert_difference 'Issue.count', 2 do
2971 2990 assert_no_difference 'Project.find(1).issues.count' do
2972 2991 post :bulk_update, :ids => [1, 2], :copy => '1',
2973 2992 :issue => {
2974 2993 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
2975 2994 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
2976 2995 }
2977 2996 end
2978 2997 end
2979 2998
2980 2999 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
2981 3000 assert_equal 2, copied_issues.size
2982 3001 copied_issues.each do |issue|
2983 3002 assert_equal 2, issue.project_id, "Project is incorrect"
2984 3003 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
2985 3004 assert_equal 3, issue.status_id, "Status is incorrect"
2986 3005 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
2987 3006 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
2988 3007 end
2989 3008 end
2990 3009
2991 3010 def test_bulk_copy_should_allow_adding_a_note
2992 3011 @request.session[:user_id] = 2
2993 3012 assert_difference 'Issue.count', 1 do
2994 3013 post :bulk_update, :ids => [1], :copy => '1',
2995 3014 :notes => 'Copying one issue',
2996 3015 :issue => {
2997 3016 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
2998 3017 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
2999 3018 }
3000 3019 end
3001 3020
3002 3021 issue = Issue.first(:order => 'id DESC')
3003 3022 assert_equal 1, issue.journals.size
3004 3023 journal = issue.journals.first
3005 3024 assert_equal 0, journal.details.size
3006 3025 assert_equal 'Copying one issue', journal.notes
3007 3026 end
3008 3027
3009 3028 def test_bulk_copy_to_another_project_should_follow_when_needed
3010 3029 @request.session[:user_id] = 2
3011 3030 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
3012 3031 issue = Issue.first(:order => 'id DESC')
3013 3032 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
3014 3033 end
3015 3034
3016 3035 def test_destroy_issue_with_no_time_entries
3017 3036 assert_nil TimeEntry.find_by_issue_id(2)
3018 3037 @request.session[:user_id] = 2
3019 3038
3020 3039 assert_difference 'Issue.count', -1 do
3021 3040 delete :destroy, :id => 2
3022 3041 end
3023 3042 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3024 3043 assert_nil Issue.find_by_id(2)
3025 3044 end
3026 3045
3027 3046 def test_destroy_issues_with_time_entries
3028 3047 @request.session[:user_id] = 2
3029 3048
3030 3049 assert_no_difference 'Issue.count' do
3031 3050 delete :destroy, :ids => [1, 3]
3032 3051 end
3033 3052 assert_response :success
3034 3053 assert_template 'destroy'
3035 3054 assert_not_nil assigns(:hours)
3036 3055 assert Issue.find_by_id(1) && Issue.find_by_id(3)
3037 3056 assert_tag 'form',
3038 3057 :descendant => {:tag => 'input', :attributes => {:name => '_method', :value => 'delete'}}
3039 3058 end
3040 3059
3041 3060 def test_destroy_issues_and_destroy_time_entries
3042 3061 @request.session[:user_id] = 2
3043 3062
3044 3063 assert_difference 'Issue.count', -2 do
3045 3064 assert_difference 'TimeEntry.count', -3 do
3046 3065 delete :destroy, :ids => [1, 3], :todo => 'destroy'
3047 3066 end
3048 3067 end
3049 3068 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3050 3069 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3051 3070 assert_nil TimeEntry.find_by_id([1, 2])
3052 3071 end
3053 3072
3054 3073 def test_destroy_issues_and_assign_time_entries_to_project
3055 3074 @request.session[:user_id] = 2
3056 3075
3057 3076 assert_difference 'Issue.count', -2 do
3058 3077 assert_no_difference 'TimeEntry.count' do
3059 3078 delete :destroy, :ids => [1, 3], :todo => 'nullify'
3060 3079 end
3061 3080 end
3062 3081 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3063 3082 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3064 3083 assert_nil TimeEntry.find(1).issue_id
3065 3084 assert_nil TimeEntry.find(2).issue_id
3066 3085 end
3067 3086
3068 3087 def test_destroy_issues_and_reassign_time_entries_to_another_issue
3069 3088 @request.session[:user_id] = 2
3070 3089
3071 3090 assert_difference 'Issue.count', -2 do
3072 3091 assert_no_difference 'TimeEntry.count' do
3073 3092 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
3074 3093 end
3075 3094 end
3076 3095 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3077 3096 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3078 3097 assert_equal 2, TimeEntry.find(1).issue_id
3079 3098 assert_equal 2, TimeEntry.find(2).issue_id
3080 3099 end
3081 3100
3082 3101 def test_destroy_issues_from_different_projects
3083 3102 @request.session[:user_id] = 2
3084 3103
3085 3104 assert_difference 'Issue.count', -3 do
3086 3105 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
3087 3106 end
3088 3107 assert_redirected_to :controller => 'issues', :action => 'index'
3089 3108 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
3090 3109 end
3091 3110
3092 3111 def test_destroy_parent_and_child_issues
3093 3112 parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue')
3094 3113 child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id)
3095 3114 assert child.is_descendant_of?(parent.reload)
3096 3115
3097 3116 @request.session[:user_id] = 2
3098 3117 assert_difference 'Issue.count', -2 do
3099 3118 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
3100 3119 end
3101 3120 assert_response 302
3102 3121 end
3103 3122
3104 3123 def test_default_search_scope
3105 3124 get :index
3106 3125 assert_tag :div, :attributes => {:id => 'quick-search'},
3107 3126 :child => {:tag => 'form',
3108 3127 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
3109 3128 end
3110 3129 end
General Comments 0
You need to be logged in to leave comments. Login now