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