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