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