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