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