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