##// END OF EJS Templates
remove hard-coded '.rhtml' from "test_index_with_project_and_filter" of functional issues controller test (#6317)....
Toshi MARUYAMA -
r6922:de9e3f94d547
parent child
Show More
@@ -1,1614 +1,1614
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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 require 'issues_controller'
19 require 'issues_controller'
20
20
21 class IssuesControllerTest < ActionController::TestCase
21 class IssuesControllerTest < ActionController::TestCase
22 fixtures :projects,
22 fixtures :projects,
23 :users,
23 :users,
24 :roles,
24 :roles,
25 :members,
25 :members,
26 :member_roles,
26 :member_roles,
27 :issues,
27 :issues,
28 :issue_statuses,
28 :issue_statuses,
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
45
46 def setup
46 def setup
47 @controller = IssuesController.new
47 @controller = IssuesController.new
48 @request = ActionController::TestRequest.new
48 @request = ActionController::TestRequest.new
49 @response = ActionController::TestResponse.new
49 @response = ActionController::TestResponse.new
50 User.current = nil
50 User.current = nil
51 end
51 end
52
52
53 def test_index
53 def test_index
54 Setting.default_language = 'en'
54 Setting.default_language = 'en'
55
55
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 assert_tag :tag => 'a', :content => /Can't print recipes/
61 assert_tag :tag => 'a', :content => /Can't print recipes/
62 assert_tag :tag => 'a', :content => /Subproject issue/
62 assert_tag :tag => 'a', :content => /Subproject issue/
63 # private projects hidden
63 # private projects hidden
64 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
64 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
65 assert_no_tag :tag => 'a', :content => /Issue on project 2/
65 assert_no_tag :tag => 'a', :content => /Issue on project 2/
66 # project column
66 # project column
67 assert_tag :tag => 'th', :content => /Project/
67 assert_tag :tag => 'th', :content => /Project/
68 end
68 end
69
69
70 def test_index_should_not_list_issues_when_module_disabled
70 def test_index_should_not_list_issues_when_module_disabled
71 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
71 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
72 get :index
72 get :index
73 assert_response :success
73 assert_response :success
74 assert_template 'index'
74 assert_template 'index'
75 assert_not_nil assigns(:issues)
75 assert_not_nil assigns(:issues)
76 assert_nil assigns(:project)
76 assert_nil assigns(:project)
77 assert_no_tag :tag => 'a', :content => /Can't print recipes/
77 assert_no_tag :tag => 'a', :content => /Can't print recipes/
78 assert_tag :tag => 'a', :content => /Subproject issue/
78 assert_tag :tag => 'a', :content => /Subproject issue/
79 end
79 end
80
80
81 def test_index_should_list_visible_issues_only
81 def test_index_should_list_visible_issues_only
82 get :index, :per_page => 100
82 get :index, :per_page => 100
83 assert_response :success
83 assert_response :success
84 assert_not_nil assigns(:issues)
84 assert_not_nil assigns(:issues)
85 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
85 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
86 end
86 end
87
87
88 def test_index_with_project
88 def test_index_with_project
89 Setting.display_subprojects_issues = 0
89 Setting.display_subprojects_issues = 0
90 get :index, :project_id => 1
90 get :index, :project_id => 1
91 assert_response :success
91 assert_response :success
92 assert_template 'index'
92 assert_template 'index'
93 assert_not_nil assigns(:issues)
93 assert_not_nil assigns(:issues)
94 assert_tag :tag => 'a', :content => /Can't print recipes/
94 assert_tag :tag => 'a', :content => /Can't print recipes/
95 assert_no_tag :tag => 'a', :content => /Subproject issue/
95 assert_no_tag :tag => 'a', :content => /Subproject issue/
96 end
96 end
97
97
98 def test_index_with_project_and_subprojects
98 def test_index_with_project_and_subprojects
99 Setting.display_subprojects_issues = 1
99 Setting.display_subprojects_issues = 1
100 get :index, :project_id => 1
100 get :index, :project_id => 1
101 assert_response :success
101 assert_response :success
102 assert_template 'index'
102 assert_template 'index'
103 assert_not_nil assigns(:issues)
103 assert_not_nil assigns(:issues)
104 assert_tag :tag => 'a', :content => /Can't print recipes/
104 assert_tag :tag => 'a', :content => /Can't print recipes/
105 assert_tag :tag => 'a', :content => /Subproject issue/
105 assert_tag :tag => 'a', :content => /Subproject issue/
106 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
106 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
107 end
107 end
108
108
109 def test_index_with_project_and_subprojects_should_show_private_subprojects
109 def test_index_with_project_and_subprojects_should_show_private_subprojects
110 @request.session[:user_id] = 2
110 @request.session[:user_id] = 2
111 Setting.display_subprojects_issues = 1
111 Setting.display_subprojects_issues = 1
112 get :index, :project_id => 1
112 get :index, :project_id => 1
113 assert_response :success
113 assert_response :success
114 assert_template 'index'
114 assert_template 'index'
115 assert_not_nil assigns(:issues)
115 assert_not_nil assigns(:issues)
116 assert_tag :tag => 'a', :content => /Can't print recipes/
116 assert_tag :tag => 'a', :content => /Can't print recipes/
117 assert_tag :tag => 'a', :content => /Subproject issue/
117 assert_tag :tag => 'a', :content => /Subproject issue/
118 assert_tag :tag => 'a', :content => /Issue of a private subproject/
118 assert_tag :tag => 'a', :content => /Issue of a private subproject/
119 end
119 end
120
120
121 def test_index_with_project_and_default_filter
121 def test_index_with_project_and_default_filter
122 get :index, :project_id => 1, :set_filter => 1
122 get :index, :project_id => 1, :set_filter => 1
123 assert_response :success
123 assert_response :success
124 assert_template 'index'
124 assert_template 'index'
125 assert_not_nil assigns(:issues)
125 assert_not_nil assigns(:issues)
126
126
127 query = assigns(:query)
127 query = assigns(:query)
128 assert_not_nil query
128 assert_not_nil query
129 # default filter
129 # default filter
130 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
130 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
131 end
131 end
132
132
133 def test_index_with_project_and_filter
133 def test_index_with_project_and_filter
134 get :index, :project_id => 1, :set_filter => 1,
134 get :index, :project_id => 1, :set_filter => 1,
135 :f => ['tracker_id'],
135 :f => ['tracker_id'],
136 :op => {'tracker_id' => '='},
136 :op => {'tracker_id' => '='},
137 :v => {'tracker_id' => ['1']}
137 :v => {'tracker_id' => ['1']}
138 assert_response :success
138 assert_response :success
139 assert_template 'index.rhtml'
139 assert_template 'index'
140 assert_not_nil assigns(:issues)
140 assert_not_nil assigns(:issues)
141
141
142 query = assigns(:query)
142 query = assigns(:query)
143 assert_not_nil query
143 assert_not_nil query
144 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
144 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
145 end
145 end
146
146
147 def test_index_with_project_and_empty_filters
147 def test_index_with_project_and_empty_filters
148 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
148 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
149 assert_response :success
149 assert_response :success
150 assert_template 'index'
150 assert_template 'index'
151 assert_not_nil assigns(:issues)
151 assert_not_nil assigns(:issues)
152
152
153 query = assigns(:query)
153 query = assigns(:query)
154 assert_not_nil query
154 assert_not_nil query
155 # no filter
155 # no filter
156 assert_equal({}, query.filters)
156 assert_equal({}, query.filters)
157 end
157 end
158
158
159 def test_index_with_query
159 def test_index_with_query
160 get :index, :project_id => 1, :query_id => 5
160 get :index, :project_id => 1, :query_id => 5
161 assert_response :success
161 assert_response :success
162 assert_template 'index'
162 assert_template 'index'
163 assert_not_nil assigns(:issues)
163 assert_not_nil assigns(:issues)
164 assert_nil assigns(:issue_count_by_group)
164 assert_nil assigns(:issue_count_by_group)
165 end
165 end
166
166
167 def test_index_with_query_grouped_by_tracker
167 def test_index_with_query_grouped_by_tracker
168 get :index, :project_id => 1, :query_id => 6
168 get :index, :project_id => 1, :query_id => 6
169 assert_response :success
169 assert_response :success
170 assert_template 'index'
170 assert_template 'index'
171 assert_not_nil assigns(:issues)
171 assert_not_nil assigns(:issues)
172 assert_not_nil assigns(:issue_count_by_group)
172 assert_not_nil assigns(:issue_count_by_group)
173 end
173 end
174
174
175 def test_index_with_query_grouped_by_list_custom_field
175 def test_index_with_query_grouped_by_list_custom_field
176 get :index, :project_id => 1, :query_id => 9
176 get :index, :project_id => 1, :query_id => 9
177 assert_response :success
177 assert_response :success
178 assert_template 'index'
178 assert_template 'index'
179 assert_not_nil assigns(:issues)
179 assert_not_nil assigns(:issues)
180 assert_not_nil assigns(:issue_count_by_group)
180 assert_not_nil assigns(:issue_count_by_group)
181 end
181 end
182
182
183 def test_private_query_should_not_be_available_to_other_users
183 def test_private_query_should_not_be_available_to_other_users
184 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
184 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
185 @request.session[:user_id] = 3
185 @request.session[:user_id] = 3
186
186
187 get :index, :query_id => q.id
187 get :index, :query_id => q.id
188 assert_response 403
188 assert_response 403
189 end
189 end
190
190
191 def test_private_query_should_be_available_to_its_user
191 def test_private_query_should_be_available_to_its_user
192 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
192 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
193 @request.session[:user_id] = 2
193 @request.session[:user_id] = 2
194
194
195 get :index, :query_id => q.id
195 get :index, :query_id => q.id
196 assert_response :success
196 assert_response :success
197 end
197 end
198
198
199 def test_public_query_should_be_available_to_other_users
199 def test_public_query_should_be_available_to_other_users
200 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
200 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
201 @request.session[:user_id] = 3
201 @request.session[:user_id] = 3
202
202
203 get :index, :query_id => q.id
203 get :index, :query_id => q.id
204 assert_response :success
204 assert_response :success
205 end
205 end
206
206
207 def test_index_sort_by_field_not_included_in_columns
207 def test_index_sort_by_field_not_included_in_columns
208 Setting.issue_list_default_columns = %w(subject author)
208 Setting.issue_list_default_columns = %w(subject author)
209 get :index, :sort => 'tracker'
209 get :index, :sort => 'tracker'
210 end
210 end
211
211
212 def test_index_csv_with_project
212 def test_index_csv_with_project
213 Setting.default_language = 'en'
213 Setting.default_language = 'en'
214
214
215 get :index, :format => 'csv'
215 get :index, :format => 'csv'
216 assert_response :success
216 assert_response :success
217 assert_not_nil assigns(:issues)
217 assert_not_nil assigns(:issues)
218 assert_equal 'text/csv', @response.content_type
218 assert_equal 'text/csv', @response.content_type
219 assert @response.body.starts_with?("#,")
219 assert @response.body.starts_with?("#,")
220
220
221 get :index, :project_id => 1, :format => 'csv'
221 get :index, :project_id => 1, :format => 'csv'
222 assert_response :success
222 assert_response :success
223 assert_not_nil assigns(:issues)
223 assert_not_nil assigns(:issues)
224 assert_equal 'text/csv', @response.content_type
224 assert_equal 'text/csv', @response.content_type
225 end
225 end
226
226
227 def test_index_pdf
227 def test_index_pdf
228 get :index, :format => 'pdf'
228 get :index, :format => 'pdf'
229 assert_response :success
229 assert_response :success
230 assert_not_nil assigns(:issues)
230 assert_not_nil assigns(:issues)
231 assert_equal 'application/pdf', @response.content_type
231 assert_equal 'application/pdf', @response.content_type
232
232
233 get :index, :project_id => 1, :format => 'pdf'
233 get :index, :project_id => 1, :format => 'pdf'
234 assert_response :success
234 assert_response :success
235 assert_not_nil assigns(:issues)
235 assert_not_nil assigns(:issues)
236 assert_equal 'application/pdf', @response.content_type
236 assert_equal 'application/pdf', @response.content_type
237
237
238 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
238 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
239 assert_response :success
239 assert_response :success
240 assert_not_nil assigns(:issues)
240 assert_not_nil assigns(:issues)
241 assert_equal 'application/pdf', @response.content_type
241 assert_equal 'application/pdf', @response.content_type
242 end
242 end
243
243
244 def test_index_pdf_with_query_grouped_by_list_custom_field
244 def test_index_pdf_with_query_grouped_by_list_custom_field
245 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
245 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
246 assert_response :success
246 assert_response :success
247 assert_not_nil assigns(:issues)
247 assert_not_nil assigns(:issues)
248 assert_not_nil assigns(:issue_count_by_group)
248 assert_not_nil assigns(:issue_count_by_group)
249 assert_equal 'application/pdf', @response.content_type
249 assert_equal 'application/pdf', @response.content_type
250 end
250 end
251
251
252 def test_index_sort
252 def test_index_sort
253 get :index, :sort => 'tracker,id:desc'
253 get :index, :sort => 'tracker,id:desc'
254 assert_response :success
254 assert_response :success
255
255
256 sort_params = @request.session['issues_index_sort']
256 sort_params = @request.session['issues_index_sort']
257 assert sort_params.is_a?(String)
257 assert sort_params.is_a?(String)
258 assert_equal 'tracker,id:desc', sort_params
258 assert_equal 'tracker,id:desc', sort_params
259
259
260 issues = assigns(:issues)
260 issues = assigns(:issues)
261 assert_not_nil issues
261 assert_not_nil issues
262 assert !issues.empty?
262 assert !issues.empty?
263 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
263 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
264 end
264 end
265
265
266 def test_index_with_columns
266 def test_index_with_columns
267 columns = ['tracker', 'subject', 'assigned_to']
267 columns = ['tracker', 'subject', 'assigned_to']
268 get :index, :set_filter => 1, :c => columns
268 get :index, :set_filter => 1, :c => columns
269 assert_response :success
269 assert_response :success
270
270
271 # query should use specified columns
271 # query should use specified columns
272 query = assigns(:query)
272 query = assigns(:query)
273 assert_kind_of Query, query
273 assert_kind_of Query, query
274 assert_equal columns, query.column_names.map(&:to_s)
274 assert_equal columns, query.column_names.map(&:to_s)
275
275
276 # columns should be stored in session
276 # columns should be stored in session
277 assert_kind_of Hash, session[:query]
277 assert_kind_of Hash, session[:query]
278 assert_kind_of Array, session[:query][:column_names]
278 assert_kind_of Array, session[:query][:column_names]
279 assert_equal columns, session[:query][:column_names].map(&:to_s)
279 assert_equal columns, session[:query][:column_names].map(&:to_s)
280
280
281 # ensure only these columns are kept in the selected columns list
281 # ensure only these columns are kept in the selected columns list
282 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
282 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
283 :children => { :count => 3 }
283 :children => { :count => 3 }
284 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
284 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
285 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
285 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
286 end
286 end
287
287
288 def test_index_with_custom_field_column
288 def test_index_with_custom_field_column
289 columns = %w(tracker subject cf_2)
289 columns = %w(tracker subject cf_2)
290 get :index, :set_filter => 1, :c => columns
290 get :index, :set_filter => 1, :c => columns
291 assert_response :success
291 assert_response :success
292
292
293 # query should use specified columns
293 # query should use specified columns
294 query = assigns(:query)
294 query = assigns(:query)
295 assert_kind_of Query, query
295 assert_kind_of Query, query
296 assert_equal columns, query.column_names.map(&:to_s)
296 assert_equal columns, query.column_names.map(&:to_s)
297
297
298 assert_tag :td,
298 assert_tag :td,
299 :attributes => {:class => 'cf_2 string'},
299 :attributes => {:class => 'cf_2 string'},
300 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
300 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
301 end
301 end
302
302
303 def test_index_send_html_if_query_is_invalid
303 def test_index_send_html_if_query_is_invalid
304 get :index, :f => ['start_date'], :op => {:start_date => '='}
304 get :index, :f => ['start_date'], :op => {:start_date => '='}
305 assert_equal 'text/html', @response.content_type
305 assert_equal 'text/html', @response.content_type
306 assert_template 'index'
306 assert_template 'index'
307 end
307 end
308
308
309 def test_index_send_nothing_if_query_is_invalid
309 def test_index_send_nothing_if_query_is_invalid
310 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
310 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
311 assert_equal 'text/csv', @response.content_type
311 assert_equal 'text/csv', @response.content_type
312 assert @response.body.blank?
312 assert @response.body.blank?
313 end
313 end
314
314
315 def test_show_by_anonymous
315 def test_show_by_anonymous
316 get :show, :id => 1
316 get :show, :id => 1
317 assert_response :success
317 assert_response :success
318 assert_template 'show'
318 assert_template 'show'
319 assert_not_nil assigns(:issue)
319 assert_not_nil assigns(:issue)
320 assert_equal Issue.find(1), assigns(:issue)
320 assert_equal Issue.find(1), assigns(:issue)
321
321
322 # anonymous role is allowed to add a note
322 # anonymous role is allowed to add a note
323 assert_tag :tag => 'form',
323 assert_tag :tag => 'form',
324 :descendant => { :tag => 'fieldset',
324 :descendant => { :tag => 'fieldset',
325 :child => { :tag => 'legend',
325 :child => { :tag => 'legend',
326 :content => /Notes/ } }
326 :content => /Notes/ } }
327 end
327 end
328
328
329 def test_show_by_manager
329 def test_show_by_manager
330 @request.session[:user_id] = 2
330 @request.session[:user_id] = 2
331 get :show, :id => 1
331 get :show, :id => 1
332 assert_response :success
332 assert_response :success
333
333
334 assert_tag :tag => 'a',
334 assert_tag :tag => 'a',
335 :content => /Quote/
335 :content => /Quote/
336
336
337 assert_tag :tag => 'form',
337 assert_tag :tag => 'form',
338 :descendant => { :tag => 'fieldset',
338 :descendant => { :tag => 'fieldset',
339 :child => { :tag => 'legend',
339 :child => { :tag => 'legend',
340 :content => /Change properties/ } },
340 :content => /Change properties/ } },
341 :descendant => { :tag => 'fieldset',
341 :descendant => { :tag => 'fieldset',
342 :child => { :tag => 'legend',
342 :child => { :tag => 'legend',
343 :content => /Log time/ } },
343 :content => /Log time/ } },
344 :descendant => { :tag => 'fieldset',
344 :descendant => { :tag => 'fieldset',
345 :child => { :tag => 'legend',
345 :child => { :tag => 'legend',
346 :content => /Notes/ } }
346 :content => /Notes/ } }
347 end
347 end
348
348
349 def test_update_form_should_not_display_inactive_enumerations
349 def test_update_form_should_not_display_inactive_enumerations
350 @request.session[:user_id] = 2
350 @request.session[:user_id] = 2
351 get :show, :id => 1
351 get :show, :id => 1
352 assert_response :success
352 assert_response :success
353
353
354 assert ! IssuePriority.find(15).active?
354 assert ! IssuePriority.find(15).active?
355 assert_no_tag :option, :attributes => {:value => '15'},
355 assert_no_tag :option, :attributes => {:value => '15'},
356 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
356 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
357 end
357 end
358
358
359 def test_update_form_should_allow_attachment_upload
359 def test_update_form_should_allow_attachment_upload
360 @request.session[:user_id] = 2
360 @request.session[:user_id] = 2
361 get :show, :id => 1
361 get :show, :id => 1
362
362
363 assert_tag :tag => 'form',
363 assert_tag :tag => 'form',
364 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
364 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
365 :descendant => {
365 :descendant => {
366 :tag => 'input',
366 :tag => 'input',
367 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
367 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
368 }
368 }
369 end
369 end
370
370
371 def test_show_should_deny_anonymous_access_without_permission
371 def test_show_should_deny_anonymous_access_without_permission
372 Role.anonymous.remove_permission!(:view_issues)
372 Role.anonymous.remove_permission!(:view_issues)
373 get :show, :id => 1
373 get :show, :id => 1
374 assert_response :redirect
374 assert_response :redirect
375 end
375 end
376
376
377 def test_show_should_deny_anonymous_access_to_private_issue
377 def test_show_should_deny_anonymous_access_to_private_issue
378 Issue.update_all(["is_private = ?", true], "id = 1")
378 Issue.update_all(["is_private = ?", true], "id = 1")
379 get :show, :id => 1
379 get :show, :id => 1
380 assert_response :redirect
380 assert_response :redirect
381 end
381 end
382
382
383 def test_show_should_deny_non_member_access_without_permission
383 def test_show_should_deny_non_member_access_without_permission
384 Role.non_member.remove_permission!(:view_issues)
384 Role.non_member.remove_permission!(:view_issues)
385 @request.session[:user_id] = 9
385 @request.session[:user_id] = 9
386 get :show, :id => 1
386 get :show, :id => 1
387 assert_response 403
387 assert_response 403
388 end
388 end
389
389
390 def test_show_should_deny_non_member_access_to_private_issue
390 def test_show_should_deny_non_member_access_to_private_issue
391 Issue.update_all(["is_private = ?", true], "id = 1")
391 Issue.update_all(["is_private = ?", true], "id = 1")
392 @request.session[:user_id] = 9
392 @request.session[:user_id] = 9
393 get :show, :id => 1
393 get :show, :id => 1
394 assert_response 403
394 assert_response 403
395 end
395 end
396
396
397 def test_show_should_deny_member_access_without_permission
397 def test_show_should_deny_member_access_without_permission
398 Role.find(1).remove_permission!(:view_issues)
398 Role.find(1).remove_permission!(:view_issues)
399 @request.session[:user_id] = 2
399 @request.session[:user_id] = 2
400 get :show, :id => 1
400 get :show, :id => 1
401 assert_response 403
401 assert_response 403
402 end
402 end
403
403
404 def test_show_should_deny_member_access_to_private_issue_without_permission
404 def test_show_should_deny_member_access_to_private_issue_without_permission
405 Issue.update_all(["is_private = ?", true], "id = 1")
405 Issue.update_all(["is_private = ?", true], "id = 1")
406 @request.session[:user_id] = 3
406 @request.session[:user_id] = 3
407 get :show, :id => 1
407 get :show, :id => 1
408 assert_response 403
408 assert_response 403
409 end
409 end
410
410
411 def test_show_should_allow_author_access_to_private_issue
411 def test_show_should_allow_author_access_to_private_issue
412 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
412 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
413 @request.session[:user_id] = 3
413 @request.session[:user_id] = 3
414 get :show, :id => 1
414 get :show, :id => 1
415 assert_response :success
415 assert_response :success
416 end
416 end
417
417
418 def test_show_should_allow_assignee_access_to_private_issue
418 def test_show_should_allow_assignee_access_to_private_issue
419 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
419 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
420 @request.session[:user_id] = 3
420 @request.session[:user_id] = 3
421 get :show, :id => 1
421 get :show, :id => 1
422 assert_response :success
422 assert_response :success
423 end
423 end
424
424
425 def test_show_should_allow_member_access_to_private_issue_with_permission
425 def test_show_should_allow_member_access_to_private_issue_with_permission
426 Issue.update_all(["is_private = ?", true], "id = 1")
426 Issue.update_all(["is_private = ?", true], "id = 1")
427 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
427 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
428 @request.session[:user_id] = 3
428 @request.session[:user_id] = 3
429 get :show, :id => 1
429 get :show, :id => 1
430 assert_response :success
430 assert_response :success
431 end
431 end
432
432
433 def test_show_should_not_disclose_relations_to_invisible_issues
433 def test_show_should_not_disclose_relations_to_invisible_issues
434 Setting.cross_project_issue_relations = '1'
434 Setting.cross_project_issue_relations = '1'
435 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
435 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
436 # Relation to a private project issue
436 # Relation to a private project issue
437 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
437 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
438
438
439 get :show, :id => 1
439 get :show, :id => 1
440 assert_response :success
440 assert_response :success
441
441
442 assert_tag :div, :attributes => { :id => 'relations' },
442 assert_tag :div, :attributes => { :id => 'relations' },
443 :descendant => { :tag => 'a', :content => /#2$/ }
443 :descendant => { :tag => 'a', :content => /#2$/ }
444 assert_no_tag :div, :attributes => { :id => 'relations' },
444 assert_no_tag :div, :attributes => { :id => 'relations' },
445 :descendant => { :tag => 'a', :content => /#4$/ }
445 :descendant => { :tag => 'a', :content => /#4$/ }
446 end
446 end
447
447
448 def test_show_atom
448 def test_show_atom
449 get :show, :id => 2, :format => 'atom'
449 get :show, :id => 2, :format => 'atom'
450 assert_response :success
450 assert_response :success
451 assert_template 'journals/index.rxml'
451 assert_template 'journals/index.rxml'
452 # Inline image
452 # Inline image
453 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
453 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
454 end
454 end
455
455
456 def test_show_export_to_pdf
456 def test_show_export_to_pdf
457 get :show, :id => 3, :format => 'pdf'
457 get :show, :id => 3, :format => 'pdf'
458 assert_response :success
458 assert_response :success
459 assert_equal 'application/pdf', @response.content_type
459 assert_equal 'application/pdf', @response.content_type
460 assert @response.body.starts_with?('%PDF')
460 assert @response.body.starts_with?('%PDF')
461 assert_not_nil assigns(:issue)
461 assert_not_nil assigns(:issue)
462 end
462 end
463
463
464 def test_get_new
464 def test_get_new
465 @request.session[:user_id] = 2
465 @request.session[:user_id] = 2
466 get :new, :project_id => 1, :tracker_id => 1
466 get :new, :project_id => 1, :tracker_id => 1
467 assert_response :success
467 assert_response :success
468 assert_template 'new'
468 assert_template 'new'
469
469
470 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
470 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
471 :value => 'Default string' }
471 :value => 'Default string' }
472
472
473 # Be sure we don't display inactive IssuePriorities
473 # Be sure we don't display inactive IssuePriorities
474 assert ! IssuePriority.find(15).active?
474 assert ! IssuePriority.find(15).active?
475 assert_no_tag :option, :attributes => {:value => '15'},
475 assert_no_tag :option, :attributes => {:value => '15'},
476 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
476 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
477 end
477 end
478
478
479 def test_get_new_form_should_allow_attachment_upload
479 def test_get_new_form_should_allow_attachment_upload
480 @request.session[:user_id] = 2
480 @request.session[:user_id] = 2
481 get :new, :project_id => 1, :tracker_id => 1
481 get :new, :project_id => 1, :tracker_id => 1
482
482
483 assert_tag :tag => 'form',
483 assert_tag :tag => 'form',
484 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
484 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
485 :descendant => {
485 :descendant => {
486 :tag => 'input',
486 :tag => 'input',
487 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
487 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
488 }
488 }
489 end
489 end
490
490
491 def test_get_new_without_tracker_id
491 def test_get_new_without_tracker_id
492 @request.session[:user_id] = 2
492 @request.session[:user_id] = 2
493 get :new, :project_id => 1
493 get :new, :project_id => 1
494 assert_response :success
494 assert_response :success
495 assert_template 'new'
495 assert_template 'new'
496
496
497 issue = assigns(:issue)
497 issue = assigns(:issue)
498 assert_not_nil issue
498 assert_not_nil issue
499 assert_equal Project.find(1).trackers.first, issue.tracker
499 assert_equal Project.find(1).trackers.first, issue.tracker
500 end
500 end
501
501
502 def test_get_new_with_no_default_status_should_display_an_error
502 def test_get_new_with_no_default_status_should_display_an_error
503 @request.session[:user_id] = 2
503 @request.session[:user_id] = 2
504 IssueStatus.delete_all
504 IssueStatus.delete_all
505
505
506 get :new, :project_id => 1
506 get :new, :project_id => 1
507 assert_response 500
507 assert_response 500
508 assert_error_tag :content => /No default issue/
508 assert_error_tag :content => /No default issue/
509 end
509 end
510
510
511 def test_get_new_with_no_tracker_should_display_an_error
511 def test_get_new_with_no_tracker_should_display_an_error
512 @request.session[:user_id] = 2
512 @request.session[:user_id] = 2
513 Tracker.delete_all
513 Tracker.delete_all
514
514
515 get :new, :project_id => 1
515 get :new, :project_id => 1
516 assert_response 500
516 assert_response 500
517 assert_error_tag :content => /No tracker/
517 assert_error_tag :content => /No tracker/
518 end
518 end
519
519
520 def test_update_new_form
520 def test_update_new_form
521 @request.session[:user_id] = 2
521 @request.session[:user_id] = 2
522 xhr :post, :new, :project_id => 1,
522 xhr :post, :new, :project_id => 1,
523 :issue => {:tracker_id => 2,
523 :issue => {:tracker_id => 2,
524 :subject => 'This is the test_new issue',
524 :subject => 'This is the test_new issue',
525 :description => 'This is the description',
525 :description => 'This is the description',
526 :priority_id => 5}
526 :priority_id => 5}
527 assert_response :success
527 assert_response :success
528 assert_template 'attributes'
528 assert_template 'attributes'
529
529
530 issue = assigns(:issue)
530 issue = assigns(:issue)
531 assert_kind_of Issue, issue
531 assert_kind_of Issue, issue
532 assert_equal 1, issue.project_id
532 assert_equal 1, issue.project_id
533 assert_equal 2, issue.tracker_id
533 assert_equal 2, issue.tracker_id
534 assert_equal 'This is the test_new issue', issue.subject
534 assert_equal 'This is the test_new issue', issue.subject
535 end
535 end
536
536
537 def test_post_create
537 def test_post_create
538 @request.session[:user_id] = 2
538 @request.session[:user_id] = 2
539 assert_difference 'Issue.count' do
539 assert_difference 'Issue.count' do
540 post :create, :project_id => 1,
540 post :create, :project_id => 1,
541 :issue => {:tracker_id => 3,
541 :issue => {:tracker_id => 3,
542 :status_id => 2,
542 :status_id => 2,
543 :subject => 'This is the test_new issue',
543 :subject => 'This is the test_new issue',
544 :description => 'This is the description',
544 :description => 'This is the description',
545 :priority_id => 5,
545 :priority_id => 5,
546 :start_date => '2010-11-07',
546 :start_date => '2010-11-07',
547 :estimated_hours => '',
547 :estimated_hours => '',
548 :custom_field_values => {'2' => 'Value for field 2'}}
548 :custom_field_values => {'2' => 'Value for field 2'}}
549 end
549 end
550 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
550 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
551
551
552 issue = Issue.find_by_subject('This is the test_new issue')
552 issue = Issue.find_by_subject('This is the test_new issue')
553 assert_not_nil issue
553 assert_not_nil issue
554 assert_equal 2, issue.author_id
554 assert_equal 2, issue.author_id
555 assert_equal 3, issue.tracker_id
555 assert_equal 3, issue.tracker_id
556 assert_equal 2, issue.status_id
556 assert_equal 2, issue.status_id
557 assert_equal Date.parse('2010-11-07'), issue.start_date
557 assert_equal Date.parse('2010-11-07'), issue.start_date
558 assert_nil issue.estimated_hours
558 assert_nil issue.estimated_hours
559 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
559 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
560 assert_not_nil v
560 assert_not_nil v
561 assert_equal 'Value for field 2', v.value
561 assert_equal 'Value for field 2', v.value
562 end
562 end
563
563
564 def test_post_new_with_group_assignment
564 def test_post_new_with_group_assignment
565 group = Group.find(11)
565 group = Group.find(11)
566 project = Project.find(1)
566 project = Project.find(1)
567 project.members << Member.new(:principal => group, :roles => [Role.first])
567 project.members << Member.new(:principal => group, :roles => [Role.first])
568
568
569 with_settings :issue_group_assignment => '1' do
569 with_settings :issue_group_assignment => '1' do
570 @request.session[:user_id] = 2
570 @request.session[:user_id] = 2
571 assert_difference 'Issue.count' do
571 assert_difference 'Issue.count' do
572 post :create, :project_id => project.id,
572 post :create, :project_id => project.id,
573 :issue => {:tracker_id => 3,
573 :issue => {:tracker_id => 3,
574 :status_id => 1,
574 :status_id => 1,
575 :subject => 'This is the test_new_with_group_assignment issue',
575 :subject => 'This is the test_new_with_group_assignment issue',
576 :assigned_to_id => group.id}
576 :assigned_to_id => group.id}
577 end
577 end
578 end
578 end
579 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
579 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
580
580
581 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
581 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
582 assert_not_nil issue
582 assert_not_nil issue
583 assert_equal group, issue.assigned_to
583 assert_equal group, issue.assigned_to
584 end
584 end
585
585
586 def test_post_create_without_start_date
586 def test_post_create_without_start_date
587 @request.session[:user_id] = 2
587 @request.session[:user_id] = 2
588 assert_difference 'Issue.count' do
588 assert_difference 'Issue.count' do
589 post :create, :project_id => 1,
589 post :create, :project_id => 1,
590 :issue => {:tracker_id => 3,
590 :issue => {:tracker_id => 3,
591 :status_id => 2,
591 :status_id => 2,
592 :subject => 'This is the test_new issue',
592 :subject => 'This is the test_new issue',
593 :description => 'This is the description',
593 :description => 'This is the description',
594 :priority_id => 5,
594 :priority_id => 5,
595 :start_date => '',
595 :start_date => '',
596 :estimated_hours => '',
596 :estimated_hours => '',
597 :custom_field_values => {'2' => 'Value for field 2'}}
597 :custom_field_values => {'2' => 'Value for field 2'}}
598 end
598 end
599 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
599 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
600
600
601 issue = Issue.find_by_subject('This is the test_new issue')
601 issue = Issue.find_by_subject('This is the test_new issue')
602 assert_not_nil issue
602 assert_not_nil issue
603 assert_nil issue.start_date
603 assert_nil issue.start_date
604 end
604 end
605
605
606 def test_post_create_and_continue
606 def test_post_create_and_continue
607 @request.session[:user_id] = 2
607 @request.session[:user_id] = 2
608 assert_difference 'Issue.count' do
608 assert_difference 'Issue.count' do
609 post :create, :project_id => 1,
609 post :create, :project_id => 1,
610 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
610 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
611 :continue => ''
611 :continue => ''
612 end
612 end
613
613
614 issue = Issue.first(:order => 'id DESC')
614 issue = Issue.first(:order => 'id DESC')
615 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
615 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
616 assert_not_nil flash[:notice], "flash was not set"
616 assert_not_nil flash[:notice], "flash was not set"
617 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
617 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
618 end
618 end
619
619
620 def test_post_create_without_custom_fields_param
620 def test_post_create_without_custom_fields_param
621 @request.session[:user_id] = 2
621 @request.session[:user_id] = 2
622 assert_difference 'Issue.count' do
622 assert_difference 'Issue.count' do
623 post :create, :project_id => 1,
623 post :create, :project_id => 1,
624 :issue => {:tracker_id => 1,
624 :issue => {:tracker_id => 1,
625 :subject => 'This is the test_new issue',
625 :subject => 'This is the test_new issue',
626 :description => 'This is the description',
626 :description => 'This is the description',
627 :priority_id => 5}
627 :priority_id => 5}
628 end
628 end
629 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
629 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
630 end
630 end
631
631
632 def test_post_create_with_required_custom_field_and_without_custom_fields_param
632 def test_post_create_with_required_custom_field_and_without_custom_fields_param
633 field = IssueCustomField.find_by_name('Database')
633 field = IssueCustomField.find_by_name('Database')
634 field.update_attribute(:is_required, true)
634 field.update_attribute(:is_required, true)
635
635
636 @request.session[:user_id] = 2
636 @request.session[:user_id] = 2
637 post :create, :project_id => 1,
637 post :create, :project_id => 1,
638 :issue => {:tracker_id => 1,
638 :issue => {:tracker_id => 1,
639 :subject => 'This is the test_new issue',
639 :subject => 'This is the test_new issue',
640 :description => 'This is the description',
640 :description => 'This is the description',
641 :priority_id => 5}
641 :priority_id => 5}
642 assert_response :success
642 assert_response :success
643 assert_template 'new'
643 assert_template 'new'
644 issue = assigns(:issue)
644 issue = assigns(:issue)
645 assert_not_nil issue
645 assert_not_nil issue
646 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
646 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
647 end
647 end
648
648
649 def test_post_create_with_watchers
649 def test_post_create_with_watchers
650 @request.session[:user_id] = 2
650 @request.session[:user_id] = 2
651 ActionMailer::Base.deliveries.clear
651 ActionMailer::Base.deliveries.clear
652
652
653 assert_difference 'Watcher.count', 2 do
653 assert_difference 'Watcher.count', 2 do
654 post :create, :project_id => 1,
654 post :create, :project_id => 1,
655 :issue => {:tracker_id => 1,
655 :issue => {:tracker_id => 1,
656 :subject => 'This is a new issue with watchers',
656 :subject => 'This is a new issue with watchers',
657 :description => 'This is the description',
657 :description => 'This is the description',
658 :priority_id => 5,
658 :priority_id => 5,
659 :watcher_user_ids => ['2', '3']}
659 :watcher_user_ids => ['2', '3']}
660 end
660 end
661 issue = Issue.find_by_subject('This is a new issue with watchers')
661 issue = Issue.find_by_subject('This is a new issue with watchers')
662 assert_not_nil issue
662 assert_not_nil issue
663 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
663 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
664
664
665 # Watchers added
665 # Watchers added
666 assert_equal [2, 3], issue.watcher_user_ids.sort
666 assert_equal [2, 3], issue.watcher_user_ids.sort
667 assert issue.watched_by?(User.find(3))
667 assert issue.watched_by?(User.find(3))
668 # Watchers notified
668 # Watchers notified
669 mail = ActionMailer::Base.deliveries.last
669 mail = ActionMailer::Base.deliveries.last
670 assert_kind_of TMail::Mail, mail
670 assert_kind_of TMail::Mail, mail
671 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
671 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
672 end
672 end
673
673
674 def test_post_create_subissue
674 def test_post_create_subissue
675 @request.session[:user_id] = 2
675 @request.session[:user_id] = 2
676
676
677 assert_difference 'Issue.count' do
677 assert_difference 'Issue.count' do
678 post :create, :project_id => 1,
678 post :create, :project_id => 1,
679 :issue => {:tracker_id => 1,
679 :issue => {:tracker_id => 1,
680 :subject => 'This is a child issue',
680 :subject => 'This is a child issue',
681 :parent_issue_id => 2}
681 :parent_issue_id => 2}
682 end
682 end
683 issue = Issue.find_by_subject('This is a child issue')
683 issue = Issue.find_by_subject('This is a child issue')
684 assert_not_nil issue
684 assert_not_nil issue
685 assert_equal Issue.find(2), issue.parent
685 assert_equal Issue.find(2), issue.parent
686 end
686 end
687
687
688 def test_post_create_subissue_with_non_numeric_parent_id
688 def test_post_create_subissue_with_non_numeric_parent_id
689 @request.session[:user_id] = 2
689 @request.session[:user_id] = 2
690
690
691 assert_difference 'Issue.count' do
691 assert_difference 'Issue.count' do
692 post :create, :project_id => 1,
692 post :create, :project_id => 1,
693 :issue => {:tracker_id => 1,
693 :issue => {:tracker_id => 1,
694 :subject => 'This is a child issue',
694 :subject => 'This is a child issue',
695 :parent_issue_id => 'ABC'}
695 :parent_issue_id => 'ABC'}
696 end
696 end
697 issue = Issue.find_by_subject('This is a child issue')
697 issue = Issue.find_by_subject('This is a child issue')
698 assert_not_nil issue
698 assert_not_nil issue
699 assert_nil issue.parent
699 assert_nil issue.parent
700 end
700 end
701
701
702 def test_post_create_private
702 def test_post_create_private
703 @request.session[:user_id] = 2
703 @request.session[:user_id] = 2
704
704
705 assert_difference 'Issue.count' do
705 assert_difference 'Issue.count' do
706 post :create, :project_id => 1,
706 post :create, :project_id => 1,
707 :issue => {:tracker_id => 1,
707 :issue => {:tracker_id => 1,
708 :subject => 'This is a private issue',
708 :subject => 'This is a private issue',
709 :is_private => '1'}
709 :is_private => '1'}
710 end
710 end
711 issue = Issue.first(:order => 'id DESC')
711 issue = Issue.first(:order => 'id DESC')
712 assert issue.is_private?
712 assert issue.is_private?
713 end
713 end
714
714
715 def test_post_create_private_with_set_own_issues_private_permission
715 def test_post_create_private_with_set_own_issues_private_permission
716 role = Role.find(1)
716 role = Role.find(1)
717 role.remove_permission! :set_issues_private
717 role.remove_permission! :set_issues_private
718 role.add_permission! :set_own_issues_private
718 role.add_permission! :set_own_issues_private
719
719
720 @request.session[:user_id] = 2
720 @request.session[:user_id] = 2
721
721
722 assert_difference 'Issue.count' do
722 assert_difference 'Issue.count' do
723 post :create, :project_id => 1,
723 post :create, :project_id => 1,
724 :issue => {:tracker_id => 1,
724 :issue => {:tracker_id => 1,
725 :subject => 'This is a private issue',
725 :subject => 'This is a private issue',
726 :is_private => '1'}
726 :is_private => '1'}
727 end
727 end
728 issue = Issue.first(:order => 'id DESC')
728 issue = Issue.first(:order => 'id DESC')
729 assert issue.is_private?
729 assert issue.is_private?
730 end
730 end
731
731
732 def test_post_create_should_send_a_notification
732 def test_post_create_should_send_a_notification
733 ActionMailer::Base.deliveries.clear
733 ActionMailer::Base.deliveries.clear
734 @request.session[:user_id] = 2
734 @request.session[:user_id] = 2
735 assert_difference 'Issue.count' do
735 assert_difference 'Issue.count' do
736 post :create, :project_id => 1,
736 post :create, :project_id => 1,
737 :issue => {:tracker_id => 3,
737 :issue => {:tracker_id => 3,
738 :subject => 'This is the test_new issue',
738 :subject => 'This is the test_new issue',
739 :description => 'This is the description',
739 :description => 'This is the description',
740 :priority_id => 5,
740 :priority_id => 5,
741 :estimated_hours => '',
741 :estimated_hours => '',
742 :custom_field_values => {'2' => 'Value for field 2'}}
742 :custom_field_values => {'2' => 'Value for field 2'}}
743 end
743 end
744 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
744 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
745
745
746 assert_equal 1, ActionMailer::Base.deliveries.size
746 assert_equal 1, ActionMailer::Base.deliveries.size
747 end
747 end
748
748
749 def test_post_create_should_preserve_fields_values_on_validation_failure
749 def test_post_create_should_preserve_fields_values_on_validation_failure
750 @request.session[:user_id] = 2
750 @request.session[:user_id] = 2
751 post :create, :project_id => 1,
751 post :create, :project_id => 1,
752 :issue => {:tracker_id => 1,
752 :issue => {:tracker_id => 1,
753 # empty subject
753 # empty subject
754 :subject => '',
754 :subject => '',
755 :description => 'This is a description',
755 :description => 'This is a description',
756 :priority_id => 6,
756 :priority_id => 6,
757 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
757 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
758 assert_response :success
758 assert_response :success
759 assert_template 'new'
759 assert_template 'new'
760
760
761 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
761 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
762 :content => 'This is a description'
762 :content => 'This is a description'
763 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
763 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
764 :child => { :tag => 'option', :attributes => { :selected => 'selected',
764 :child => { :tag => 'option', :attributes => { :selected => 'selected',
765 :value => '6' },
765 :value => '6' },
766 :content => 'High' }
766 :content => 'High' }
767 # Custom fields
767 # Custom fields
768 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
768 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
769 :child => { :tag => 'option', :attributes => { :selected => 'selected',
769 :child => { :tag => 'option', :attributes => { :selected => 'selected',
770 :value => 'Oracle' },
770 :value => 'Oracle' },
771 :content => 'Oracle' }
771 :content => 'Oracle' }
772 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
772 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
773 :value => 'Value for field 2'}
773 :value => 'Value for field 2'}
774 end
774 end
775
775
776 def test_post_create_should_ignore_non_safe_attributes
776 def test_post_create_should_ignore_non_safe_attributes
777 @request.session[:user_id] = 2
777 @request.session[:user_id] = 2
778 assert_nothing_raised do
778 assert_nothing_raised do
779 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
779 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
780 end
780 end
781 end
781 end
782
782
783 def test_post_create_with_attachment
783 def test_post_create_with_attachment
784 set_tmp_attachments_directory
784 set_tmp_attachments_directory
785 @request.session[:user_id] = 2
785 @request.session[:user_id] = 2
786
786
787 assert_difference 'Issue.count' do
787 assert_difference 'Issue.count' do
788 assert_difference 'Attachment.count' do
788 assert_difference 'Attachment.count' do
789 post :create, :project_id => 1,
789 post :create, :project_id => 1,
790 :issue => { :tracker_id => '1', :subject => 'With attachment' },
790 :issue => { :tracker_id => '1', :subject => 'With attachment' },
791 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
791 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
792 end
792 end
793 end
793 end
794
794
795 issue = Issue.first(:order => 'id DESC')
795 issue = Issue.first(:order => 'id DESC')
796 attachment = Attachment.first(:order => 'id DESC')
796 attachment = Attachment.first(:order => 'id DESC')
797
797
798 assert_equal issue, attachment.container
798 assert_equal issue, attachment.container
799 assert_equal 2, attachment.author_id
799 assert_equal 2, attachment.author_id
800 assert_equal 'testfile.txt', attachment.filename
800 assert_equal 'testfile.txt', attachment.filename
801 assert_equal 'text/plain', attachment.content_type
801 assert_equal 'text/plain', attachment.content_type
802 assert_equal 'test file', attachment.description
802 assert_equal 'test file', attachment.description
803 assert_equal 59, attachment.filesize
803 assert_equal 59, attachment.filesize
804 assert File.exists?(attachment.diskfile)
804 assert File.exists?(attachment.diskfile)
805 assert_equal 59, File.size(attachment.diskfile)
805 assert_equal 59, File.size(attachment.diskfile)
806 end
806 end
807
807
808 context "without workflow privilege" do
808 context "without workflow privilege" do
809 setup do
809 setup do
810 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
810 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
811 Role.anonymous.add_permission! :add_issues, :add_issue_notes
811 Role.anonymous.add_permission! :add_issues, :add_issue_notes
812 end
812 end
813
813
814 context "#new" do
814 context "#new" do
815 should "propose default status only" do
815 should "propose default status only" do
816 get :new, :project_id => 1
816 get :new, :project_id => 1
817 assert_response :success
817 assert_response :success
818 assert_template 'new'
818 assert_template 'new'
819 assert_tag :tag => 'select',
819 assert_tag :tag => 'select',
820 :attributes => {:name => 'issue[status_id]'},
820 :attributes => {:name => 'issue[status_id]'},
821 :children => {:count => 1},
821 :children => {:count => 1},
822 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
822 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
823 end
823 end
824
824
825 should "accept default status" do
825 should "accept default status" do
826 assert_difference 'Issue.count' do
826 assert_difference 'Issue.count' do
827 post :create, :project_id => 1,
827 post :create, :project_id => 1,
828 :issue => {:tracker_id => 1,
828 :issue => {:tracker_id => 1,
829 :subject => 'This is an issue',
829 :subject => 'This is an issue',
830 :status_id => 1}
830 :status_id => 1}
831 end
831 end
832 issue = Issue.last(:order => 'id')
832 issue = Issue.last(:order => 'id')
833 assert_equal IssueStatus.default, issue.status
833 assert_equal IssueStatus.default, issue.status
834 end
834 end
835
835
836 should "ignore unauthorized status" do
836 should "ignore unauthorized status" do
837 assert_difference 'Issue.count' do
837 assert_difference 'Issue.count' do
838 post :create, :project_id => 1,
838 post :create, :project_id => 1,
839 :issue => {:tracker_id => 1,
839 :issue => {:tracker_id => 1,
840 :subject => 'This is an issue',
840 :subject => 'This is an issue',
841 :status_id => 3}
841 :status_id => 3}
842 end
842 end
843 issue = Issue.last(:order => 'id')
843 issue = Issue.last(:order => 'id')
844 assert_equal IssueStatus.default, issue.status
844 assert_equal IssueStatus.default, issue.status
845 end
845 end
846 end
846 end
847
847
848 context "#update" do
848 context "#update" do
849 should "ignore status change" do
849 should "ignore status change" do
850 assert_difference 'Journal.count' do
850 assert_difference 'Journal.count' do
851 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
851 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
852 end
852 end
853 assert_equal 1, Issue.find(1).status_id
853 assert_equal 1, Issue.find(1).status_id
854 end
854 end
855
855
856 should "ignore attributes changes" do
856 should "ignore attributes changes" do
857 assert_difference 'Journal.count' do
857 assert_difference 'Journal.count' do
858 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
858 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
859 end
859 end
860 issue = Issue.find(1)
860 issue = Issue.find(1)
861 assert_equal "Can't print recipes", issue.subject
861 assert_equal "Can't print recipes", issue.subject
862 assert_nil issue.assigned_to
862 assert_nil issue.assigned_to
863 end
863 end
864 end
864 end
865 end
865 end
866
866
867 context "with workflow privilege" do
867 context "with workflow privilege" do
868 setup do
868 setup do
869 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
869 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
870 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
870 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
871 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
871 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
872 Role.anonymous.add_permission! :add_issues, :add_issue_notes
872 Role.anonymous.add_permission! :add_issues, :add_issue_notes
873 end
873 end
874
874
875 context "#update" do
875 context "#update" do
876 should "accept authorized status" do
876 should "accept authorized status" do
877 assert_difference 'Journal.count' do
877 assert_difference 'Journal.count' do
878 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
878 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
879 end
879 end
880 assert_equal 3, Issue.find(1).status_id
880 assert_equal 3, Issue.find(1).status_id
881 end
881 end
882
882
883 should "ignore unauthorized status" do
883 should "ignore unauthorized status" do
884 assert_difference 'Journal.count' do
884 assert_difference 'Journal.count' do
885 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
885 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
886 end
886 end
887 assert_equal 1, Issue.find(1).status_id
887 assert_equal 1, Issue.find(1).status_id
888 end
888 end
889
889
890 should "accept authorized attributes changes" do
890 should "accept authorized attributes changes" do
891 assert_difference 'Journal.count' do
891 assert_difference 'Journal.count' do
892 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
892 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
893 end
893 end
894 issue = Issue.find(1)
894 issue = Issue.find(1)
895 assert_equal 2, issue.assigned_to_id
895 assert_equal 2, issue.assigned_to_id
896 end
896 end
897
897
898 should "ignore unauthorized attributes changes" do
898 should "ignore unauthorized attributes changes" do
899 assert_difference 'Journal.count' do
899 assert_difference 'Journal.count' do
900 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
900 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
901 end
901 end
902 issue = Issue.find(1)
902 issue = Issue.find(1)
903 assert_equal "Can't print recipes", issue.subject
903 assert_equal "Can't print recipes", issue.subject
904 end
904 end
905 end
905 end
906
906
907 context "and :edit_issues permission" do
907 context "and :edit_issues permission" do
908 setup do
908 setup do
909 Role.anonymous.add_permission! :add_issues, :edit_issues
909 Role.anonymous.add_permission! :add_issues, :edit_issues
910 end
910 end
911
911
912 should "accept authorized status" do
912 should "accept authorized status" do
913 assert_difference 'Journal.count' do
913 assert_difference 'Journal.count' do
914 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
914 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
915 end
915 end
916 assert_equal 3, Issue.find(1).status_id
916 assert_equal 3, Issue.find(1).status_id
917 end
917 end
918
918
919 should "ignore unauthorized status" do
919 should "ignore unauthorized status" do
920 assert_difference 'Journal.count' do
920 assert_difference 'Journal.count' do
921 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
921 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
922 end
922 end
923 assert_equal 1, Issue.find(1).status_id
923 assert_equal 1, Issue.find(1).status_id
924 end
924 end
925
925
926 should "accept authorized attributes changes" do
926 should "accept authorized attributes changes" do
927 assert_difference 'Journal.count' do
927 assert_difference 'Journal.count' do
928 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
928 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
929 end
929 end
930 issue = Issue.find(1)
930 issue = Issue.find(1)
931 assert_equal "changed", issue.subject
931 assert_equal "changed", issue.subject
932 assert_equal 2, issue.assigned_to_id
932 assert_equal 2, issue.assigned_to_id
933 end
933 end
934 end
934 end
935 end
935 end
936
936
937 def test_copy_issue
937 def test_copy_issue
938 @request.session[:user_id] = 2
938 @request.session[:user_id] = 2
939 get :new, :project_id => 1, :copy_from => 1
939 get :new, :project_id => 1, :copy_from => 1
940 assert_template 'new'
940 assert_template 'new'
941 assert_not_nil assigns(:issue)
941 assert_not_nil assigns(:issue)
942 orig = Issue.find(1)
942 orig = Issue.find(1)
943 assert_equal orig.subject, assigns(:issue).subject
943 assert_equal orig.subject, assigns(:issue).subject
944 end
944 end
945
945
946 def test_get_edit
946 def test_get_edit
947 @request.session[:user_id] = 2
947 @request.session[:user_id] = 2
948 get :edit, :id => 1
948 get :edit, :id => 1
949 assert_response :success
949 assert_response :success
950 assert_template 'edit'
950 assert_template 'edit'
951 assert_not_nil assigns(:issue)
951 assert_not_nil assigns(:issue)
952 assert_equal Issue.find(1), assigns(:issue)
952 assert_equal Issue.find(1), assigns(:issue)
953
953
954 # Be sure we don't display inactive IssuePriorities
954 # Be sure we don't display inactive IssuePriorities
955 assert ! IssuePriority.find(15).active?
955 assert ! IssuePriority.find(15).active?
956 assert_no_tag :option, :attributes => {:value => '15'},
956 assert_no_tag :option, :attributes => {:value => '15'},
957 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
957 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
958 end
958 end
959
959
960 def test_get_edit_with_params
960 def test_get_edit_with_params
961 @request.session[:user_id] = 2
961 @request.session[:user_id] = 2
962 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
962 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
963 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
963 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
964 assert_response :success
964 assert_response :success
965 assert_template 'edit'
965 assert_template 'edit'
966
966
967 issue = assigns(:issue)
967 issue = assigns(:issue)
968 assert_not_nil issue
968 assert_not_nil issue
969
969
970 assert_equal 5, issue.status_id
970 assert_equal 5, issue.status_id
971 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
971 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
972 :child => { :tag => 'option',
972 :child => { :tag => 'option',
973 :content => 'Closed',
973 :content => 'Closed',
974 :attributes => { :selected => 'selected' } }
974 :attributes => { :selected => 'selected' } }
975
975
976 assert_equal 7, issue.priority_id
976 assert_equal 7, issue.priority_id
977 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
977 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
978 :child => { :tag => 'option',
978 :child => { :tag => 'option',
979 :content => 'Urgent',
979 :content => 'Urgent',
980 :attributes => { :selected => 'selected' } }
980 :attributes => { :selected => 'selected' } }
981
981
982 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
982 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
983 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
983 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
984 :child => { :tag => 'option',
984 :child => { :tag => 'option',
985 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
985 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
986 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
986 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
987 end
987 end
988
988
989 def test_update_edit_form
989 def test_update_edit_form
990 @request.session[:user_id] = 2
990 @request.session[:user_id] = 2
991 xhr :post, :new, :project_id => 1,
991 xhr :post, :new, :project_id => 1,
992 :id => 1,
992 :id => 1,
993 :issue => {:tracker_id => 2,
993 :issue => {:tracker_id => 2,
994 :subject => 'This is the test_new issue',
994 :subject => 'This is the test_new issue',
995 :description => 'This is the description',
995 :description => 'This is the description',
996 :priority_id => 5}
996 :priority_id => 5}
997 assert_response :success
997 assert_response :success
998 assert_template 'attributes'
998 assert_template 'attributes'
999
999
1000 issue = assigns(:issue)
1000 issue = assigns(:issue)
1001 assert_kind_of Issue, issue
1001 assert_kind_of Issue, issue
1002 assert_equal 1, issue.id
1002 assert_equal 1, issue.id
1003 assert_equal 1, issue.project_id
1003 assert_equal 1, issue.project_id
1004 assert_equal 2, issue.tracker_id
1004 assert_equal 2, issue.tracker_id
1005 assert_equal 'This is the test_new issue', issue.subject
1005 assert_equal 'This is the test_new issue', issue.subject
1006 end
1006 end
1007
1007
1008 def test_update_using_invalid_http_verbs
1008 def test_update_using_invalid_http_verbs
1009 @request.session[:user_id] = 2
1009 @request.session[:user_id] = 2
1010 subject = 'Updated by an invalid http verb'
1010 subject = 'Updated by an invalid http verb'
1011
1011
1012 get :update, :id => 1, :issue => {:subject => subject}
1012 get :update, :id => 1, :issue => {:subject => subject}
1013 assert_not_equal subject, Issue.find(1).subject
1013 assert_not_equal subject, Issue.find(1).subject
1014
1014
1015 post :update, :id => 1, :issue => {:subject => subject}
1015 post :update, :id => 1, :issue => {:subject => subject}
1016 assert_not_equal subject, Issue.find(1).subject
1016 assert_not_equal subject, Issue.find(1).subject
1017
1017
1018 delete :update, :id => 1, :issue => {:subject => subject}
1018 delete :update, :id => 1, :issue => {:subject => subject}
1019 assert_not_equal subject, Issue.find(1).subject
1019 assert_not_equal subject, Issue.find(1).subject
1020 end
1020 end
1021
1021
1022 def test_put_update_without_custom_fields_param
1022 def test_put_update_without_custom_fields_param
1023 @request.session[:user_id] = 2
1023 @request.session[:user_id] = 2
1024 ActionMailer::Base.deliveries.clear
1024 ActionMailer::Base.deliveries.clear
1025
1025
1026 issue = Issue.find(1)
1026 issue = Issue.find(1)
1027 assert_equal '125', issue.custom_value_for(2).value
1027 assert_equal '125', issue.custom_value_for(2).value
1028 old_subject = issue.subject
1028 old_subject = issue.subject
1029 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1029 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1030
1030
1031 assert_difference('Journal.count') do
1031 assert_difference('Journal.count') do
1032 assert_difference('JournalDetail.count', 2) do
1032 assert_difference('JournalDetail.count', 2) do
1033 put :update, :id => 1, :issue => {:subject => new_subject,
1033 put :update, :id => 1, :issue => {:subject => new_subject,
1034 :priority_id => '6',
1034 :priority_id => '6',
1035 :category_id => '1' # no change
1035 :category_id => '1' # no change
1036 }
1036 }
1037 end
1037 end
1038 end
1038 end
1039 assert_redirected_to :action => 'show', :id => '1'
1039 assert_redirected_to :action => 'show', :id => '1'
1040 issue.reload
1040 issue.reload
1041 assert_equal new_subject, issue.subject
1041 assert_equal new_subject, issue.subject
1042 # Make sure custom fields were not cleared
1042 # Make sure custom fields were not cleared
1043 assert_equal '125', issue.custom_value_for(2).value
1043 assert_equal '125', issue.custom_value_for(2).value
1044
1044
1045 mail = ActionMailer::Base.deliveries.last
1045 mail = ActionMailer::Base.deliveries.last
1046 assert_kind_of TMail::Mail, mail
1046 assert_kind_of TMail::Mail, mail
1047 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1047 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1048 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
1048 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
1049 end
1049 end
1050
1050
1051 def test_put_update_with_custom_field_change
1051 def test_put_update_with_custom_field_change
1052 @request.session[:user_id] = 2
1052 @request.session[:user_id] = 2
1053 issue = Issue.find(1)
1053 issue = Issue.find(1)
1054 assert_equal '125', issue.custom_value_for(2).value
1054 assert_equal '125', issue.custom_value_for(2).value
1055
1055
1056 assert_difference('Journal.count') do
1056 assert_difference('Journal.count') do
1057 assert_difference('JournalDetail.count', 3) do
1057 assert_difference('JournalDetail.count', 3) do
1058 put :update, :id => 1, :issue => {:subject => 'Custom field change',
1058 put :update, :id => 1, :issue => {:subject => 'Custom field change',
1059 :priority_id => '6',
1059 :priority_id => '6',
1060 :category_id => '1', # no change
1060 :category_id => '1', # no change
1061 :custom_field_values => { '2' => 'New custom value' }
1061 :custom_field_values => { '2' => 'New custom value' }
1062 }
1062 }
1063 end
1063 end
1064 end
1064 end
1065 assert_redirected_to :action => 'show', :id => '1'
1065 assert_redirected_to :action => 'show', :id => '1'
1066 issue.reload
1066 issue.reload
1067 assert_equal 'New custom value', issue.custom_value_for(2).value
1067 assert_equal 'New custom value', issue.custom_value_for(2).value
1068
1068
1069 mail = ActionMailer::Base.deliveries.last
1069 mail = ActionMailer::Base.deliveries.last
1070 assert_kind_of TMail::Mail, mail
1070 assert_kind_of TMail::Mail, mail
1071 assert mail.body.include?("Searchable field changed from 125 to New custom value")
1071 assert mail.body.include?("Searchable field changed from 125 to New custom value")
1072 end
1072 end
1073
1073
1074 def test_put_update_with_status_and_assignee_change
1074 def test_put_update_with_status_and_assignee_change
1075 issue = Issue.find(1)
1075 issue = Issue.find(1)
1076 assert_equal 1, issue.status_id
1076 assert_equal 1, issue.status_id
1077 @request.session[:user_id] = 2
1077 @request.session[:user_id] = 2
1078 assert_difference('TimeEntry.count', 0) do
1078 assert_difference('TimeEntry.count', 0) do
1079 put :update,
1079 put :update,
1080 :id => 1,
1080 :id => 1,
1081 :issue => { :status_id => 2, :assigned_to_id => 3 },
1081 :issue => { :status_id => 2, :assigned_to_id => 3 },
1082 :notes => 'Assigned to dlopper',
1082 :notes => 'Assigned to dlopper',
1083 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
1083 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
1084 end
1084 end
1085 assert_redirected_to :action => 'show', :id => '1'
1085 assert_redirected_to :action => 'show', :id => '1'
1086 issue.reload
1086 issue.reload
1087 assert_equal 2, issue.status_id
1087 assert_equal 2, issue.status_id
1088 j = Journal.find(:first, :order => 'id DESC')
1088 j = Journal.find(:first, :order => 'id DESC')
1089 assert_equal 'Assigned to dlopper', j.notes
1089 assert_equal 'Assigned to dlopper', j.notes
1090 assert_equal 2, j.details.size
1090 assert_equal 2, j.details.size
1091
1091
1092 mail = ActionMailer::Base.deliveries.last
1092 mail = ActionMailer::Base.deliveries.last
1093 assert mail.body.include?("Status changed from New to Assigned")
1093 assert mail.body.include?("Status changed from New to Assigned")
1094 # subject should contain the new status
1094 # subject should contain the new status
1095 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
1095 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
1096 end
1096 end
1097
1097
1098 def test_put_update_with_note_only
1098 def test_put_update_with_note_only
1099 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
1099 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
1100 # anonymous user
1100 # anonymous user
1101 put :update,
1101 put :update,
1102 :id => 1,
1102 :id => 1,
1103 :notes => notes
1103 :notes => notes
1104 assert_redirected_to :action => 'show', :id => '1'
1104 assert_redirected_to :action => 'show', :id => '1'
1105 j = Journal.find(:first, :order => 'id DESC')
1105 j = Journal.find(:first, :order => 'id DESC')
1106 assert_equal notes, j.notes
1106 assert_equal notes, j.notes
1107 assert_equal 0, j.details.size
1107 assert_equal 0, j.details.size
1108 assert_equal User.anonymous, j.user
1108 assert_equal User.anonymous, j.user
1109
1109
1110 mail = ActionMailer::Base.deliveries.last
1110 mail = ActionMailer::Base.deliveries.last
1111 assert mail.body.include?(notes)
1111 assert mail.body.include?(notes)
1112 end
1112 end
1113
1113
1114 def test_put_update_with_note_and_spent_time
1114 def test_put_update_with_note_and_spent_time
1115 @request.session[:user_id] = 2
1115 @request.session[:user_id] = 2
1116 spent_hours_before = Issue.find(1).spent_hours
1116 spent_hours_before = Issue.find(1).spent_hours
1117 assert_difference('TimeEntry.count') do
1117 assert_difference('TimeEntry.count') do
1118 put :update,
1118 put :update,
1119 :id => 1,
1119 :id => 1,
1120 :notes => '2.5 hours added',
1120 :notes => '2.5 hours added',
1121 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
1121 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
1122 end
1122 end
1123 assert_redirected_to :action => 'show', :id => '1'
1123 assert_redirected_to :action => 'show', :id => '1'
1124
1124
1125 issue = Issue.find(1)
1125 issue = Issue.find(1)
1126
1126
1127 j = Journal.find(:first, :order => 'id DESC')
1127 j = Journal.find(:first, :order => 'id DESC')
1128 assert_equal '2.5 hours added', j.notes
1128 assert_equal '2.5 hours added', j.notes
1129 assert_equal 0, j.details.size
1129 assert_equal 0, j.details.size
1130
1130
1131 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
1131 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
1132 assert_not_nil t
1132 assert_not_nil t
1133 assert_equal 2.5, t.hours
1133 assert_equal 2.5, t.hours
1134 assert_equal spent_hours_before + 2.5, issue.spent_hours
1134 assert_equal spent_hours_before + 2.5, issue.spent_hours
1135 end
1135 end
1136
1136
1137 def test_put_update_with_attachment_only
1137 def test_put_update_with_attachment_only
1138 set_tmp_attachments_directory
1138 set_tmp_attachments_directory
1139
1139
1140 # Delete all fixtured journals, a race condition can occur causing the wrong
1140 # Delete all fixtured journals, a race condition can occur causing the wrong
1141 # journal to get fetched in the next find.
1141 # journal to get fetched in the next find.
1142 Journal.delete_all
1142 Journal.delete_all
1143
1143
1144 # anonymous user
1144 # anonymous user
1145 assert_difference 'Attachment.count' do
1145 assert_difference 'Attachment.count' do
1146 put :update, :id => 1,
1146 put :update, :id => 1,
1147 :notes => '',
1147 :notes => '',
1148 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1148 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1149 end
1149 end
1150
1150
1151 assert_redirected_to :action => 'show', :id => '1'
1151 assert_redirected_to :action => 'show', :id => '1'
1152 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
1152 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
1153 assert j.notes.blank?
1153 assert j.notes.blank?
1154 assert_equal 1, j.details.size
1154 assert_equal 1, j.details.size
1155 assert_equal 'testfile.txt', j.details.first.value
1155 assert_equal 'testfile.txt', j.details.first.value
1156 assert_equal User.anonymous, j.user
1156 assert_equal User.anonymous, j.user
1157
1157
1158 attachment = Attachment.first(:order => 'id DESC')
1158 attachment = Attachment.first(:order => 'id DESC')
1159 assert_equal Issue.find(1), attachment.container
1159 assert_equal Issue.find(1), attachment.container
1160 assert_equal User.anonymous, attachment.author
1160 assert_equal User.anonymous, attachment.author
1161 assert_equal 'testfile.txt', attachment.filename
1161 assert_equal 'testfile.txt', attachment.filename
1162 assert_equal 'text/plain', attachment.content_type
1162 assert_equal 'text/plain', attachment.content_type
1163 assert_equal 'test file', attachment.description
1163 assert_equal 'test file', attachment.description
1164 assert_equal 59, attachment.filesize
1164 assert_equal 59, attachment.filesize
1165 assert File.exists?(attachment.diskfile)
1165 assert File.exists?(attachment.diskfile)
1166 assert_equal 59, File.size(attachment.diskfile)
1166 assert_equal 59, File.size(attachment.diskfile)
1167
1167
1168 mail = ActionMailer::Base.deliveries.last
1168 mail = ActionMailer::Base.deliveries.last
1169 assert mail.body.include?('testfile.txt')
1169 assert mail.body.include?('testfile.txt')
1170 end
1170 end
1171
1171
1172 def test_put_update_with_attachment_that_fails_to_save
1172 def test_put_update_with_attachment_that_fails_to_save
1173 set_tmp_attachments_directory
1173 set_tmp_attachments_directory
1174
1174
1175 # Delete all fixtured journals, a race condition can occur causing the wrong
1175 # Delete all fixtured journals, a race condition can occur causing the wrong
1176 # journal to get fetched in the next find.
1176 # journal to get fetched in the next find.
1177 Journal.delete_all
1177 Journal.delete_all
1178
1178
1179 # Mock out the unsaved attachment
1179 # Mock out the unsaved attachment
1180 Attachment.any_instance.stubs(:create).returns(Attachment.new)
1180 Attachment.any_instance.stubs(:create).returns(Attachment.new)
1181
1181
1182 # anonymous user
1182 # anonymous user
1183 put :update,
1183 put :update,
1184 :id => 1,
1184 :id => 1,
1185 :notes => '',
1185 :notes => '',
1186 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
1186 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
1187 assert_redirected_to :action => 'show', :id => '1'
1187 assert_redirected_to :action => 'show', :id => '1'
1188 assert_equal '1 file(s) could not be saved.', flash[:warning]
1188 assert_equal '1 file(s) could not be saved.', flash[:warning]
1189
1189
1190 end if Object.const_defined?(:Mocha)
1190 end if Object.const_defined?(:Mocha)
1191
1191
1192 def test_put_update_with_no_change
1192 def test_put_update_with_no_change
1193 issue = Issue.find(1)
1193 issue = Issue.find(1)
1194 issue.journals.clear
1194 issue.journals.clear
1195 ActionMailer::Base.deliveries.clear
1195 ActionMailer::Base.deliveries.clear
1196
1196
1197 put :update,
1197 put :update,
1198 :id => 1,
1198 :id => 1,
1199 :notes => ''
1199 :notes => ''
1200 assert_redirected_to :action => 'show', :id => '1'
1200 assert_redirected_to :action => 'show', :id => '1'
1201
1201
1202 issue.reload
1202 issue.reload
1203 assert issue.journals.empty?
1203 assert issue.journals.empty?
1204 # No email should be sent
1204 # No email should be sent
1205 assert ActionMailer::Base.deliveries.empty?
1205 assert ActionMailer::Base.deliveries.empty?
1206 end
1206 end
1207
1207
1208 def test_put_update_should_send_a_notification
1208 def test_put_update_should_send_a_notification
1209 @request.session[:user_id] = 2
1209 @request.session[:user_id] = 2
1210 ActionMailer::Base.deliveries.clear
1210 ActionMailer::Base.deliveries.clear
1211 issue = Issue.find(1)
1211 issue = Issue.find(1)
1212 old_subject = issue.subject
1212 old_subject = issue.subject
1213 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1213 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1214
1214
1215 put :update, :id => 1, :issue => {:subject => new_subject,
1215 put :update, :id => 1, :issue => {:subject => new_subject,
1216 :priority_id => '6',
1216 :priority_id => '6',
1217 :category_id => '1' # no change
1217 :category_id => '1' # no change
1218 }
1218 }
1219 assert_equal 1, ActionMailer::Base.deliveries.size
1219 assert_equal 1, ActionMailer::Base.deliveries.size
1220 end
1220 end
1221
1221
1222 def test_put_update_with_invalid_spent_time_hours_only
1222 def test_put_update_with_invalid_spent_time_hours_only
1223 @request.session[:user_id] = 2
1223 @request.session[:user_id] = 2
1224 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1224 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1225
1225
1226 assert_no_difference('Journal.count') do
1226 assert_no_difference('Journal.count') do
1227 put :update,
1227 put :update,
1228 :id => 1,
1228 :id => 1,
1229 :notes => notes,
1229 :notes => notes,
1230 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
1230 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
1231 end
1231 end
1232 assert_response :success
1232 assert_response :success
1233 assert_template 'edit'
1233 assert_template 'edit'
1234
1234
1235 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1235 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1236 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1236 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1237 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
1237 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
1238 end
1238 end
1239
1239
1240 def test_put_update_with_invalid_spent_time_comments_only
1240 def test_put_update_with_invalid_spent_time_comments_only
1241 @request.session[:user_id] = 2
1241 @request.session[:user_id] = 2
1242 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1242 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1243
1243
1244 assert_no_difference('Journal.count') do
1244 assert_no_difference('Journal.count') do
1245 put :update,
1245 put :update,
1246 :id => 1,
1246 :id => 1,
1247 :notes => notes,
1247 :notes => notes,
1248 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
1248 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
1249 end
1249 end
1250 assert_response :success
1250 assert_response :success
1251 assert_template 'edit'
1251 assert_template 'edit'
1252
1252
1253 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1253 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1254 assert_error_tag :descendant => {:content => /Hours can't be blank/}
1254 assert_error_tag :descendant => {:content => /Hours can't be blank/}
1255 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1255 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1256 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
1256 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
1257 end
1257 end
1258
1258
1259 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
1259 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
1260 issue = Issue.find(2)
1260 issue = Issue.find(2)
1261 @request.session[:user_id] = 2
1261 @request.session[:user_id] = 2
1262
1262
1263 put :update,
1263 put :update,
1264 :id => issue.id,
1264 :id => issue.id,
1265 :issue => {
1265 :issue => {
1266 :fixed_version_id => 4
1266 :fixed_version_id => 4
1267 }
1267 }
1268
1268
1269 assert_response :redirect
1269 assert_response :redirect
1270 issue.reload
1270 issue.reload
1271 assert_equal 4, issue.fixed_version_id
1271 assert_equal 4, issue.fixed_version_id
1272 assert_not_equal issue.project_id, issue.fixed_version.project_id
1272 assert_not_equal issue.project_id, issue.fixed_version.project_id
1273 end
1273 end
1274
1274
1275 def test_put_update_should_redirect_back_using_the_back_url_parameter
1275 def test_put_update_should_redirect_back_using_the_back_url_parameter
1276 issue = Issue.find(2)
1276 issue = Issue.find(2)
1277 @request.session[:user_id] = 2
1277 @request.session[:user_id] = 2
1278
1278
1279 put :update,
1279 put :update,
1280 :id => issue.id,
1280 :id => issue.id,
1281 :issue => {
1281 :issue => {
1282 :fixed_version_id => 4
1282 :fixed_version_id => 4
1283 },
1283 },
1284 :back_url => '/issues'
1284 :back_url => '/issues'
1285
1285
1286 assert_response :redirect
1286 assert_response :redirect
1287 assert_redirected_to '/issues'
1287 assert_redirected_to '/issues'
1288 end
1288 end
1289
1289
1290 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1290 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1291 issue = Issue.find(2)
1291 issue = Issue.find(2)
1292 @request.session[:user_id] = 2
1292 @request.session[:user_id] = 2
1293
1293
1294 put :update,
1294 put :update,
1295 :id => issue.id,
1295 :id => issue.id,
1296 :issue => {
1296 :issue => {
1297 :fixed_version_id => 4
1297 :fixed_version_id => 4
1298 },
1298 },
1299 :back_url => 'http://google.com'
1299 :back_url => 'http://google.com'
1300
1300
1301 assert_response :redirect
1301 assert_response :redirect
1302 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
1302 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
1303 end
1303 end
1304
1304
1305 def test_get_bulk_edit
1305 def test_get_bulk_edit
1306 @request.session[:user_id] = 2
1306 @request.session[:user_id] = 2
1307 get :bulk_edit, :ids => [1, 2]
1307 get :bulk_edit, :ids => [1, 2]
1308 assert_response :success
1308 assert_response :success
1309 assert_template 'bulk_edit'
1309 assert_template 'bulk_edit'
1310
1310
1311 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1311 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1312
1312
1313 # Project specific custom field, date type
1313 # Project specific custom field, date type
1314 field = CustomField.find(9)
1314 field = CustomField.find(9)
1315 assert !field.is_for_all?
1315 assert !field.is_for_all?
1316 assert_equal 'date', field.field_format
1316 assert_equal 'date', field.field_format
1317 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1317 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1318
1318
1319 # System wide custom field
1319 # System wide custom field
1320 assert CustomField.find(1).is_for_all?
1320 assert CustomField.find(1).is_for_all?
1321 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
1321 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
1322
1322
1323 # Be sure we don't display inactive IssuePriorities
1323 # Be sure we don't display inactive IssuePriorities
1324 assert ! IssuePriority.find(15).active?
1324 assert ! IssuePriority.find(15).active?
1325 assert_no_tag :option, :attributes => {:value => '15'},
1325 assert_no_tag :option, :attributes => {:value => '15'},
1326 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1326 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1327 end
1327 end
1328
1328
1329 def test_get_bulk_edit_on_different_projects
1329 def test_get_bulk_edit_on_different_projects
1330 @request.session[:user_id] = 2
1330 @request.session[:user_id] = 2
1331 get :bulk_edit, :ids => [1, 2, 6]
1331 get :bulk_edit, :ids => [1, 2, 6]
1332 assert_response :success
1332 assert_response :success
1333 assert_template 'bulk_edit'
1333 assert_template 'bulk_edit'
1334
1334
1335 # Can not set issues from different projects as children of an issue
1335 # Can not set issues from different projects as children of an issue
1336 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1336 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1337
1337
1338 # Project specific custom field, date type
1338 # Project specific custom field, date type
1339 field = CustomField.find(9)
1339 field = CustomField.find(9)
1340 assert !field.is_for_all?
1340 assert !field.is_for_all?
1341 assert !field.project_ids.include?(Issue.find(6).project_id)
1341 assert !field.project_ids.include?(Issue.find(6).project_id)
1342 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1342 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1343 end
1343 end
1344
1344
1345 def test_get_bulk_edit_with_user_custom_field
1345 def test_get_bulk_edit_with_user_custom_field
1346 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
1346 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
1347
1347
1348 @request.session[:user_id] = 2
1348 @request.session[:user_id] = 2
1349 get :bulk_edit, :ids => [1, 2]
1349 get :bulk_edit, :ids => [1, 2]
1350 assert_response :success
1350 assert_response :success
1351 assert_template 'bulk_edit'
1351 assert_template 'bulk_edit'
1352
1352
1353 assert_tag :select,
1353 assert_tag :select,
1354 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1354 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1355 :children => {
1355 :children => {
1356 :only => {:tag => 'option'},
1356 :only => {:tag => 'option'},
1357 :count => Project.find(1).users.count + 1
1357 :count => Project.find(1).users.count + 1
1358 }
1358 }
1359 end
1359 end
1360
1360
1361 def test_get_bulk_edit_with_version_custom_field
1361 def test_get_bulk_edit_with_version_custom_field
1362 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
1362 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
1363
1363
1364 @request.session[:user_id] = 2
1364 @request.session[:user_id] = 2
1365 get :bulk_edit, :ids => [1, 2]
1365 get :bulk_edit, :ids => [1, 2]
1366 assert_response :success
1366 assert_response :success
1367 assert_template 'bulk_edit'
1367 assert_template 'bulk_edit'
1368
1368
1369 assert_tag :select,
1369 assert_tag :select,
1370 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1370 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1371 :children => {
1371 :children => {
1372 :only => {:tag => 'option'},
1372 :only => {:tag => 'option'},
1373 :count => Project.find(1).versions.count + 1
1373 :count => Project.find(1).versions.count + 1
1374 }
1374 }
1375 end
1375 end
1376
1376
1377 def test_bulk_update
1377 def test_bulk_update
1378 @request.session[:user_id] = 2
1378 @request.session[:user_id] = 2
1379 # update issues priority
1379 # update issues priority
1380 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1380 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1381 :issue => {:priority_id => 7,
1381 :issue => {:priority_id => 7,
1382 :assigned_to_id => '',
1382 :assigned_to_id => '',
1383 :custom_field_values => {'2' => ''}}
1383 :custom_field_values => {'2' => ''}}
1384
1384
1385 assert_response 302
1385 assert_response 302
1386 # check that the issues were updated
1386 # check that the issues were updated
1387 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
1387 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
1388
1388
1389 issue = Issue.find(1)
1389 issue = Issue.find(1)
1390 journal = issue.journals.find(:first, :order => 'created_on DESC')
1390 journal = issue.journals.find(:first, :order => 'created_on DESC')
1391 assert_equal '125', issue.custom_value_for(2).value
1391 assert_equal '125', issue.custom_value_for(2).value
1392 assert_equal 'Bulk editing', journal.notes
1392 assert_equal 'Bulk editing', journal.notes
1393 assert_equal 1, journal.details.size
1393 assert_equal 1, journal.details.size
1394 end
1394 end
1395
1395
1396 def test_bulk_update_with_group_assignee
1396 def test_bulk_update_with_group_assignee
1397 group = Group.find(11)
1397 group = Group.find(11)
1398 project = Project.find(1)
1398 project = Project.find(1)
1399 project.members << Member.new(:principal => group, :roles => [Role.first])
1399 project.members << Member.new(:principal => group, :roles => [Role.first])
1400
1400
1401 @request.session[:user_id] = 2
1401 @request.session[:user_id] = 2
1402 # update issues assignee
1402 # update issues assignee
1403 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1403 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1404 :issue => {:priority_id => '',
1404 :issue => {:priority_id => '',
1405 :assigned_to_id => group.id,
1405 :assigned_to_id => group.id,
1406 :custom_field_values => {'2' => ''}}
1406 :custom_field_values => {'2' => ''}}
1407
1407
1408 assert_response 302
1408 assert_response 302
1409 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
1409 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
1410 end
1410 end
1411
1411
1412 def test_bulk_update_on_different_projects
1412 def test_bulk_update_on_different_projects
1413 @request.session[:user_id] = 2
1413 @request.session[:user_id] = 2
1414 # update issues priority
1414 # update issues priority
1415 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
1415 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
1416 :issue => {:priority_id => 7,
1416 :issue => {:priority_id => 7,
1417 :assigned_to_id => '',
1417 :assigned_to_id => '',
1418 :custom_field_values => {'2' => ''}}
1418 :custom_field_values => {'2' => ''}}
1419
1419
1420 assert_response 302
1420 assert_response 302
1421 # check that the issues were updated
1421 # check that the issues were updated
1422 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
1422 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
1423
1423
1424 issue = Issue.find(1)
1424 issue = Issue.find(1)
1425 journal = issue.journals.find(:first, :order => 'created_on DESC')
1425 journal = issue.journals.find(:first, :order => 'created_on DESC')
1426 assert_equal '125', issue.custom_value_for(2).value
1426 assert_equal '125', issue.custom_value_for(2).value
1427 assert_equal 'Bulk editing', journal.notes
1427 assert_equal 'Bulk editing', journal.notes
1428 assert_equal 1, journal.details.size
1428 assert_equal 1, journal.details.size
1429 end
1429 end
1430
1430
1431 def test_bulk_update_on_different_projects_without_rights
1431 def test_bulk_update_on_different_projects_without_rights
1432 @request.session[:user_id] = 3
1432 @request.session[:user_id] = 3
1433 user = User.find(3)
1433 user = User.find(3)
1434 action = { :controller => "issues", :action => "bulk_update" }
1434 action = { :controller => "issues", :action => "bulk_update" }
1435 assert user.allowed_to?(action, Issue.find(1).project)
1435 assert user.allowed_to?(action, Issue.find(1).project)
1436 assert ! user.allowed_to?(action, Issue.find(6).project)
1436 assert ! user.allowed_to?(action, Issue.find(6).project)
1437 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
1437 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
1438 :issue => {:priority_id => 7,
1438 :issue => {:priority_id => 7,
1439 :assigned_to_id => '',
1439 :assigned_to_id => '',
1440 :custom_field_values => {'2' => ''}}
1440 :custom_field_values => {'2' => ''}}
1441 assert_response 403
1441 assert_response 403
1442 assert_not_equal "Bulk should fail", Journal.last.notes
1442 assert_not_equal "Bulk should fail", Journal.last.notes
1443 end
1443 end
1444
1444
1445 def test_bullk_update_should_send_a_notification
1445 def test_bullk_update_should_send_a_notification
1446 @request.session[:user_id] = 2
1446 @request.session[:user_id] = 2
1447 ActionMailer::Base.deliveries.clear
1447 ActionMailer::Base.deliveries.clear
1448 post(:bulk_update,
1448 post(:bulk_update,
1449 {
1449 {
1450 :ids => [1, 2],
1450 :ids => [1, 2],
1451 :notes => 'Bulk editing',
1451 :notes => 'Bulk editing',
1452 :issue => {
1452 :issue => {
1453 :priority_id => 7,
1453 :priority_id => 7,
1454 :assigned_to_id => '',
1454 :assigned_to_id => '',
1455 :custom_field_values => {'2' => ''}
1455 :custom_field_values => {'2' => ''}
1456 }
1456 }
1457 })
1457 })
1458
1458
1459 assert_response 302
1459 assert_response 302
1460 assert_equal 2, ActionMailer::Base.deliveries.size
1460 assert_equal 2, ActionMailer::Base.deliveries.size
1461 end
1461 end
1462
1462
1463 def test_bulk_update_status
1463 def test_bulk_update_status
1464 @request.session[:user_id] = 2
1464 @request.session[:user_id] = 2
1465 # update issues priority
1465 # update issues priority
1466 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
1466 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
1467 :issue => {:priority_id => '',
1467 :issue => {:priority_id => '',
1468 :assigned_to_id => '',
1468 :assigned_to_id => '',
1469 :status_id => '5'}
1469 :status_id => '5'}
1470
1470
1471 assert_response 302
1471 assert_response 302
1472 issue = Issue.find(1)
1472 issue = Issue.find(1)
1473 assert issue.closed?
1473 assert issue.closed?
1474 end
1474 end
1475
1475
1476 def test_bulk_update_parent_id
1476 def test_bulk_update_parent_id
1477 @request.session[:user_id] = 2
1477 @request.session[:user_id] = 2
1478 post :bulk_update, :ids => [1, 3],
1478 post :bulk_update, :ids => [1, 3],
1479 :notes => 'Bulk editing parent',
1479 :notes => 'Bulk editing parent',
1480 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
1480 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
1481
1481
1482 assert_response 302
1482 assert_response 302
1483 parent = Issue.find(2)
1483 parent = Issue.find(2)
1484 assert_equal parent.id, Issue.find(1).parent_id
1484 assert_equal parent.id, Issue.find(1).parent_id
1485 assert_equal parent.id, Issue.find(3).parent_id
1485 assert_equal parent.id, Issue.find(3).parent_id
1486 assert_equal [1, 3], parent.children.collect(&:id).sort
1486 assert_equal [1, 3], parent.children.collect(&:id).sort
1487 end
1487 end
1488
1488
1489 def test_bulk_update_custom_field
1489 def test_bulk_update_custom_field
1490 @request.session[:user_id] = 2
1490 @request.session[:user_id] = 2
1491 # update issues priority
1491 # update issues priority
1492 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
1492 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
1493 :issue => {:priority_id => '',
1493 :issue => {:priority_id => '',
1494 :assigned_to_id => '',
1494 :assigned_to_id => '',
1495 :custom_field_values => {'2' => '777'}}
1495 :custom_field_values => {'2' => '777'}}
1496
1496
1497 assert_response 302
1497 assert_response 302
1498
1498
1499 issue = Issue.find(1)
1499 issue = Issue.find(1)
1500 journal = issue.journals.find(:first, :order => 'created_on DESC')
1500 journal = issue.journals.find(:first, :order => 'created_on DESC')
1501 assert_equal '777', issue.custom_value_for(2).value
1501 assert_equal '777', issue.custom_value_for(2).value
1502 assert_equal 1, journal.details.size
1502 assert_equal 1, journal.details.size
1503 assert_equal '125', journal.details.first.old_value
1503 assert_equal '125', journal.details.first.old_value
1504 assert_equal '777', journal.details.first.value
1504 assert_equal '777', journal.details.first.value
1505 end
1505 end
1506
1506
1507 def test_bulk_update_unassign
1507 def test_bulk_update_unassign
1508 assert_not_nil Issue.find(2).assigned_to
1508 assert_not_nil Issue.find(2).assigned_to
1509 @request.session[:user_id] = 2
1509 @request.session[:user_id] = 2
1510 # unassign issues
1510 # unassign issues
1511 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
1511 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
1512 assert_response 302
1512 assert_response 302
1513 # check that the issues were updated
1513 # check that the issues were updated
1514 assert_nil Issue.find(2).assigned_to
1514 assert_nil Issue.find(2).assigned_to
1515 end
1515 end
1516
1516
1517 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
1517 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
1518 @request.session[:user_id] = 2
1518 @request.session[:user_id] = 2
1519
1519
1520 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
1520 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
1521
1521
1522 assert_response :redirect
1522 assert_response :redirect
1523 issues = Issue.find([1,2])
1523 issues = Issue.find([1,2])
1524 issues.each do |issue|
1524 issues.each do |issue|
1525 assert_equal 4, issue.fixed_version_id
1525 assert_equal 4, issue.fixed_version_id
1526 assert_not_equal issue.project_id, issue.fixed_version.project_id
1526 assert_not_equal issue.project_id, issue.fixed_version.project_id
1527 end
1527 end
1528 end
1528 end
1529
1529
1530 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
1530 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
1531 @request.session[:user_id] = 2
1531 @request.session[:user_id] = 2
1532 post :bulk_update, :ids => [1,2], :back_url => '/issues'
1532 post :bulk_update, :ids => [1,2], :back_url => '/issues'
1533
1533
1534 assert_response :redirect
1534 assert_response :redirect
1535 assert_redirected_to '/issues'
1535 assert_redirected_to '/issues'
1536 end
1536 end
1537
1537
1538 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1538 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1539 @request.session[:user_id] = 2
1539 @request.session[:user_id] = 2
1540 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
1540 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
1541
1541
1542 assert_response :redirect
1542 assert_response :redirect
1543 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
1543 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
1544 end
1544 end
1545
1545
1546 def test_destroy_issue_with_no_time_entries
1546 def test_destroy_issue_with_no_time_entries
1547 assert_nil TimeEntry.find_by_issue_id(2)
1547 assert_nil TimeEntry.find_by_issue_id(2)
1548 @request.session[:user_id] = 2
1548 @request.session[:user_id] = 2
1549 post :destroy, :id => 2
1549 post :destroy, :id => 2
1550 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1550 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1551 assert_nil Issue.find_by_id(2)
1551 assert_nil Issue.find_by_id(2)
1552 end
1552 end
1553
1553
1554 def test_destroy_issues_with_time_entries
1554 def test_destroy_issues_with_time_entries
1555 @request.session[:user_id] = 2
1555 @request.session[:user_id] = 2
1556 post :destroy, :ids => [1, 3]
1556 post :destroy, :ids => [1, 3]
1557 assert_response :success
1557 assert_response :success
1558 assert_template 'destroy'
1558 assert_template 'destroy'
1559 assert_not_nil assigns(:hours)
1559 assert_not_nil assigns(:hours)
1560 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1560 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1561 end
1561 end
1562
1562
1563 def test_destroy_issues_and_destroy_time_entries
1563 def test_destroy_issues_and_destroy_time_entries
1564 @request.session[:user_id] = 2
1564 @request.session[:user_id] = 2
1565 post :destroy, :ids => [1, 3], :todo => 'destroy'
1565 post :destroy, :ids => [1, 3], :todo => 'destroy'
1566 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1566 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1567 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1567 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1568 assert_nil TimeEntry.find_by_id([1, 2])
1568 assert_nil TimeEntry.find_by_id([1, 2])
1569 end
1569 end
1570
1570
1571 def test_destroy_issues_and_assign_time_entries_to_project
1571 def test_destroy_issues_and_assign_time_entries_to_project
1572 @request.session[:user_id] = 2
1572 @request.session[:user_id] = 2
1573 post :destroy, :ids => [1, 3], :todo => 'nullify'
1573 post :destroy, :ids => [1, 3], :todo => 'nullify'
1574 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1574 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1575 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1575 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1576 assert_nil TimeEntry.find(1).issue_id
1576 assert_nil TimeEntry.find(1).issue_id
1577 assert_nil TimeEntry.find(2).issue_id
1577 assert_nil TimeEntry.find(2).issue_id
1578 end
1578 end
1579
1579
1580 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1580 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1581 @request.session[:user_id] = 2
1581 @request.session[:user_id] = 2
1582 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1582 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1583 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1583 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1584 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1584 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1585 assert_equal 2, TimeEntry.find(1).issue_id
1585 assert_equal 2, TimeEntry.find(1).issue_id
1586 assert_equal 2, TimeEntry.find(2).issue_id
1586 assert_equal 2, TimeEntry.find(2).issue_id
1587 end
1587 end
1588
1588
1589 def test_destroy_issues_from_different_projects
1589 def test_destroy_issues_from_different_projects
1590 @request.session[:user_id] = 2
1590 @request.session[:user_id] = 2
1591 post :destroy, :ids => [1, 2, 6], :todo => 'destroy'
1591 post :destroy, :ids => [1, 2, 6], :todo => 'destroy'
1592 assert_redirected_to :controller => 'issues', :action => 'index'
1592 assert_redirected_to :controller => 'issues', :action => 'index'
1593 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
1593 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
1594 end
1594 end
1595
1595
1596 def test_destroy_parent_and_child_issues
1596 def test_destroy_parent_and_child_issues
1597 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
1597 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
1598 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
1598 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
1599 assert child.is_descendant_of?(parent.reload)
1599 assert child.is_descendant_of?(parent.reload)
1600
1600
1601 @request.session[:user_id] = 2
1601 @request.session[:user_id] = 2
1602 assert_difference 'Issue.count', -2 do
1602 assert_difference 'Issue.count', -2 do
1603 post :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
1603 post :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
1604 end
1604 end
1605 assert_response 302
1605 assert_response 302
1606 end
1606 end
1607
1607
1608 def test_default_search_scope
1608 def test_default_search_scope
1609 get :index
1609 get :index
1610 assert_tag :div, :attributes => {:id => 'quick-search'},
1610 assert_tag :div, :attributes => {:id => 'quick-search'},
1611 :child => {:tag => 'form',
1611 :child => {:tag => 'form',
1612 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
1612 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
1613 end
1613 end
1614 end
1614 end
General Comments 0
You need to be logged in to leave comments. Login now