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