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