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