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