##// END OF EJS Templates
Fixed that export links include page parameter....
Jean-Philippe Lang -
r9248:04e7b18869ee
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,3226 +1,3235
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_update_new_form_should_propose_transitions_based_on_initial_status
1367 1376 @request.session[:user_id] = 2
1368 1377 Workflow.delete_all
1369 1378 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2)
1370 1379 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5)
1371 1380 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4)
1372 1381
1373 1382 xhr :post, :new, :project_id => 1,
1374 1383 :issue => {:tracker_id => 1,
1375 1384 :status_id => 5,
1376 1385 :subject => 'This is an issue'}
1377 1386
1378 1387 assert_equal 5, assigns(:issue).status_id
1379 1388 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
1380 1389 end
1381 1390
1382 1391 def test_post_create
1383 1392 @request.session[:user_id] = 2
1384 1393 assert_difference 'Issue.count' do
1385 1394 post :create, :project_id => 1,
1386 1395 :issue => {:tracker_id => 3,
1387 1396 :status_id => 2,
1388 1397 :subject => 'This is the test_new issue',
1389 1398 :description => 'This is the description',
1390 1399 :priority_id => 5,
1391 1400 :start_date => '2010-11-07',
1392 1401 :estimated_hours => '',
1393 1402 :custom_field_values => {'2' => 'Value for field 2'}}
1394 1403 end
1395 1404 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1396 1405
1397 1406 issue = Issue.find_by_subject('This is the test_new issue')
1398 1407 assert_not_nil issue
1399 1408 assert_equal 2, issue.author_id
1400 1409 assert_equal 3, issue.tracker_id
1401 1410 assert_equal 2, issue.status_id
1402 1411 assert_equal Date.parse('2010-11-07'), issue.start_date
1403 1412 assert_nil issue.estimated_hours
1404 1413 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
1405 1414 assert_not_nil v
1406 1415 assert_equal 'Value for field 2', v.value
1407 1416 end
1408 1417
1409 1418 def test_post_new_with_group_assignment
1410 1419 group = Group.find(11)
1411 1420 project = Project.find(1)
1412 1421 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
1413 1422
1414 1423 with_settings :issue_group_assignment => '1' do
1415 1424 @request.session[:user_id] = 2
1416 1425 assert_difference 'Issue.count' do
1417 1426 post :create, :project_id => project.id,
1418 1427 :issue => {:tracker_id => 3,
1419 1428 :status_id => 1,
1420 1429 :subject => 'This is the test_new_with_group_assignment issue',
1421 1430 :assigned_to_id => group.id}
1422 1431 end
1423 1432 end
1424 1433 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1425 1434
1426 1435 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
1427 1436 assert_not_nil issue
1428 1437 assert_equal group, issue.assigned_to
1429 1438 end
1430 1439
1431 1440 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
1432 1441 Setting.default_issue_start_date_to_creation_date = 0
1433 1442
1434 1443 @request.session[:user_id] = 2
1435 1444 assert_difference 'Issue.count' do
1436 1445 post :create, :project_id => 1,
1437 1446 :issue => {:tracker_id => 3,
1438 1447 :status_id => 2,
1439 1448 :subject => 'This is the test_new issue',
1440 1449 :description => 'This is the description',
1441 1450 :priority_id => 5,
1442 1451 :estimated_hours => '',
1443 1452 :custom_field_values => {'2' => 'Value for field 2'}}
1444 1453 end
1445 1454 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1446 1455
1447 1456 issue = Issue.find_by_subject('This is the test_new issue')
1448 1457 assert_not_nil issue
1449 1458 assert_nil issue.start_date
1450 1459 end
1451 1460
1452 1461 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1453 1462 Setting.default_issue_start_date_to_creation_date = 1
1454 1463
1455 1464 @request.session[:user_id] = 2
1456 1465 assert_difference 'Issue.count' do
1457 1466 post :create, :project_id => 1,
1458 1467 :issue => {:tracker_id => 3,
1459 1468 :status_id => 2,
1460 1469 :subject => 'This is the test_new issue',
1461 1470 :description => 'This is the description',
1462 1471 :priority_id => 5,
1463 1472 :estimated_hours => '',
1464 1473 :custom_field_values => {'2' => 'Value for field 2'}}
1465 1474 end
1466 1475 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1467 1476
1468 1477 issue = Issue.find_by_subject('This is the test_new issue')
1469 1478 assert_not_nil issue
1470 1479 assert_equal Date.today, issue.start_date
1471 1480 end
1472 1481
1473 1482 def test_post_create_and_continue
1474 1483 @request.session[:user_id] = 2
1475 1484 assert_difference 'Issue.count' do
1476 1485 post :create, :project_id => 1,
1477 1486 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1478 1487 :continue => ''
1479 1488 end
1480 1489
1481 1490 issue = Issue.first(:order => 'id DESC')
1482 1491 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1483 1492 assert_not_nil flash[:notice], "flash was not set"
1484 1493 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
1485 1494 end
1486 1495
1487 1496 def test_post_create_without_custom_fields_param
1488 1497 @request.session[:user_id] = 2
1489 1498 assert_difference 'Issue.count' do
1490 1499 post :create, :project_id => 1,
1491 1500 :issue => {:tracker_id => 1,
1492 1501 :subject => 'This is the test_new issue',
1493 1502 :description => 'This is the description',
1494 1503 :priority_id => 5}
1495 1504 end
1496 1505 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1497 1506 end
1498 1507
1499 1508 def test_post_create_with_multi_custom_field
1500 1509 field = IssueCustomField.find_by_name('Database')
1501 1510 field.update_attribute(:multiple, true)
1502 1511
1503 1512 @request.session[:user_id] = 2
1504 1513 assert_difference 'Issue.count' do
1505 1514 post :create, :project_id => 1,
1506 1515 :issue => {:tracker_id => 1,
1507 1516 :subject => 'This is the test_new issue',
1508 1517 :description => 'This is the description',
1509 1518 :priority_id => 5,
1510 1519 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}}
1511 1520 end
1512 1521 assert_response 302
1513 1522 issue = Issue.first(:order => 'id DESC')
1514 1523 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
1515 1524 end
1516 1525
1517 1526 def test_post_create_with_empty_multi_custom_field
1518 1527 field = IssueCustomField.find_by_name('Database')
1519 1528 field.update_attribute(:multiple, true)
1520 1529
1521 1530 @request.session[:user_id] = 2
1522 1531 assert_difference 'Issue.count' do
1523 1532 post :create, :project_id => 1,
1524 1533 :issue => {:tracker_id => 1,
1525 1534 :subject => 'This is the test_new issue',
1526 1535 :description => 'This is the description',
1527 1536 :priority_id => 5,
1528 1537 :custom_field_values => {'1' => ['']}}
1529 1538 end
1530 1539 assert_response 302
1531 1540 issue = Issue.first(:order => 'id DESC')
1532 1541 assert_equal [''], issue.custom_field_value(1).sort
1533 1542 end
1534 1543
1535 1544 def test_post_create_with_multi_user_custom_field
1536 1545 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1537 1546 :tracker_ids => [1], :is_for_all => true)
1538 1547
1539 1548 @request.session[:user_id] = 2
1540 1549 assert_difference 'Issue.count' do
1541 1550 post :create, :project_id => 1,
1542 1551 :issue => {:tracker_id => 1,
1543 1552 :subject => 'This is the test_new issue',
1544 1553 :description => 'This is the description',
1545 1554 :priority_id => 5,
1546 1555 :custom_field_values => {field.id.to_s => ['', '2', '3']}}
1547 1556 end
1548 1557 assert_response 302
1549 1558 issue = Issue.first(:order => 'id DESC')
1550 1559 assert_equal ['2', '3'], issue.custom_field_value(field).sort
1551 1560 end
1552 1561
1553 1562 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1554 1563 field = IssueCustomField.find_by_name('Database')
1555 1564 field.update_attribute(:is_required, true)
1556 1565
1557 1566 @request.session[:user_id] = 2
1558 1567 assert_no_difference 'Issue.count' do
1559 1568 post :create, :project_id => 1,
1560 1569 :issue => {:tracker_id => 1,
1561 1570 :subject => 'This is the test_new issue',
1562 1571 :description => 'This is the description',
1563 1572 :priority_id => 5}
1564 1573 end
1565 1574 assert_response :success
1566 1575 assert_template 'new'
1567 1576 issue = assigns(:issue)
1568 1577 assert_not_nil issue
1569 1578 assert_error_tag :content => /Database can't be blank/
1570 1579 end
1571 1580
1572 1581 def test_post_create_with_watchers
1573 1582 @request.session[:user_id] = 2
1574 1583 ActionMailer::Base.deliveries.clear
1575 1584
1576 1585 assert_difference 'Watcher.count', 2 do
1577 1586 post :create, :project_id => 1,
1578 1587 :issue => {:tracker_id => 1,
1579 1588 :subject => 'This is a new issue with watchers',
1580 1589 :description => 'This is the description',
1581 1590 :priority_id => 5,
1582 1591 :watcher_user_ids => ['2', '3']}
1583 1592 end
1584 1593 issue = Issue.find_by_subject('This is a new issue with watchers')
1585 1594 assert_not_nil issue
1586 1595 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1587 1596
1588 1597 # Watchers added
1589 1598 assert_equal [2, 3], issue.watcher_user_ids.sort
1590 1599 assert issue.watched_by?(User.find(3))
1591 1600 # Watchers notified
1592 1601 mail = ActionMailer::Base.deliveries.last
1593 1602 assert_not_nil mail
1594 1603 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
1595 1604 end
1596 1605
1597 1606 def test_post_create_subissue
1598 1607 @request.session[:user_id] = 2
1599 1608
1600 1609 assert_difference 'Issue.count' do
1601 1610 post :create, :project_id => 1,
1602 1611 :issue => {:tracker_id => 1,
1603 1612 :subject => 'This is a child issue',
1604 1613 :parent_issue_id => 2}
1605 1614 end
1606 1615 issue = Issue.find_by_subject('This is a child issue')
1607 1616 assert_not_nil issue
1608 1617 assert_equal Issue.find(2), issue.parent
1609 1618 end
1610 1619
1611 1620 def test_post_create_subissue_with_non_numeric_parent_id
1612 1621 @request.session[:user_id] = 2
1613 1622
1614 1623 assert_difference 'Issue.count' do
1615 1624 post :create, :project_id => 1,
1616 1625 :issue => {:tracker_id => 1,
1617 1626 :subject => 'This is a child issue',
1618 1627 :parent_issue_id => 'ABC'}
1619 1628 end
1620 1629 issue = Issue.find_by_subject('This is a child issue')
1621 1630 assert_not_nil issue
1622 1631 assert_nil issue.parent
1623 1632 end
1624 1633
1625 1634 def test_post_create_private
1626 1635 @request.session[:user_id] = 2
1627 1636
1628 1637 assert_difference 'Issue.count' do
1629 1638 post :create, :project_id => 1,
1630 1639 :issue => {:tracker_id => 1,
1631 1640 :subject => 'This is a private issue',
1632 1641 :is_private => '1'}
1633 1642 end
1634 1643 issue = Issue.first(:order => 'id DESC')
1635 1644 assert issue.is_private?
1636 1645 end
1637 1646
1638 1647 def test_post_create_private_with_set_own_issues_private_permission
1639 1648 role = Role.find(1)
1640 1649 role.remove_permission! :set_issues_private
1641 1650 role.add_permission! :set_own_issues_private
1642 1651
1643 1652 @request.session[:user_id] = 2
1644 1653
1645 1654 assert_difference 'Issue.count' do
1646 1655 post :create, :project_id => 1,
1647 1656 :issue => {:tracker_id => 1,
1648 1657 :subject => 'This is a private issue',
1649 1658 :is_private => '1'}
1650 1659 end
1651 1660 issue = Issue.first(:order => 'id DESC')
1652 1661 assert issue.is_private?
1653 1662 end
1654 1663
1655 1664 def test_post_create_should_send_a_notification
1656 1665 ActionMailer::Base.deliveries.clear
1657 1666 @request.session[:user_id] = 2
1658 1667 assert_difference 'Issue.count' do
1659 1668 post :create, :project_id => 1,
1660 1669 :issue => {:tracker_id => 3,
1661 1670 :subject => 'This is the test_new issue',
1662 1671 :description => 'This is the description',
1663 1672 :priority_id => 5,
1664 1673 :estimated_hours => '',
1665 1674 :custom_field_values => {'2' => 'Value for field 2'}}
1666 1675 end
1667 1676 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1668 1677
1669 1678 assert_equal 1, ActionMailer::Base.deliveries.size
1670 1679 end
1671 1680
1672 1681 def test_post_create_should_preserve_fields_values_on_validation_failure
1673 1682 @request.session[:user_id] = 2
1674 1683 post :create, :project_id => 1,
1675 1684 :issue => {:tracker_id => 1,
1676 1685 # empty subject
1677 1686 :subject => '',
1678 1687 :description => 'This is a description',
1679 1688 :priority_id => 6,
1680 1689 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
1681 1690 assert_response :success
1682 1691 assert_template 'new'
1683 1692
1684 1693 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
1685 1694 :content => 'This is a description'
1686 1695 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1687 1696 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1688 1697 :value => '6' },
1689 1698 :content => 'High' }
1690 1699 # Custom fields
1691 1700 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
1692 1701 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1693 1702 :value => 'Oracle' },
1694 1703 :content => 'Oracle' }
1695 1704 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
1696 1705 :value => 'Value for field 2'}
1697 1706 end
1698 1707
1699 1708 def test_post_create_with_failure_should_preserve_watchers
1700 1709 assert !User.find(8).member_of?(Project.find(1))
1701 1710
1702 1711 @request.session[:user_id] = 2
1703 1712 post :create, :project_id => 1,
1704 1713 :issue => {:tracker_id => 1,
1705 1714 :watcher_user_ids => ['3', '8']}
1706 1715 assert_response :success
1707 1716 assert_template 'new'
1708 1717
1709 1718 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '2', :checked => nil}
1710 1719 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '3', :checked => 'checked'}
1711 1720 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '8', :checked => 'checked'}
1712 1721 end
1713 1722
1714 1723 def test_post_create_should_ignore_non_safe_attributes
1715 1724 @request.session[:user_id] = 2
1716 1725 assert_nothing_raised do
1717 1726 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
1718 1727 end
1719 1728 end
1720 1729
1721 1730 def test_post_create_with_attachment
1722 1731 set_tmp_attachments_directory
1723 1732 @request.session[:user_id] = 2
1724 1733
1725 1734 assert_difference 'Issue.count' do
1726 1735 assert_difference 'Attachment.count' do
1727 1736 post :create, :project_id => 1,
1728 1737 :issue => { :tracker_id => '1', :subject => 'With attachment' },
1729 1738 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1730 1739 end
1731 1740 end
1732 1741
1733 1742 issue = Issue.first(:order => 'id DESC')
1734 1743 attachment = Attachment.first(:order => 'id DESC')
1735 1744
1736 1745 assert_equal issue, attachment.container
1737 1746 assert_equal 2, attachment.author_id
1738 1747 assert_equal 'testfile.txt', attachment.filename
1739 1748 assert_equal 'text/plain', attachment.content_type
1740 1749 assert_equal 'test file', attachment.description
1741 1750 assert_equal 59, attachment.filesize
1742 1751 assert File.exists?(attachment.diskfile)
1743 1752 assert_equal 59, File.size(attachment.diskfile)
1744 1753 end
1745 1754
1746 1755 def test_post_create_with_failure_should_save_attachments
1747 1756 set_tmp_attachments_directory
1748 1757 @request.session[:user_id] = 2
1749 1758
1750 1759 assert_no_difference 'Issue.count' do
1751 1760 assert_difference 'Attachment.count' do
1752 1761 post :create, :project_id => 1,
1753 1762 :issue => { :tracker_id => '1', :subject => '' },
1754 1763 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1755 1764 assert_response :success
1756 1765 assert_template 'new'
1757 1766 end
1758 1767 end
1759 1768
1760 1769 attachment = Attachment.first(:order => 'id DESC')
1761 1770 assert_equal 'testfile.txt', attachment.filename
1762 1771 assert File.exists?(attachment.diskfile)
1763 1772 assert_nil attachment.container
1764 1773
1765 1774 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
1766 1775 assert_tag 'span', :content => /testfile.txt/
1767 1776 end
1768 1777
1769 1778 def test_post_create_with_failure_should_keep_saved_attachments
1770 1779 set_tmp_attachments_directory
1771 1780 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
1772 1781 @request.session[:user_id] = 2
1773 1782
1774 1783 assert_no_difference 'Issue.count' do
1775 1784 assert_no_difference 'Attachment.count' do
1776 1785 post :create, :project_id => 1,
1777 1786 :issue => { :tracker_id => '1', :subject => '' },
1778 1787 :attachments => {'p0' => {'token' => attachment.token}}
1779 1788 assert_response :success
1780 1789 assert_template 'new'
1781 1790 end
1782 1791 end
1783 1792
1784 1793 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
1785 1794 assert_tag 'span', :content => /testfile.txt/
1786 1795 end
1787 1796
1788 1797 def test_post_create_should_attach_saved_attachments
1789 1798 set_tmp_attachments_directory
1790 1799 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
1791 1800 @request.session[:user_id] = 2
1792 1801
1793 1802 assert_difference 'Issue.count' do
1794 1803 assert_no_difference 'Attachment.count' do
1795 1804 post :create, :project_id => 1,
1796 1805 :issue => { :tracker_id => '1', :subject => 'Saved attachments' },
1797 1806 :attachments => {'p0' => {'token' => attachment.token}}
1798 1807 assert_response 302
1799 1808 end
1800 1809 end
1801 1810
1802 1811 issue = Issue.first(:order => 'id DESC')
1803 1812 assert_equal 1, issue.attachments.count
1804 1813
1805 1814 attachment.reload
1806 1815 assert_equal issue, attachment.container
1807 1816 end
1808 1817
1809 1818 context "without workflow privilege" do
1810 1819 setup do
1811 1820 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1812 1821 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1813 1822 end
1814 1823
1815 1824 context "#new" do
1816 1825 should "propose default status only" do
1817 1826 get :new, :project_id => 1
1818 1827 assert_response :success
1819 1828 assert_template 'new'
1820 1829 assert_tag :tag => 'select',
1821 1830 :attributes => {:name => 'issue[status_id]'},
1822 1831 :children => {:count => 1},
1823 1832 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
1824 1833 end
1825 1834
1826 1835 should "accept default status" do
1827 1836 assert_difference 'Issue.count' do
1828 1837 post :create, :project_id => 1,
1829 1838 :issue => {:tracker_id => 1,
1830 1839 :subject => 'This is an issue',
1831 1840 :status_id => 1}
1832 1841 end
1833 1842 issue = Issue.last(:order => 'id')
1834 1843 assert_equal IssueStatus.default, issue.status
1835 1844 end
1836 1845
1837 1846 should "ignore unauthorized status" do
1838 1847 assert_difference 'Issue.count' do
1839 1848 post :create, :project_id => 1,
1840 1849 :issue => {:tracker_id => 1,
1841 1850 :subject => 'This is an issue',
1842 1851 :status_id => 3}
1843 1852 end
1844 1853 issue = Issue.last(:order => 'id')
1845 1854 assert_equal IssueStatus.default, issue.status
1846 1855 end
1847 1856 end
1848 1857
1849 1858 context "#update" do
1850 1859 should "ignore status change" do
1851 1860 assert_difference 'Journal.count' do
1852 1861 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1853 1862 end
1854 1863 assert_equal 1, Issue.find(1).status_id
1855 1864 end
1856 1865
1857 1866 should "ignore attributes changes" do
1858 1867 assert_difference 'Journal.count' do
1859 1868 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1860 1869 end
1861 1870 issue = Issue.find(1)
1862 1871 assert_equal "Can't print recipes", issue.subject
1863 1872 assert_nil issue.assigned_to
1864 1873 end
1865 1874 end
1866 1875 end
1867 1876
1868 1877 context "with workflow privilege" do
1869 1878 setup do
1870 1879 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1871 1880 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
1872 1881 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
1873 1882 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1874 1883 end
1875 1884
1876 1885 context "#update" do
1877 1886 should "accept authorized status" do
1878 1887 assert_difference 'Journal.count' do
1879 1888 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1880 1889 end
1881 1890 assert_equal 3, Issue.find(1).status_id
1882 1891 end
1883 1892
1884 1893 should "ignore unauthorized status" do
1885 1894 assert_difference 'Journal.count' do
1886 1895 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1887 1896 end
1888 1897 assert_equal 1, Issue.find(1).status_id
1889 1898 end
1890 1899
1891 1900 should "accept authorized attributes changes" do
1892 1901 assert_difference 'Journal.count' do
1893 1902 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
1894 1903 end
1895 1904 issue = Issue.find(1)
1896 1905 assert_equal 2, issue.assigned_to_id
1897 1906 end
1898 1907
1899 1908 should "ignore unauthorized attributes changes" do
1900 1909 assert_difference 'Journal.count' do
1901 1910 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
1902 1911 end
1903 1912 issue = Issue.find(1)
1904 1913 assert_equal "Can't print recipes", issue.subject
1905 1914 end
1906 1915 end
1907 1916
1908 1917 context "and :edit_issues permission" do
1909 1918 setup do
1910 1919 Role.anonymous.add_permission! :add_issues, :edit_issues
1911 1920 end
1912 1921
1913 1922 should "accept authorized status" do
1914 1923 assert_difference 'Journal.count' do
1915 1924 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1916 1925 end
1917 1926 assert_equal 3, Issue.find(1).status_id
1918 1927 end
1919 1928
1920 1929 should "ignore unauthorized status" do
1921 1930 assert_difference 'Journal.count' do
1922 1931 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1923 1932 end
1924 1933 assert_equal 1, Issue.find(1).status_id
1925 1934 end
1926 1935
1927 1936 should "accept authorized attributes changes" do
1928 1937 assert_difference 'Journal.count' do
1929 1938 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1930 1939 end
1931 1940 issue = Issue.find(1)
1932 1941 assert_equal "changed", issue.subject
1933 1942 assert_equal 2, issue.assigned_to_id
1934 1943 end
1935 1944 end
1936 1945 end
1937 1946
1938 1947 def test_new_as_copy
1939 1948 @request.session[:user_id] = 2
1940 1949 get :new, :project_id => 1, :copy_from => 1
1941 1950
1942 1951 assert_response :success
1943 1952 assert_template 'new'
1944 1953
1945 1954 assert_not_nil assigns(:issue)
1946 1955 orig = Issue.find(1)
1947 1956 assert_equal 1, assigns(:issue).project_id
1948 1957 assert_equal orig.subject, assigns(:issue).subject
1949 1958 assert assigns(:issue).copy?
1950 1959
1951 1960 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
1952 1961 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
1953 1962 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1954 1963 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'}
1955 1964 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1956 1965 :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'}
1957 1966 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
1958 1967 end
1959 1968
1960 1969 def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
1961 1970 @request.session[:user_id] = 2
1962 1971 issue = Issue.find(3)
1963 1972 assert issue.attachments.count > 0
1964 1973 get :new, :project_id => 1, :copy_from => 3
1965 1974
1966 1975 assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
1967 1976 end
1968 1977
1969 1978 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
1970 1979 @request.session[:user_id] = 2
1971 1980 issue = Issue.find(3)
1972 1981 issue.attachments.delete_all
1973 1982 get :new, :project_id => 1, :copy_from => 3
1974 1983
1975 1984 assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
1976 1985 end
1977 1986
1978 1987 def test_new_as_copy_with_invalid_issue_should_respond_with_404
1979 1988 @request.session[:user_id] = 2
1980 1989 get :new, :project_id => 1, :copy_from => 99999
1981 1990 assert_response 404
1982 1991 end
1983 1992
1984 1993 def test_create_as_copy_on_different_project
1985 1994 @request.session[:user_id] = 2
1986 1995 assert_difference 'Issue.count' do
1987 1996 post :create, :project_id => 1, :copy_from => 1,
1988 1997 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
1989 1998
1990 1999 assert_not_nil assigns(:issue)
1991 2000 assert assigns(:issue).copy?
1992 2001 end
1993 2002 issue = Issue.first(:order => 'id DESC')
1994 2003 assert_redirected_to "/issues/#{issue.id}"
1995 2004
1996 2005 assert_equal 2, issue.project_id
1997 2006 assert_equal 3, issue.tracker_id
1998 2007 assert_equal 'Copy', issue.subject
1999 2008 end
2000 2009
2001 2010 def test_create_as_copy_should_copy_attachments
2002 2011 @request.session[:user_id] = 2
2003 2012 issue = Issue.find(3)
2004 2013 count = issue.attachments.count
2005 2014 assert count > 0
2006 2015
2007 2016 assert_difference 'Issue.count' do
2008 2017 assert_difference 'Attachment.count', count do
2009 2018 assert_no_difference 'Journal.count' do
2010 2019 post :create, :project_id => 1, :copy_from => 3,
2011 2020 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
2012 2021 :copy_attachments => '1'
2013 2022 end
2014 2023 end
2015 2024 end
2016 2025 copy = Issue.first(:order => 'id DESC')
2017 2026 assert_equal count, copy.attachments.count
2018 2027 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
2019 2028 end
2020 2029
2021 2030 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
2022 2031 @request.session[:user_id] = 2
2023 2032 issue = Issue.find(3)
2024 2033 count = issue.attachments.count
2025 2034 assert count > 0
2026 2035
2027 2036 assert_difference 'Issue.count' do
2028 2037 assert_no_difference 'Attachment.count' do
2029 2038 assert_no_difference 'Journal.count' do
2030 2039 post :create, :project_id => 1, :copy_from => 3,
2031 2040 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}
2032 2041 end
2033 2042 end
2034 2043 end
2035 2044 copy = Issue.first(:order => 'id DESC')
2036 2045 assert_equal 0, copy.attachments.count
2037 2046 end
2038 2047
2039 2048 def test_create_as_copy_with_attachments_should_add_new_files
2040 2049 @request.session[:user_id] = 2
2041 2050 issue = Issue.find(3)
2042 2051 count = issue.attachments.count
2043 2052 assert count > 0
2044 2053
2045 2054 assert_difference 'Issue.count' do
2046 2055 assert_difference 'Attachment.count', count + 1 do
2047 2056 assert_no_difference 'Journal.count' do
2048 2057 post :create, :project_id => 1, :copy_from => 3,
2049 2058 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
2050 2059 :copy_attachments => '1',
2051 2060 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2052 2061 end
2053 2062 end
2054 2063 end
2055 2064 copy = Issue.first(:order => 'id DESC')
2056 2065 assert_equal count + 1, copy.attachments.count
2057 2066 end
2058 2067
2059 2068 def test_create_as_copy_with_failure
2060 2069 @request.session[:user_id] = 2
2061 2070 post :create, :project_id => 1, :copy_from => 1,
2062 2071 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
2063 2072
2064 2073 assert_response :success
2065 2074 assert_template 'new'
2066 2075
2067 2076 assert_not_nil assigns(:issue)
2068 2077 assert assigns(:issue).copy?
2069 2078
2070 2079 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
2071 2080 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
2072 2081 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2073 2082 :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'}
2074 2083 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2075 2084 :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'}
2076 2085 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
2077 2086 end
2078 2087
2079 2088 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
2080 2089 @request.session[:user_id] = 2
2081 2090 assert !User.find(2).member_of?(Project.find(4))
2082 2091
2083 2092 assert_difference 'Issue.count' do
2084 2093 post :create, :project_id => 1, :copy_from => 1,
2085 2094 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2086 2095 end
2087 2096 issue = Issue.first(:order => 'id DESC')
2088 2097 assert_equal 1, issue.project_id
2089 2098 end
2090 2099
2091 2100 def test_get_edit
2092 2101 @request.session[:user_id] = 2
2093 2102 get :edit, :id => 1
2094 2103 assert_response :success
2095 2104 assert_template 'edit'
2096 2105 assert_not_nil assigns(:issue)
2097 2106 assert_equal Issue.find(1), assigns(:issue)
2098 2107
2099 2108 # Be sure we don't display inactive IssuePriorities
2100 2109 assert ! IssuePriority.find(15).active?
2101 2110 assert_no_tag :option, :attributes => {:value => '15'},
2102 2111 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2103 2112 end
2104 2113
2105 2114 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
2106 2115 @request.session[:user_id] = 2
2107 2116 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
2108 2117
2109 2118 get :edit, :id => 1
2110 2119 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2111 2120 end
2112 2121
2113 2122 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
2114 2123 @request.session[:user_id] = 2
2115 2124 Role.find_by_name('Manager').remove_permission! :log_time
2116 2125
2117 2126 get :edit, :id => 1
2118 2127 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2119 2128 end
2120 2129
2121 2130 def test_get_edit_with_params
2122 2131 @request.session[:user_id] = 2
2123 2132 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
2124 2133 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
2125 2134 assert_response :success
2126 2135 assert_template 'edit'
2127 2136
2128 2137 issue = assigns(:issue)
2129 2138 assert_not_nil issue
2130 2139
2131 2140 assert_equal 5, issue.status_id
2132 2141 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
2133 2142 :child => { :tag => 'option',
2134 2143 :content => 'Closed',
2135 2144 :attributes => { :selected => 'selected' } }
2136 2145
2137 2146 assert_equal 7, issue.priority_id
2138 2147 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
2139 2148 :child => { :tag => 'option',
2140 2149 :content => 'Urgent',
2141 2150 :attributes => { :selected => 'selected' } }
2142 2151
2143 2152 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
2144 2153 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
2145 2154 :child => { :tag => 'option',
2146 2155 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
2147 2156 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
2148 2157 end
2149 2158
2150 2159 def test_get_edit_with_multi_custom_field
2151 2160 field = CustomField.find(1)
2152 2161 field.update_attribute :multiple, true
2153 2162 issue = Issue.find(1)
2154 2163 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2155 2164 issue.save!
2156 2165
2157 2166 @request.session[:user_id] = 2
2158 2167 get :edit, :id => 1
2159 2168 assert_response :success
2160 2169 assert_template 'edit'
2161 2170
2162 2171 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'}
2163 2172 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2164 2173 :child => {:tag => 'option', :attributes => {:value => 'MySQL', :selected => 'selected'}}
2165 2174 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2166 2175 :child => {:tag => 'option', :attributes => {:value => 'PostgreSQL', :selected => nil}}
2167 2176 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2168 2177 :child => {:tag => 'option', :attributes => {:value => 'Oracle', :selected => 'selected'}}
2169 2178 end
2170 2179
2171 2180 def test_update_edit_form
2172 2181 @request.session[:user_id] = 2
2173 2182 xhr :put, :new, :project_id => 1,
2174 2183 :id => 1,
2175 2184 :issue => {:tracker_id => 2,
2176 2185 :subject => 'This is the test_new issue',
2177 2186 :description => 'This is the description',
2178 2187 :priority_id => 5}
2179 2188 assert_response :success
2180 2189 assert_template 'attributes'
2181 2190
2182 2191 issue = assigns(:issue)
2183 2192 assert_kind_of Issue, issue
2184 2193 assert_equal 1, issue.id
2185 2194 assert_equal 1, issue.project_id
2186 2195 assert_equal 2, issue.tracker_id
2187 2196 assert_equal 'This is the test_new issue', issue.subject
2188 2197 end
2189 2198
2190 2199 def test_update_edit_form_should_propose_transitions_based_on_initial_status
2191 2200 @request.session[:user_id] = 2
2192 2201 Workflow.delete_all
2193 2202 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
2194 2203 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
2195 2204 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4)
2196 2205
2197 2206 xhr :put, :new, :project_id => 1,
2198 2207 :id => 2,
2199 2208 :issue => {:tracker_id => 2,
2200 2209 :status_id => 5,
2201 2210 :subject => 'This is an issue'}
2202 2211
2203 2212 assert_equal 5, assigns(:issue).status_id
2204 2213 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
2205 2214 end
2206 2215
2207 2216 def test_update_edit_form_with_project_change
2208 2217 @request.session[:user_id] = 2
2209 2218 xhr :put, :new, :project_id => 1,
2210 2219 :id => 1,
2211 2220 :project_change => '1',
2212 2221 :issue => {:project_id => 2,
2213 2222 :tracker_id => 2,
2214 2223 :subject => 'This is the test_new issue',
2215 2224 :description => 'This is the description',
2216 2225 :priority_id => 5}
2217 2226 assert_response :success
2218 2227 assert_template 'form'
2219 2228
2220 2229 issue = assigns(:issue)
2221 2230 assert_kind_of Issue, issue
2222 2231 assert_equal 1, issue.id
2223 2232 assert_equal 2, issue.project_id
2224 2233 assert_equal 2, issue.tracker_id
2225 2234 assert_equal 'This is the test_new issue', issue.subject
2226 2235 end
2227 2236
2228 2237 def test_put_update_without_custom_fields_param
2229 2238 @request.session[:user_id] = 2
2230 2239 ActionMailer::Base.deliveries.clear
2231 2240
2232 2241 issue = Issue.find(1)
2233 2242 assert_equal '125', issue.custom_value_for(2).value
2234 2243 old_subject = issue.subject
2235 2244 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2236 2245
2237 2246 assert_difference('Journal.count') do
2238 2247 assert_difference('JournalDetail.count', 2) do
2239 2248 put :update, :id => 1, :issue => {:subject => new_subject,
2240 2249 :priority_id => '6',
2241 2250 :category_id => '1' # no change
2242 2251 }
2243 2252 end
2244 2253 end
2245 2254 assert_redirected_to :action => 'show', :id => '1'
2246 2255 issue.reload
2247 2256 assert_equal new_subject, issue.subject
2248 2257 # Make sure custom fields were not cleared
2249 2258 assert_equal '125', issue.custom_value_for(2).value
2250 2259
2251 2260 mail = ActionMailer::Base.deliveries.last
2252 2261 assert_not_nil mail
2253 2262 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2254 2263 assert_mail_body_match "Subject changed from #{old_subject} to #{new_subject}", mail
2255 2264 end
2256 2265
2257 2266 def test_put_update_with_project_change
2258 2267 @request.session[:user_id] = 2
2259 2268 ActionMailer::Base.deliveries.clear
2260 2269
2261 2270 assert_difference('Journal.count') do
2262 2271 assert_difference('JournalDetail.count', 3) do
2263 2272 put :update, :id => 1, :issue => {:project_id => '2',
2264 2273 :tracker_id => '1', # no change
2265 2274 :priority_id => '6',
2266 2275 :category_id => '3'
2267 2276 }
2268 2277 end
2269 2278 end
2270 2279 assert_redirected_to :action => 'show', :id => '1'
2271 2280 issue = Issue.find(1)
2272 2281 assert_equal 2, issue.project_id
2273 2282 assert_equal 1, issue.tracker_id
2274 2283 assert_equal 6, issue.priority_id
2275 2284 assert_equal 3, issue.category_id
2276 2285
2277 2286 mail = ActionMailer::Base.deliveries.last
2278 2287 assert_not_nil mail
2279 2288 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2280 2289 assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail
2281 2290 end
2282 2291
2283 2292 def test_put_update_with_tracker_change
2284 2293 @request.session[:user_id] = 2
2285 2294 ActionMailer::Base.deliveries.clear
2286 2295
2287 2296 assert_difference('Journal.count') do
2288 2297 assert_difference('JournalDetail.count', 2) do
2289 2298 put :update, :id => 1, :issue => {:project_id => '1',
2290 2299 :tracker_id => '2',
2291 2300 :priority_id => '6'
2292 2301 }
2293 2302 end
2294 2303 end
2295 2304 assert_redirected_to :action => 'show', :id => '1'
2296 2305 issue = Issue.find(1)
2297 2306 assert_equal 1, issue.project_id
2298 2307 assert_equal 2, issue.tracker_id
2299 2308 assert_equal 6, issue.priority_id
2300 2309 assert_equal 1, issue.category_id
2301 2310
2302 2311 mail = ActionMailer::Base.deliveries.last
2303 2312 assert_not_nil mail
2304 2313 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2305 2314 assert_mail_body_match "Tracker changed from Bug to Feature request", mail
2306 2315 end
2307 2316
2308 2317 def test_put_update_with_custom_field_change
2309 2318 @request.session[:user_id] = 2
2310 2319 issue = Issue.find(1)
2311 2320 assert_equal '125', issue.custom_value_for(2).value
2312 2321
2313 2322 assert_difference('Journal.count') do
2314 2323 assert_difference('JournalDetail.count', 3) do
2315 2324 put :update, :id => 1, :issue => {:subject => 'Custom field change',
2316 2325 :priority_id => '6',
2317 2326 :category_id => '1', # no change
2318 2327 :custom_field_values => { '2' => 'New custom value' }
2319 2328 }
2320 2329 end
2321 2330 end
2322 2331 assert_redirected_to :action => 'show', :id => '1'
2323 2332 issue.reload
2324 2333 assert_equal 'New custom value', issue.custom_value_for(2).value
2325 2334
2326 2335 mail = ActionMailer::Base.deliveries.last
2327 2336 assert_not_nil mail
2328 2337 assert_mail_body_match "Searchable field changed from 125 to New custom value", mail
2329 2338 end
2330 2339
2331 2340 def test_put_update_with_multi_custom_field_change
2332 2341 field = CustomField.find(1)
2333 2342 field.update_attribute :multiple, true
2334 2343 issue = Issue.find(1)
2335 2344 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2336 2345 issue.save!
2337 2346
2338 2347 @request.session[:user_id] = 2
2339 2348 assert_difference('Journal.count') do
2340 2349 assert_difference('JournalDetail.count', 3) do
2341 2350 put :update, :id => 1,
2342 2351 :issue => {
2343 2352 :subject => 'Custom field change',
2344 2353 :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] }
2345 2354 }
2346 2355 end
2347 2356 end
2348 2357 assert_redirected_to :action => 'show', :id => '1'
2349 2358 assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort
2350 2359 end
2351 2360
2352 2361 def test_put_update_with_status_and_assignee_change
2353 2362 issue = Issue.find(1)
2354 2363 assert_equal 1, issue.status_id
2355 2364 @request.session[:user_id] = 2
2356 2365 assert_difference('TimeEntry.count', 0) do
2357 2366 put :update,
2358 2367 :id => 1,
2359 2368 :issue => { :status_id => 2, :assigned_to_id => 3 },
2360 2369 :notes => 'Assigned to dlopper',
2361 2370 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
2362 2371 end
2363 2372 assert_redirected_to :action => 'show', :id => '1'
2364 2373 issue.reload
2365 2374 assert_equal 2, issue.status_id
2366 2375 j = Journal.find(:first, :order => 'id DESC')
2367 2376 assert_equal 'Assigned to dlopper', j.notes
2368 2377 assert_equal 2, j.details.size
2369 2378
2370 2379 mail = ActionMailer::Base.deliveries.last
2371 2380 assert_mail_body_match "Status changed from New to Assigned", mail
2372 2381 # subject should contain the new status
2373 2382 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
2374 2383 end
2375 2384
2376 2385 def test_put_update_with_note_only
2377 2386 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
2378 2387 # anonymous user
2379 2388 put :update,
2380 2389 :id => 1,
2381 2390 :notes => notes
2382 2391 assert_redirected_to :action => 'show', :id => '1'
2383 2392 j = Journal.find(:first, :order => 'id DESC')
2384 2393 assert_equal notes, j.notes
2385 2394 assert_equal 0, j.details.size
2386 2395 assert_equal User.anonymous, j.user
2387 2396
2388 2397 mail = ActionMailer::Base.deliveries.last
2389 2398 assert_mail_body_match notes, mail
2390 2399 end
2391 2400
2392 2401 def test_put_update_with_note_and_spent_time
2393 2402 @request.session[:user_id] = 2
2394 2403 spent_hours_before = Issue.find(1).spent_hours
2395 2404 assert_difference('TimeEntry.count') do
2396 2405 put :update,
2397 2406 :id => 1,
2398 2407 :notes => '2.5 hours added',
2399 2408 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
2400 2409 end
2401 2410 assert_redirected_to :action => 'show', :id => '1'
2402 2411
2403 2412 issue = Issue.find(1)
2404 2413
2405 2414 j = Journal.find(:first, :order => 'id DESC')
2406 2415 assert_equal '2.5 hours added', j.notes
2407 2416 assert_equal 0, j.details.size
2408 2417
2409 2418 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
2410 2419 assert_not_nil t
2411 2420 assert_equal 2.5, t.hours
2412 2421 assert_equal spent_hours_before + 2.5, issue.spent_hours
2413 2422 end
2414 2423
2415 2424 def test_put_update_with_attachment_only
2416 2425 set_tmp_attachments_directory
2417 2426
2418 2427 # Delete all fixtured journals, a race condition can occur causing the wrong
2419 2428 # journal to get fetched in the next find.
2420 2429 Journal.delete_all
2421 2430
2422 2431 # anonymous user
2423 2432 assert_difference 'Attachment.count' do
2424 2433 put :update, :id => 1,
2425 2434 :notes => '',
2426 2435 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2427 2436 end
2428 2437
2429 2438 assert_redirected_to :action => 'show', :id => '1'
2430 2439 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
2431 2440 assert j.notes.blank?
2432 2441 assert_equal 1, j.details.size
2433 2442 assert_equal 'testfile.txt', j.details.first.value
2434 2443 assert_equal User.anonymous, j.user
2435 2444
2436 2445 attachment = Attachment.first(:order => 'id DESC')
2437 2446 assert_equal Issue.find(1), attachment.container
2438 2447 assert_equal User.anonymous, attachment.author
2439 2448 assert_equal 'testfile.txt', attachment.filename
2440 2449 assert_equal 'text/plain', attachment.content_type
2441 2450 assert_equal 'test file', attachment.description
2442 2451 assert_equal 59, attachment.filesize
2443 2452 assert File.exists?(attachment.diskfile)
2444 2453 assert_equal 59, File.size(attachment.diskfile)
2445 2454
2446 2455 mail = ActionMailer::Base.deliveries.last
2447 2456 assert_mail_body_match 'testfile.txt', mail
2448 2457 end
2449 2458
2450 2459 def test_put_update_with_failure_should_save_attachments
2451 2460 set_tmp_attachments_directory
2452 2461 @request.session[:user_id] = 2
2453 2462
2454 2463 assert_no_difference 'Journal.count' do
2455 2464 assert_difference 'Attachment.count' do
2456 2465 put :update, :id => 1,
2457 2466 :issue => { :subject => '' },
2458 2467 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2459 2468 assert_response :success
2460 2469 assert_template 'edit'
2461 2470 end
2462 2471 end
2463 2472
2464 2473 attachment = Attachment.first(:order => 'id DESC')
2465 2474 assert_equal 'testfile.txt', attachment.filename
2466 2475 assert File.exists?(attachment.diskfile)
2467 2476 assert_nil attachment.container
2468 2477
2469 2478 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2470 2479 assert_tag 'span', :content => /testfile.txt/
2471 2480 end
2472 2481
2473 2482 def test_put_update_with_failure_should_keep_saved_attachments
2474 2483 set_tmp_attachments_directory
2475 2484 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2476 2485 @request.session[:user_id] = 2
2477 2486
2478 2487 assert_no_difference 'Journal.count' do
2479 2488 assert_no_difference 'Attachment.count' do
2480 2489 put :update, :id => 1,
2481 2490 :issue => { :subject => '' },
2482 2491 :attachments => {'p0' => {'token' => attachment.token}}
2483 2492 assert_response :success
2484 2493 assert_template 'edit'
2485 2494 end
2486 2495 end
2487 2496
2488 2497 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2489 2498 assert_tag 'span', :content => /testfile.txt/
2490 2499 end
2491 2500
2492 2501 def test_put_update_should_attach_saved_attachments
2493 2502 set_tmp_attachments_directory
2494 2503 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2495 2504 @request.session[:user_id] = 2
2496 2505
2497 2506 assert_difference 'Journal.count' do
2498 2507 assert_difference 'JournalDetail.count' do
2499 2508 assert_no_difference 'Attachment.count' do
2500 2509 put :update, :id => 1,
2501 2510 :notes => 'Attachment added',
2502 2511 :attachments => {'p0' => {'token' => attachment.token}}
2503 2512 assert_redirected_to '/issues/1'
2504 2513 end
2505 2514 end
2506 2515 end
2507 2516
2508 2517 attachment.reload
2509 2518 assert_equal Issue.find(1), attachment.container
2510 2519
2511 2520 journal = Journal.first(:order => 'id DESC')
2512 2521 assert_equal 1, journal.details.size
2513 2522 assert_equal 'testfile.txt', journal.details.first.value
2514 2523 end
2515 2524
2516 2525 def test_put_update_with_attachment_that_fails_to_save
2517 2526 set_tmp_attachments_directory
2518 2527
2519 2528 # Delete all fixtured journals, a race condition can occur causing the wrong
2520 2529 # journal to get fetched in the next find.
2521 2530 Journal.delete_all
2522 2531
2523 2532 # Mock out the unsaved attachment
2524 2533 Attachment.any_instance.stubs(:create).returns(Attachment.new)
2525 2534
2526 2535 # anonymous user
2527 2536 put :update,
2528 2537 :id => 1,
2529 2538 :notes => '',
2530 2539 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
2531 2540 assert_redirected_to :action => 'show', :id => '1'
2532 2541 assert_equal '1 file(s) could not be saved.', flash[:warning]
2533 2542 end
2534 2543
2535 2544 def test_put_update_with_no_change
2536 2545 issue = Issue.find(1)
2537 2546 issue.journals.clear
2538 2547 ActionMailer::Base.deliveries.clear
2539 2548
2540 2549 put :update,
2541 2550 :id => 1,
2542 2551 :notes => ''
2543 2552 assert_redirected_to :action => 'show', :id => '1'
2544 2553
2545 2554 issue.reload
2546 2555 assert issue.journals.empty?
2547 2556 # No email should be sent
2548 2557 assert ActionMailer::Base.deliveries.empty?
2549 2558 end
2550 2559
2551 2560 def test_put_update_should_send_a_notification
2552 2561 @request.session[:user_id] = 2
2553 2562 ActionMailer::Base.deliveries.clear
2554 2563 issue = Issue.find(1)
2555 2564 old_subject = issue.subject
2556 2565 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2557 2566
2558 2567 put :update, :id => 1, :issue => {:subject => new_subject,
2559 2568 :priority_id => '6',
2560 2569 :category_id => '1' # no change
2561 2570 }
2562 2571 assert_equal 1, ActionMailer::Base.deliveries.size
2563 2572 end
2564 2573
2565 2574 def test_put_update_with_invalid_spent_time_hours_only
2566 2575 @request.session[:user_id] = 2
2567 2576 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2568 2577
2569 2578 assert_no_difference('Journal.count') do
2570 2579 put :update,
2571 2580 :id => 1,
2572 2581 :notes => notes,
2573 2582 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
2574 2583 end
2575 2584 assert_response :success
2576 2585 assert_template 'edit'
2577 2586
2578 2587 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2579 2588 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2580 2589 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
2581 2590 end
2582 2591
2583 2592 def test_put_update_with_invalid_spent_time_comments_only
2584 2593 @request.session[:user_id] = 2
2585 2594 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2586 2595
2587 2596 assert_no_difference('Journal.count') do
2588 2597 put :update,
2589 2598 :id => 1,
2590 2599 :notes => notes,
2591 2600 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
2592 2601 end
2593 2602 assert_response :success
2594 2603 assert_template 'edit'
2595 2604
2596 2605 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2597 2606 assert_error_tag :descendant => {:content => /Hours can't be blank/}
2598 2607 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2599 2608 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
2600 2609 end
2601 2610
2602 2611 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
2603 2612 issue = Issue.find(2)
2604 2613 @request.session[:user_id] = 2
2605 2614
2606 2615 put :update,
2607 2616 :id => issue.id,
2608 2617 :issue => {
2609 2618 :fixed_version_id => 4
2610 2619 }
2611 2620
2612 2621 assert_response :redirect
2613 2622 issue.reload
2614 2623 assert_equal 4, issue.fixed_version_id
2615 2624 assert_not_equal issue.project_id, issue.fixed_version.project_id
2616 2625 end
2617 2626
2618 2627 def test_put_update_should_redirect_back_using_the_back_url_parameter
2619 2628 issue = Issue.find(2)
2620 2629 @request.session[:user_id] = 2
2621 2630
2622 2631 put :update,
2623 2632 :id => issue.id,
2624 2633 :issue => {
2625 2634 :fixed_version_id => 4
2626 2635 },
2627 2636 :back_url => '/issues'
2628 2637
2629 2638 assert_response :redirect
2630 2639 assert_redirected_to '/issues'
2631 2640 end
2632 2641
2633 2642 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
2634 2643 issue = Issue.find(2)
2635 2644 @request.session[:user_id] = 2
2636 2645
2637 2646 put :update,
2638 2647 :id => issue.id,
2639 2648 :issue => {
2640 2649 :fixed_version_id => 4
2641 2650 },
2642 2651 :back_url => 'http://google.com'
2643 2652
2644 2653 assert_response :redirect
2645 2654 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
2646 2655 end
2647 2656
2648 2657 def test_get_bulk_edit
2649 2658 @request.session[:user_id] = 2
2650 2659 get :bulk_edit, :ids => [1, 2]
2651 2660 assert_response :success
2652 2661 assert_template 'bulk_edit'
2653 2662
2654 2663 assert_tag :select, :attributes => {:name => 'issue[project_id]'}
2655 2664 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2656 2665
2657 2666 # Project specific custom field, date type
2658 2667 field = CustomField.find(9)
2659 2668 assert !field.is_for_all?
2660 2669 assert_equal 'date', field.field_format
2661 2670 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2662 2671
2663 2672 # System wide custom field
2664 2673 assert CustomField.find(1).is_for_all?
2665 2674 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
2666 2675
2667 2676 # Be sure we don't display inactive IssuePriorities
2668 2677 assert ! IssuePriority.find(15).active?
2669 2678 assert_no_tag :option, :attributes => {:value => '15'},
2670 2679 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2671 2680 end
2672 2681
2673 2682 def test_get_bulk_edit_on_different_projects
2674 2683 @request.session[:user_id] = 2
2675 2684 get :bulk_edit, :ids => [1, 2, 6]
2676 2685 assert_response :success
2677 2686 assert_template 'bulk_edit'
2678 2687
2679 2688 # Can not set issues from different projects as children of an issue
2680 2689 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2681 2690
2682 2691 # Project specific custom field, date type
2683 2692 field = CustomField.find(9)
2684 2693 assert !field.is_for_all?
2685 2694 assert !field.project_ids.include?(Issue.find(6).project_id)
2686 2695 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2687 2696 end
2688 2697
2689 2698 def test_get_bulk_edit_with_user_custom_field
2690 2699 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => 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][#{field.id}]"},
2699 2708 :children => {
2700 2709 :only => {:tag => 'option'},
2701 2710 :count => Project.find(1).users.count + 2 # "no change" + "none" options
2702 2711 }
2703 2712 end
2704 2713
2705 2714 def test_get_bulk_edit_with_version_custom_field
2706 2715 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
2707 2716
2708 2717 @request.session[:user_id] = 2
2709 2718 get :bulk_edit, :ids => [1, 2]
2710 2719 assert_response :success
2711 2720 assert_template 'bulk_edit'
2712 2721
2713 2722 assert_tag :select,
2714 2723 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2715 2724 :children => {
2716 2725 :only => {:tag => 'option'},
2717 2726 :count => Project.find(1).shared_versions.count + 2 # "no change" + "none" options
2718 2727 }
2719 2728 end
2720 2729
2721 2730 def test_get_bulk_edit_with_multi_custom_field
2722 2731 field = CustomField.find(1)
2723 2732 field.update_attribute :multiple, true
2724 2733
2725 2734 @request.session[:user_id] = 2
2726 2735 get :bulk_edit, :ids => [1, 2]
2727 2736 assert_response :success
2728 2737 assert_template 'bulk_edit'
2729 2738
2730 2739 assert_tag :select,
2731 2740 :attributes => {:name => "issue[custom_field_values][1][]"},
2732 2741 :children => {
2733 2742 :only => {:tag => 'option'},
2734 2743 :count => field.possible_values.size + 1 # "none" options
2735 2744 }
2736 2745 end
2737 2746
2738 2747 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
2739 2748 Workflow.delete_all
2740 2749 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1)
2741 2750 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
2742 2751 Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
2743 2752 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
2744 2753 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
2745 2754 Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
2746 2755 @request.session[:user_id] = 2
2747 2756 get :bulk_edit, :ids => [1, 2]
2748 2757
2749 2758 assert_response :success
2750 2759 statuses = assigns(:available_statuses)
2751 2760 assert_not_nil statuses
2752 2761 assert_equal [1, 3], statuses.map(&:id).sort
2753 2762
2754 2763 assert_tag 'select', :attributes => {:name => 'issue[status_id]'},
2755 2764 :children => {:count => 3} # 2 statuses + "no change" option
2756 2765 end
2757 2766
2758 2767 def test_bulk_edit_should_propose_target_project_open_shared_versions
2759 2768 @request.session[:user_id] = 2
2760 2769 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
2761 2770 assert_response :success
2762 2771 assert_template 'bulk_edit'
2763 2772 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort
2764 2773 assert_tag 'select',
2765 2774 :attributes => {:name => 'issue[fixed_version_id]'},
2766 2775 :descendant => {:tag => 'option', :content => '2.0'}
2767 2776 end
2768 2777
2769 2778 def test_bulk_edit_should_propose_target_project_categories
2770 2779 @request.session[:user_id] = 2
2771 2780 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
2772 2781 assert_response :success
2773 2782 assert_template 'bulk_edit'
2774 2783 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort
2775 2784 assert_tag 'select',
2776 2785 :attributes => {:name => 'issue[category_id]'},
2777 2786 :descendant => {:tag => 'option', :content => 'Recipes'}
2778 2787 end
2779 2788
2780 2789 def test_bulk_update
2781 2790 @request.session[:user_id] = 2
2782 2791 # update issues priority
2783 2792 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2784 2793 :issue => {:priority_id => 7,
2785 2794 :assigned_to_id => '',
2786 2795 :custom_field_values => {'2' => ''}}
2787 2796
2788 2797 assert_response 302
2789 2798 # check that the issues were updated
2790 2799 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
2791 2800
2792 2801 issue = Issue.find(1)
2793 2802 journal = issue.journals.find(:first, :order => 'created_on DESC')
2794 2803 assert_equal '125', issue.custom_value_for(2).value
2795 2804 assert_equal 'Bulk editing', journal.notes
2796 2805 assert_equal 1, journal.details.size
2797 2806 end
2798 2807
2799 2808 def test_bulk_update_with_group_assignee
2800 2809 group = Group.find(11)
2801 2810 project = Project.find(1)
2802 2811 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
2803 2812
2804 2813 @request.session[:user_id] = 2
2805 2814 # update issues assignee
2806 2815 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2807 2816 :issue => {:priority_id => '',
2808 2817 :assigned_to_id => group.id,
2809 2818 :custom_field_values => {'2' => ''}}
2810 2819
2811 2820 assert_response 302
2812 2821 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
2813 2822 end
2814 2823
2815 2824 def test_bulk_update_on_different_projects
2816 2825 @request.session[:user_id] = 2
2817 2826 # update issues priority
2818 2827 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
2819 2828 :issue => {:priority_id => 7,
2820 2829 :assigned_to_id => '',
2821 2830 :custom_field_values => {'2' => ''}}
2822 2831
2823 2832 assert_response 302
2824 2833 # check that the issues were updated
2825 2834 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
2826 2835
2827 2836 issue = Issue.find(1)
2828 2837 journal = issue.journals.find(:first, :order => 'created_on DESC')
2829 2838 assert_equal '125', issue.custom_value_for(2).value
2830 2839 assert_equal 'Bulk editing', journal.notes
2831 2840 assert_equal 1, journal.details.size
2832 2841 end
2833 2842
2834 2843 def test_bulk_update_on_different_projects_without_rights
2835 2844 @request.session[:user_id] = 3
2836 2845 user = User.find(3)
2837 2846 action = { :controller => "issues", :action => "bulk_update" }
2838 2847 assert user.allowed_to?(action, Issue.find(1).project)
2839 2848 assert ! user.allowed_to?(action, Issue.find(6).project)
2840 2849 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
2841 2850 :issue => {:priority_id => 7,
2842 2851 :assigned_to_id => '',
2843 2852 :custom_field_values => {'2' => ''}}
2844 2853 assert_response 403
2845 2854 assert_not_equal "Bulk should fail", Journal.last.notes
2846 2855 end
2847 2856
2848 2857 def test_bullk_update_should_send_a_notification
2849 2858 @request.session[:user_id] = 2
2850 2859 ActionMailer::Base.deliveries.clear
2851 2860 post(:bulk_update,
2852 2861 {
2853 2862 :ids => [1, 2],
2854 2863 :notes => 'Bulk editing',
2855 2864 :issue => {
2856 2865 :priority_id => 7,
2857 2866 :assigned_to_id => '',
2858 2867 :custom_field_values => {'2' => ''}
2859 2868 }
2860 2869 })
2861 2870
2862 2871 assert_response 302
2863 2872 assert_equal 2, ActionMailer::Base.deliveries.size
2864 2873 end
2865 2874
2866 2875 def test_bulk_update_project
2867 2876 @request.session[:user_id] = 2
2868 2877 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
2869 2878 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2870 2879 # Issues moved to project 2
2871 2880 assert_equal 2, Issue.find(1).project_id
2872 2881 assert_equal 2, Issue.find(2).project_id
2873 2882 # No tracker change
2874 2883 assert_equal 1, Issue.find(1).tracker_id
2875 2884 assert_equal 2, Issue.find(2).tracker_id
2876 2885 end
2877 2886
2878 2887 def test_bulk_update_project_on_single_issue_should_follow_when_needed
2879 2888 @request.session[:user_id] = 2
2880 2889 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
2881 2890 assert_redirected_to '/issues/1'
2882 2891 end
2883 2892
2884 2893 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
2885 2894 @request.session[:user_id] = 2
2886 2895 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
2887 2896 assert_redirected_to '/projects/onlinestore/issues'
2888 2897 end
2889 2898
2890 2899 def test_bulk_update_tracker
2891 2900 @request.session[:user_id] = 2
2892 2901 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
2893 2902 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2894 2903 assert_equal 2, Issue.find(1).tracker_id
2895 2904 assert_equal 2, Issue.find(2).tracker_id
2896 2905 end
2897 2906
2898 2907 def test_bulk_update_status
2899 2908 @request.session[:user_id] = 2
2900 2909 # update issues priority
2901 2910 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
2902 2911 :issue => {:priority_id => '',
2903 2912 :assigned_to_id => '',
2904 2913 :status_id => '5'}
2905 2914
2906 2915 assert_response 302
2907 2916 issue = Issue.find(1)
2908 2917 assert issue.closed?
2909 2918 end
2910 2919
2911 2920 def test_bulk_update_priority
2912 2921 @request.session[:user_id] = 2
2913 2922 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
2914 2923
2915 2924 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2916 2925 assert_equal 6, Issue.find(1).priority_id
2917 2926 assert_equal 6, Issue.find(2).priority_id
2918 2927 end
2919 2928
2920 2929 def test_bulk_update_with_notes
2921 2930 @request.session[:user_id] = 2
2922 2931 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
2923 2932
2924 2933 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2925 2934 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
2926 2935 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
2927 2936 end
2928 2937
2929 2938 def test_bulk_update_parent_id
2930 2939 @request.session[:user_id] = 2
2931 2940 post :bulk_update, :ids => [1, 3],
2932 2941 :notes => 'Bulk editing parent',
2933 2942 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
2934 2943
2935 2944 assert_response 302
2936 2945 parent = Issue.find(2)
2937 2946 assert_equal parent.id, Issue.find(1).parent_id
2938 2947 assert_equal parent.id, Issue.find(3).parent_id
2939 2948 assert_equal [1, 3], parent.children.collect(&:id).sort
2940 2949 end
2941 2950
2942 2951 def test_bulk_update_custom_field
2943 2952 @request.session[:user_id] = 2
2944 2953 # update issues priority
2945 2954 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
2946 2955 :issue => {:priority_id => '',
2947 2956 :assigned_to_id => '',
2948 2957 :custom_field_values => {'2' => '777'}}
2949 2958
2950 2959 assert_response 302
2951 2960
2952 2961 issue = Issue.find(1)
2953 2962 journal = issue.journals.find(:first, :order => 'created_on DESC')
2954 2963 assert_equal '777', issue.custom_value_for(2).value
2955 2964 assert_equal 1, journal.details.size
2956 2965 assert_equal '125', journal.details.first.old_value
2957 2966 assert_equal '777', journal.details.first.value
2958 2967 end
2959 2968
2960 2969 def test_bulk_update_custom_field_to_blank
2961 2970 @request.session[:user_id] = 2
2962 2971 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing custom field',
2963 2972 :issue => {:priority_id => '',
2964 2973 :assigned_to_id => '',
2965 2974 :custom_field_values => {'1' => '__none__'}}
2966 2975 assert_response 302
2967 2976 assert_equal '', Issue.find(1).custom_field_value(1)
2968 2977 assert_equal '', Issue.find(3).custom_field_value(1)
2969 2978 end
2970 2979
2971 2980 def test_bulk_update_multi_custom_field
2972 2981 field = CustomField.find(1)
2973 2982 field.update_attribute :multiple, true
2974 2983
2975 2984 @request.session[:user_id] = 2
2976 2985 post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field',
2977 2986 :issue => {:priority_id => '',
2978 2987 :assigned_to_id => '',
2979 2988 :custom_field_values => {'1' => ['MySQL', 'Oracle']}}
2980 2989
2981 2990 assert_response 302
2982 2991
2983 2992 assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort
2984 2993 assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort
2985 2994 # the custom field is not associated with the issue tracker
2986 2995 assert_nil Issue.find(2).custom_field_value(1)
2987 2996 end
2988 2997
2989 2998 def test_bulk_update_multi_custom_field_to_blank
2990 2999 field = CustomField.find(1)
2991 3000 field.update_attribute :multiple, true
2992 3001
2993 3002 @request.session[:user_id] = 2
2994 3003 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing multi custom field',
2995 3004 :issue => {:priority_id => '',
2996 3005 :assigned_to_id => '',
2997 3006 :custom_field_values => {'1' => ['__none__']}}
2998 3007 assert_response 302
2999 3008 assert_equal [''], Issue.find(1).custom_field_value(1)
3000 3009 assert_equal [''], Issue.find(3).custom_field_value(1)
3001 3010 end
3002 3011
3003 3012 def test_bulk_update_unassign
3004 3013 assert_not_nil Issue.find(2).assigned_to
3005 3014 @request.session[:user_id] = 2
3006 3015 # unassign issues
3007 3016 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
3008 3017 assert_response 302
3009 3018 # check that the issues were updated
3010 3019 assert_nil Issue.find(2).assigned_to
3011 3020 end
3012 3021
3013 3022 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
3014 3023 @request.session[:user_id] = 2
3015 3024
3016 3025 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
3017 3026
3018 3027 assert_response :redirect
3019 3028 issues = Issue.find([1,2])
3020 3029 issues.each do |issue|
3021 3030 assert_equal 4, issue.fixed_version_id
3022 3031 assert_not_equal issue.project_id, issue.fixed_version.project_id
3023 3032 end
3024 3033 end
3025 3034
3026 3035 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
3027 3036 @request.session[:user_id] = 2
3028 3037 post :bulk_update, :ids => [1,2], :back_url => '/issues'
3029 3038
3030 3039 assert_response :redirect
3031 3040 assert_redirected_to '/issues'
3032 3041 end
3033 3042
3034 3043 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
3035 3044 @request.session[:user_id] = 2
3036 3045 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
3037 3046
3038 3047 assert_response :redirect
3039 3048 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
3040 3049 end
3041 3050
3042 3051 def test_bulk_update_with_failure_should_set_flash
3043 3052 @request.session[:user_id] = 2
3044 3053 Issue.update_all("subject = ''", "id = 2") # Make it invalid
3045 3054 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
3046 3055
3047 3056 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3048 3057 assert_equal 'Failed to save 1 issue(s) on 2 selected: #2.', flash[:error]
3049 3058 end
3050 3059
3051 3060 def test_bulk_copy_to_another_project
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], :issue => {:project_id => '2'}, :copy => '1'
3056 3065 end
3057 3066 end
3058 3067 assert_redirected_to '/projects/ecookbook/issues'
3059 3068 end
3060 3069
3061 3070 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
3062 3071 @request.session[:user_id] = 2
3063 3072 issue_before_move = Issue.find(1)
3064 3073 assert_difference 'Issue.count', 1 do
3065 3074 assert_no_difference 'Project.find(1).issues.count' do
3066 3075 post :bulk_update, :ids => [1], :copy => '1',
3067 3076 :issue => {
3068 3077 :project_id => '2', :tracker_id => '', :assigned_to_id => '',
3069 3078 :status_id => '', :start_date => '', :due_date => ''
3070 3079 }
3071 3080 end
3072 3081 end
3073 3082 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
3074 3083 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
3075 3084 assert_equal issue_before_move.status_id, issue_after_move.status_id
3076 3085 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
3077 3086 end
3078 3087
3079 3088 def test_bulk_copy_should_allow_changing_the_issue_attributes
3080 3089 # Fixes random test failure with Mysql
3081 3090 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
3082 3091 # doesn't return the expected results
3083 3092 Issue.delete_all("project_id=2")
3084 3093
3085 3094 @request.session[:user_id] = 2
3086 3095 assert_difference 'Issue.count', 2 do
3087 3096 assert_no_difference 'Project.find(1).issues.count' do
3088 3097 post :bulk_update, :ids => [1, 2], :copy => '1',
3089 3098 :issue => {
3090 3099 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
3091 3100 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
3092 3101 }
3093 3102 end
3094 3103 end
3095 3104
3096 3105 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
3097 3106 assert_equal 2, copied_issues.size
3098 3107 copied_issues.each do |issue|
3099 3108 assert_equal 2, issue.project_id, "Project is incorrect"
3100 3109 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
3101 3110 assert_equal 3, issue.status_id, "Status is incorrect"
3102 3111 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
3103 3112 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
3104 3113 end
3105 3114 end
3106 3115
3107 3116 def test_bulk_copy_should_allow_adding_a_note
3108 3117 @request.session[:user_id] = 2
3109 3118 assert_difference 'Issue.count', 1 do
3110 3119 post :bulk_update, :ids => [1], :copy => '1',
3111 3120 :notes => 'Copying one issue',
3112 3121 :issue => {
3113 3122 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
3114 3123 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
3115 3124 }
3116 3125 end
3117 3126
3118 3127 issue = Issue.first(:order => 'id DESC')
3119 3128 assert_equal 1, issue.journals.size
3120 3129 journal = issue.journals.first
3121 3130 assert_equal 0, journal.details.size
3122 3131 assert_equal 'Copying one issue', journal.notes
3123 3132 end
3124 3133
3125 3134 def test_bulk_copy_to_another_project_should_follow_when_needed
3126 3135 @request.session[:user_id] = 2
3127 3136 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
3128 3137 issue = Issue.first(:order => 'id DESC')
3129 3138 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
3130 3139 end
3131 3140
3132 3141 def test_destroy_issue_with_no_time_entries
3133 3142 assert_nil TimeEntry.find_by_issue_id(2)
3134 3143 @request.session[:user_id] = 2
3135 3144
3136 3145 assert_difference 'Issue.count', -1 do
3137 3146 delete :destroy, :id => 2
3138 3147 end
3139 3148 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3140 3149 assert_nil Issue.find_by_id(2)
3141 3150 end
3142 3151
3143 3152 def test_destroy_issues_with_time_entries
3144 3153 @request.session[:user_id] = 2
3145 3154
3146 3155 assert_no_difference 'Issue.count' do
3147 3156 delete :destroy, :ids => [1, 3]
3148 3157 end
3149 3158 assert_response :success
3150 3159 assert_template 'destroy'
3151 3160 assert_not_nil assigns(:hours)
3152 3161 assert Issue.find_by_id(1) && Issue.find_by_id(3)
3153 3162 assert_tag 'form',
3154 3163 :descendant => {:tag => 'input', :attributes => {:name => '_method', :value => 'delete'}}
3155 3164 end
3156 3165
3157 3166 def test_destroy_issues_and_destroy_time_entries
3158 3167 @request.session[:user_id] = 2
3159 3168
3160 3169 assert_difference 'Issue.count', -2 do
3161 3170 assert_difference 'TimeEntry.count', -3 do
3162 3171 delete :destroy, :ids => [1, 3], :todo => 'destroy'
3163 3172 end
3164 3173 end
3165 3174 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3166 3175 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3167 3176 assert_nil TimeEntry.find_by_id([1, 2])
3168 3177 end
3169 3178
3170 3179 def test_destroy_issues_and_assign_time_entries_to_project
3171 3180 @request.session[:user_id] = 2
3172 3181
3173 3182 assert_difference 'Issue.count', -2 do
3174 3183 assert_no_difference 'TimeEntry.count' do
3175 3184 delete :destroy, :ids => [1, 3], :todo => 'nullify'
3176 3185 end
3177 3186 end
3178 3187 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3179 3188 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3180 3189 assert_nil TimeEntry.find(1).issue_id
3181 3190 assert_nil TimeEntry.find(2).issue_id
3182 3191 end
3183 3192
3184 3193 def test_destroy_issues_and_reassign_time_entries_to_another_issue
3185 3194 @request.session[:user_id] = 2
3186 3195
3187 3196 assert_difference 'Issue.count', -2 do
3188 3197 assert_no_difference 'TimeEntry.count' do
3189 3198 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
3190 3199 end
3191 3200 end
3192 3201 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3193 3202 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3194 3203 assert_equal 2, TimeEntry.find(1).issue_id
3195 3204 assert_equal 2, TimeEntry.find(2).issue_id
3196 3205 end
3197 3206
3198 3207 def test_destroy_issues_from_different_projects
3199 3208 @request.session[:user_id] = 2
3200 3209
3201 3210 assert_difference 'Issue.count', -3 do
3202 3211 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
3203 3212 end
3204 3213 assert_redirected_to :controller => 'issues', :action => 'index'
3205 3214 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
3206 3215 end
3207 3216
3208 3217 def test_destroy_parent_and_child_issues
3209 3218 parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue')
3210 3219 child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id)
3211 3220 assert child.is_descendant_of?(parent.reload)
3212 3221
3213 3222 @request.session[:user_id] = 2
3214 3223 assert_difference 'Issue.count', -2 do
3215 3224 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
3216 3225 end
3217 3226 assert_response 302
3218 3227 end
3219 3228
3220 3229 def test_default_search_scope
3221 3230 get :index
3222 3231 assert_tag :div, :attributes => {:id => 'quick-search'},
3223 3232 :child => {:tag => 'form',
3224 3233 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
3225 3234 end
3226 3235 end
General Comments 0
You need to be logged in to leave comments. Login now