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