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