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