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