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