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