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