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