##// END OF EJS Templates
Fixing tests (sort refactoring)....
Jean-Philippe Lang -
r2509:adbe164246dd
parent child
Show More
@@ -1,989 +1,993
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'issues_controller'
19 require 'issues_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class IssuesController; def rescue_action(e) raise e end; end
22 class IssuesController; def rescue_action(e) raise e end; end
23
23
24 class IssuesControllerTest < Test::Unit::TestCase
24 class IssuesControllerTest < Test::Unit::TestCase
25 fixtures :projects,
25 fixtures :projects,
26 :users,
26 :users,
27 :roles,
27 :roles,
28 :members,
28 :members,
29 :issues,
29 :issues,
30 :issue_statuses,
30 :issue_statuses,
31 :versions,
31 :versions,
32 :trackers,
32 :trackers,
33 :projects_trackers,
33 :projects_trackers,
34 :issue_categories,
34 :issue_categories,
35 :enabled_modules,
35 :enabled_modules,
36 :enumerations,
36 :enumerations,
37 :attachments,
37 :attachments,
38 :workflows,
38 :workflows,
39 :custom_fields,
39 :custom_fields,
40 :custom_values,
40 :custom_values,
41 :custom_fields_trackers,
41 :custom_fields_trackers,
42 :time_entries,
42 :time_entries,
43 :journals,
43 :journals,
44 :journal_details
44 :journal_details
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_routing
53 def test_index_routing
54 assert_routing(
54 assert_routing(
55 {:method => :get, :path => '/issues'},
55 {:method => :get, :path => '/issues'},
56 :controller => 'issues', :action => 'index'
56 :controller => 'issues', :action => 'index'
57 )
57 )
58 end
58 end
59
59
60 def test_index
60 def test_index
61 Setting.default_language = 'en'
61 Setting.default_language = 'en'
62
62
63 get :index
63 get :index
64 assert_response :success
64 assert_response :success
65 assert_template 'index.rhtml'
65 assert_template 'index.rhtml'
66 assert_not_nil assigns(:issues)
66 assert_not_nil assigns(:issues)
67 assert_nil assigns(:project)
67 assert_nil assigns(:project)
68 assert_tag :tag => 'a', :content => /Can't print recipes/
68 assert_tag :tag => 'a', :content => /Can't print recipes/
69 assert_tag :tag => 'a', :content => /Subproject issue/
69 assert_tag :tag => 'a', :content => /Subproject issue/
70 # private projects hidden
70 # private projects hidden
71 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
71 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
72 assert_no_tag :tag => 'a', :content => /Issue on project 2/
72 assert_no_tag :tag => 'a', :content => /Issue on project 2/
73 # project column
73 # project column
74 assert_tag :tag => 'th', :content => /Project/
74 assert_tag :tag => 'th', :content => /Project/
75 end
75 end
76
76
77 def test_index_should_not_list_issues_when_module_disabled
77 def test_index_should_not_list_issues_when_module_disabled
78 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
78 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
79 get :index
79 get :index
80 assert_response :success
80 assert_response :success
81 assert_template 'index.rhtml'
81 assert_template 'index.rhtml'
82 assert_not_nil assigns(:issues)
82 assert_not_nil assigns(:issues)
83 assert_nil assigns(:project)
83 assert_nil assigns(:project)
84 assert_no_tag :tag => 'a', :content => /Can't print recipes/
84 assert_no_tag :tag => 'a', :content => /Can't print recipes/
85 assert_tag :tag => 'a', :content => /Subproject issue/
85 assert_tag :tag => 'a', :content => /Subproject issue/
86 end
86 end
87
87
88 def test_index_with_project_routing
88 def test_index_with_project_routing
89 assert_routing(
89 assert_routing(
90 {:method => :get, :path => '/projects/23/issues'},
90 {:method => :get, :path => '/projects/23/issues'},
91 :controller => 'issues', :action => 'index', :project_id => '23'
91 :controller => 'issues', :action => 'index', :project_id => '23'
92 )
92 )
93 end
93 end
94
94
95 def test_index_should_not_list_issues_when_module_disabled
95 def test_index_should_not_list_issues_when_module_disabled
96 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
96 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
97 get :index
97 get :index
98 assert_response :success
98 assert_response :success
99 assert_template 'index.rhtml'
99 assert_template 'index.rhtml'
100 assert_not_nil assigns(:issues)
100 assert_not_nil assigns(:issues)
101 assert_nil assigns(:project)
101 assert_nil assigns(:project)
102 assert_no_tag :tag => 'a', :content => /Can't print recipes/
102 assert_no_tag :tag => 'a', :content => /Can't print recipes/
103 assert_tag :tag => 'a', :content => /Subproject issue/
103 assert_tag :tag => 'a', :content => /Subproject issue/
104 end
104 end
105
105
106 def test_index_with_project_routing
106 def test_index_with_project_routing
107 assert_routing(
107 assert_routing(
108 {:method => :get, :path => 'projects/23/issues'},
108 {:method => :get, :path => 'projects/23/issues'},
109 :controller => 'issues', :action => 'index', :project_id => '23'
109 :controller => 'issues', :action => 'index', :project_id => '23'
110 )
110 )
111 end
111 end
112
112
113 def test_index_with_project
113 def test_index_with_project
114 Setting.display_subprojects_issues = 0
114 Setting.display_subprojects_issues = 0
115 get :index, :project_id => 1
115 get :index, :project_id => 1
116 assert_response :success
116 assert_response :success
117 assert_template 'index.rhtml'
117 assert_template 'index.rhtml'
118 assert_not_nil assigns(:issues)
118 assert_not_nil assigns(:issues)
119 assert_tag :tag => 'a', :content => /Can't print recipes/
119 assert_tag :tag => 'a', :content => /Can't print recipes/
120 assert_no_tag :tag => 'a', :content => /Subproject issue/
120 assert_no_tag :tag => 'a', :content => /Subproject issue/
121 end
121 end
122
122
123 def test_index_with_project_and_subprojects
123 def test_index_with_project_and_subprojects
124 Setting.display_subprojects_issues = 1
124 Setting.display_subprojects_issues = 1
125 get :index, :project_id => 1
125 get :index, :project_id => 1
126 assert_response :success
126 assert_response :success
127 assert_template 'index.rhtml'
127 assert_template 'index.rhtml'
128 assert_not_nil assigns(:issues)
128 assert_not_nil assigns(:issues)
129 assert_tag :tag => 'a', :content => /Can't print recipes/
129 assert_tag :tag => 'a', :content => /Can't print recipes/
130 assert_tag :tag => 'a', :content => /Subproject issue/
130 assert_tag :tag => 'a', :content => /Subproject issue/
131 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
131 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
132 end
132 end
133
133
134 def test_index_with_project_and_subprojects_should_show_private_subprojects
134 def test_index_with_project_and_subprojects_should_show_private_subprojects
135 @request.session[:user_id] = 2
135 @request.session[:user_id] = 2
136 Setting.display_subprojects_issues = 1
136 Setting.display_subprojects_issues = 1
137 get :index, :project_id => 1
137 get :index, :project_id => 1
138 assert_response :success
138 assert_response :success
139 assert_template 'index.rhtml'
139 assert_template 'index.rhtml'
140 assert_not_nil assigns(:issues)
140 assert_not_nil assigns(:issues)
141 assert_tag :tag => 'a', :content => /Can't print recipes/
141 assert_tag :tag => 'a', :content => /Can't print recipes/
142 assert_tag :tag => 'a', :content => /Subproject issue/
142 assert_tag :tag => 'a', :content => /Subproject issue/
143 assert_tag :tag => 'a', :content => /Issue of a private subproject/
143 assert_tag :tag => 'a', :content => /Issue of a private subproject/
144 end
144 end
145
145
146 def test_index_with_project_routing_formatted
146 def test_index_with_project_routing_formatted
147 assert_routing(
147 assert_routing(
148 {:method => :get, :path => 'projects/23/issues.pdf'},
148 {:method => :get, :path => 'projects/23/issues.pdf'},
149 :controller => 'issues', :action => 'index', :project_id => '23', :format => 'pdf'
149 :controller => 'issues', :action => 'index', :project_id => '23', :format => 'pdf'
150 )
150 )
151 assert_routing(
151 assert_routing(
152 {:method => :get, :path => 'projects/23/issues.atom'},
152 {:method => :get, :path => 'projects/23/issues.atom'},
153 :controller => 'issues', :action => 'index', :project_id => '23', :format => 'atom'
153 :controller => 'issues', :action => 'index', :project_id => '23', :format => 'atom'
154 )
154 )
155 end
155 end
156
156
157 def test_index_with_project_and_filter
157 def test_index_with_project_and_filter
158 get :index, :project_id => 1, :set_filter => 1
158 get :index, :project_id => 1, :set_filter => 1
159 assert_response :success
159 assert_response :success
160 assert_template 'index.rhtml'
160 assert_template 'index.rhtml'
161 assert_not_nil assigns(:issues)
161 assert_not_nil assigns(:issues)
162 end
162 end
163
163
164 def test_index_csv_with_project
164 def test_index_csv_with_project
165 get :index, :format => 'csv'
165 get :index, :format => 'csv'
166 assert_response :success
166 assert_response :success
167 assert_not_nil assigns(:issues)
167 assert_not_nil assigns(:issues)
168 assert_equal 'text/csv', @response.content_type
168 assert_equal 'text/csv', @response.content_type
169
169
170 get :index, :project_id => 1, :format => 'csv'
170 get :index, :project_id => 1, :format => 'csv'
171 assert_response :success
171 assert_response :success
172 assert_not_nil assigns(:issues)
172 assert_not_nil assigns(:issues)
173 assert_equal 'text/csv', @response.content_type
173 assert_equal 'text/csv', @response.content_type
174 end
174 end
175
175
176 def test_index_formatted
176 def test_index_formatted
177 assert_routing(
177 assert_routing(
178 {:method => :get, :path => 'issues.pdf'},
178 {:method => :get, :path => 'issues.pdf'},
179 :controller => 'issues', :action => 'index', :format => 'pdf'
179 :controller => 'issues', :action => 'index', :format => 'pdf'
180 )
180 )
181 assert_routing(
181 assert_routing(
182 {:method => :get, :path => 'issues.atom'},
182 {:method => :get, :path => 'issues.atom'},
183 :controller => 'issues', :action => 'index', :format => 'atom'
183 :controller => 'issues', :action => 'index', :format => 'atom'
184 )
184 )
185 end
185 end
186
186
187 def test_index_pdf
187 def test_index_pdf
188 get :index, :format => 'pdf'
188 get :index, :format => 'pdf'
189 assert_response :success
189 assert_response :success
190 assert_not_nil assigns(:issues)
190 assert_not_nil assigns(:issues)
191 assert_equal 'application/pdf', @response.content_type
191 assert_equal 'application/pdf', @response.content_type
192
192
193 get :index, :project_id => 1, :format => 'pdf'
193 get :index, :project_id => 1, :format => 'pdf'
194 assert_response :success
194 assert_response :success
195 assert_not_nil assigns(:issues)
195 assert_not_nil assigns(:issues)
196 assert_equal 'application/pdf', @response.content_type
196 assert_equal 'application/pdf', @response.content_type
197 end
197 end
198
198
199 def test_index_sort
199 def test_index_sort
200 get :index, :sort_key => 'tracker'
200 get :index, :sort => 'tracker,id:desc'
201 assert_response :success
201 assert_response :success
202
202
203 sort_params = @request.session['issuesindex_sort']
203 sort_params = @request.session['issues_index_sort']
204 assert sort_params.is_a?(Hash)
204 assert sort_params.is_a?(String)
205 assert_equal 'tracker', sort_params[:key]
205 assert_equal 'tracker,id:desc', sort_params
206 assert_equal 'ASC', sort_params[:order]
206
207 issues = assigns(:issues)
208 assert_not_nil issues
209 assert !issues.empty?
210 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
207 end
211 end
208
212
209 def test_gantt
213 def test_gantt
210 get :gantt, :project_id => 1
214 get :gantt, :project_id => 1
211 assert_response :success
215 assert_response :success
212 assert_template 'gantt.rhtml'
216 assert_template 'gantt.rhtml'
213 assert_not_nil assigns(:gantt)
217 assert_not_nil assigns(:gantt)
214 events = assigns(:gantt).events
218 events = assigns(:gantt).events
215 assert_not_nil events
219 assert_not_nil events
216 # Issue with start and due dates
220 # Issue with start and due dates
217 i = Issue.find(1)
221 i = Issue.find(1)
218 assert_not_nil i.due_date
222 assert_not_nil i.due_date
219 assert events.include?(Issue.find(1))
223 assert events.include?(Issue.find(1))
220 # Issue with without due date but targeted to a version with date
224 # Issue with without due date but targeted to a version with date
221 i = Issue.find(2)
225 i = Issue.find(2)
222 assert_nil i.due_date
226 assert_nil i.due_date
223 assert events.include?(i)
227 assert events.include?(i)
224 end
228 end
225
229
226 def test_cross_project_gantt
230 def test_cross_project_gantt
227 get :gantt
231 get :gantt
228 assert_response :success
232 assert_response :success
229 assert_template 'gantt.rhtml'
233 assert_template 'gantt.rhtml'
230 assert_not_nil assigns(:gantt)
234 assert_not_nil assigns(:gantt)
231 events = assigns(:gantt).events
235 events = assigns(:gantt).events
232 assert_not_nil events
236 assert_not_nil events
233 end
237 end
234
238
235 def test_gantt_export_to_pdf
239 def test_gantt_export_to_pdf
236 get :gantt, :project_id => 1, :format => 'pdf'
240 get :gantt, :project_id => 1, :format => 'pdf'
237 assert_response :success
241 assert_response :success
238 assert_equal 'application/pdf', @response.content_type
242 assert_equal 'application/pdf', @response.content_type
239 assert @response.body.starts_with?('%PDF')
243 assert @response.body.starts_with?('%PDF')
240 assert_not_nil assigns(:gantt)
244 assert_not_nil assigns(:gantt)
241 end
245 end
242
246
243 def test_cross_project_gantt_export_to_pdf
247 def test_cross_project_gantt_export_to_pdf
244 get :gantt, :format => 'pdf'
248 get :gantt, :format => 'pdf'
245 assert_response :success
249 assert_response :success
246 assert_equal 'application/pdf', @response.content_type
250 assert_equal 'application/pdf', @response.content_type
247 assert @response.body.starts_with?('%PDF')
251 assert @response.body.starts_with?('%PDF')
248 assert_not_nil assigns(:gantt)
252 assert_not_nil assigns(:gantt)
249 end
253 end
250
254
251 if Object.const_defined?(:Magick)
255 if Object.const_defined?(:Magick)
252 def test_gantt_image
256 def test_gantt_image
253 get :gantt, :project_id => 1, :format => 'png'
257 get :gantt, :project_id => 1, :format => 'png'
254 assert_response :success
258 assert_response :success
255 assert_equal 'image/png', @response.content_type
259 assert_equal 'image/png', @response.content_type
256 end
260 end
257 else
261 else
258 puts "RMagick not installed. Skipping tests !!!"
262 puts "RMagick not installed. Skipping tests !!!"
259 end
263 end
260
264
261 def test_calendar
265 def test_calendar
262 get :calendar, :project_id => 1
266 get :calendar, :project_id => 1
263 assert_response :success
267 assert_response :success
264 assert_template 'calendar'
268 assert_template 'calendar'
265 assert_not_nil assigns(:calendar)
269 assert_not_nil assigns(:calendar)
266 end
270 end
267
271
268 def test_cross_project_calendar
272 def test_cross_project_calendar
269 get :calendar
273 get :calendar
270 assert_response :success
274 assert_response :success
271 assert_template 'calendar'
275 assert_template 'calendar'
272 assert_not_nil assigns(:calendar)
276 assert_not_nil assigns(:calendar)
273 end
277 end
274
278
275 def test_changes
279 def test_changes
276 get :changes, :project_id => 1
280 get :changes, :project_id => 1
277 assert_response :success
281 assert_response :success
278 assert_not_nil assigns(:journals)
282 assert_not_nil assigns(:journals)
279 assert_equal 'application/atom+xml', @response.content_type
283 assert_equal 'application/atom+xml', @response.content_type
280 end
284 end
281
285
282 def test_show_routing
286 def test_show_routing
283 assert_routing(
287 assert_routing(
284 {:method => :get, :path => '/issues/64'},
288 {:method => :get, :path => '/issues/64'},
285 :controller => 'issues', :action => 'show', :id => '64'
289 :controller => 'issues', :action => 'show', :id => '64'
286 )
290 )
287 end
291 end
288
292
289 def test_show_routing_formatted
293 def test_show_routing_formatted
290 assert_routing(
294 assert_routing(
291 {:method => :get, :path => '/issues/2332.pdf'},
295 {:method => :get, :path => '/issues/2332.pdf'},
292 :controller => 'issues', :action => 'show', :id => '2332', :format => 'pdf'
296 :controller => 'issues', :action => 'show', :id => '2332', :format => 'pdf'
293 )
297 )
294 assert_routing(
298 assert_routing(
295 {:method => :get, :path => '/issues/23123.atom'},
299 {:method => :get, :path => '/issues/23123.atom'},
296 :controller => 'issues', :action => 'show', :id => '23123', :format => 'atom'
300 :controller => 'issues', :action => 'show', :id => '23123', :format => 'atom'
297 )
301 )
298 end
302 end
299
303
300 def test_show_by_anonymous
304 def test_show_by_anonymous
301 get :show, :id => 1
305 get :show, :id => 1
302 assert_response :success
306 assert_response :success
303 assert_template 'show.rhtml'
307 assert_template 'show.rhtml'
304 assert_not_nil assigns(:issue)
308 assert_not_nil assigns(:issue)
305 assert_equal Issue.find(1), assigns(:issue)
309 assert_equal Issue.find(1), assigns(:issue)
306
310
307 # anonymous role is allowed to add a note
311 # anonymous role is allowed to add a note
308 assert_tag :tag => 'form',
312 assert_tag :tag => 'form',
309 :descendant => { :tag => 'fieldset',
313 :descendant => { :tag => 'fieldset',
310 :child => { :tag => 'legend',
314 :child => { :tag => 'legend',
311 :content => /Notes/ } }
315 :content => /Notes/ } }
312 end
316 end
313
317
314 def test_show_by_manager
318 def test_show_by_manager
315 @request.session[:user_id] = 2
319 @request.session[:user_id] = 2
316 get :show, :id => 1
320 get :show, :id => 1
317 assert_response :success
321 assert_response :success
318
322
319 assert_tag :tag => 'form',
323 assert_tag :tag => 'form',
320 :descendant => { :tag => 'fieldset',
324 :descendant => { :tag => 'fieldset',
321 :child => { :tag => 'legend',
325 :child => { :tag => 'legend',
322 :content => /Change properties/ } },
326 :content => /Change properties/ } },
323 :descendant => { :tag => 'fieldset',
327 :descendant => { :tag => 'fieldset',
324 :child => { :tag => 'legend',
328 :child => { :tag => 'legend',
325 :content => /Log time/ } },
329 :content => /Log time/ } },
326 :descendant => { :tag => 'fieldset',
330 :descendant => { :tag => 'fieldset',
327 :child => { :tag => 'legend',
331 :child => { :tag => 'legend',
328 :content => /Notes/ } }
332 :content => /Notes/ } }
329 end
333 end
330
334
331 def test_show_should_not_disclose_relations_to_invisible_issues
335 def test_show_should_not_disclose_relations_to_invisible_issues
332 Setting.cross_project_issue_relations = '1'
336 Setting.cross_project_issue_relations = '1'
333 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
337 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
334 # Relation to a private project issue
338 # Relation to a private project issue
335 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
339 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
336
340
337 get :show, :id => 1
341 get :show, :id => 1
338 assert_response :success
342 assert_response :success
339
343
340 assert_tag :div, :attributes => { :id => 'relations' },
344 assert_tag :div, :attributes => { :id => 'relations' },
341 :descendant => { :tag => 'a', :content => /#2$/ }
345 :descendant => { :tag => 'a', :content => /#2$/ }
342 assert_no_tag :div, :attributes => { :id => 'relations' },
346 assert_no_tag :div, :attributes => { :id => 'relations' },
343 :descendant => { :tag => 'a', :content => /#4$/ }
347 :descendant => { :tag => 'a', :content => /#4$/ }
344 end
348 end
345
349
346 def test_new_routing
350 def test_new_routing
347 assert_routing(
351 assert_routing(
348 {:method => :get, :path => '/projects/1/issues/new'},
352 {:method => :get, :path => '/projects/1/issues/new'},
349 :controller => 'issues', :action => 'new', :project_id => '1'
353 :controller => 'issues', :action => 'new', :project_id => '1'
350 )
354 )
351 assert_recognizes(
355 assert_recognizes(
352 {:controller => 'issues', :action => 'new', :project_id => '1'},
356 {:controller => 'issues', :action => 'new', :project_id => '1'},
353 {:method => :post, :path => '/projects/1/issues'}
357 {:method => :post, :path => '/projects/1/issues'}
354 )
358 )
355 end
359 end
356
360
357 def test_show_export_to_pdf
361 def test_show_export_to_pdf
358 get :show, :id => 3, :format => 'pdf'
362 get :show, :id => 3, :format => 'pdf'
359 assert_response :success
363 assert_response :success
360 assert_equal 'application/pdf', @response.content_type
364 assert_equal 'application/pdf', @response.content_type
361 assert @response.body.starts_with?('%PDF')
365 assert @response.body.starts_with?('%PDF')
362 assert_not_nil assigns(:issue)
366 assert_not_nil assigns(:issue)
363 end
367 end
364
368
365 def test_get_new
369 def test_get_new
366 @request.session[:user_id] = 2
370 @request.session[:user_id] = 2
367 get :new, :project_id => 1, :tracker_id => 1
371 get :new, :project_id => 1, :tracker_id => 1
368 assert_response :success
372 assert_response :success
369 assert_template 'new'
373 assert_template 'new'
370
374
371 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
375 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
372 :value => 'Default string' }
376 :value => 'Default string' }
373 end
377 end
374
378
375 def test_get_new_without_tracker_id
379 def test_get_new_without_tracker_id
376 @request.session[:user_id] = 2
380 @request.session[:user_id] = 2
377 get :new, :project_id => 1
381 get :new, :project_id => 1
378 assert_response :success
382 assert_response :success
379 assert_template 'new'
383 assert_template 'new'
380
384
381 issue = assigns(:issue)
385 issue = assigns(:issue)
382 assert_not_nil issue
386 assert_not_nil issue
383 assert_equal Project.find(1).trackers.first, issue.tracker
387 assert_equal Project.find(1).trackers.first, issue.tracker
384 end
388 end
385
389
386 def test_get_new_with_no_default_status_should_display_an_error
390 def test_get_new_with_no_default_status_should_display_an_error
387 @request.session[:user_id] = 2
391 @request.session[:user_id] = 2
388 IssueStatus.delete_all
392 IssueStatus.delete_all
389
393
390 get :new, :project_id => 1
394 get :new, :project_id => 1
391 assert_response 500
395 assert_response 500
392 assert_not_nil flash[:error]
396 assert_not_nil flash[:error]
393 assert_tag :tag => 'div', :attributes => { :class => /error/ },
397 assert_tag :tag => 'div', :attributes => { :class => /error/ },
394 :content => /No default issue/
398 :content => /No default issue/
395 end
399 end
396
400
397 def test_get_new_with_no_tracker_should_display_an_error
401 def test_get_new_with_no_tracker_should_display_an_error
398 @request.session[:user_id] = 2
402 @request.session[:user_id] = 2
399 Tracker.delete_all
403 Tracker.delete_all
400
404
401 get :new, :project_id => 1
405 get :new, :project_id => 1
402 assert_response 500
406 assert_response 500
403 assert_not_nil flash[:error]
407 assert_not_nil flash[:error]
404 assert_tag :tag => 'div', :attributes => { :class => /error/ },
408 assert_tag :tag => 'div', :attributes => { :class => /error/ },
405 :content => /No tracker/
409 :content => /No tracker/
406 end
410 end
407
411
408 def test_update_new_form
412 def test_update_new_form
409 @request.session[:user_id] = 2
413 @request.session[:user_id] = 2
410 xhr :post, :new, :project_id => 1,
414 xhr :post, :new, :project_id => 1,
411 :issue => {:tracker_id => 2,
415 :issue => {:tracker_id => 2,
412 :subject => 'This is the test_new issue',
416 :subject => 'This is the test_new issue',
413 :description => 'This is the description',
417 :description => 'This is the description',
414 :priority_id => 5}
418 :priority_id => 5}
415 assert_response :success
419 assert_response :success
416 assert_template 'new'
420 assert_template 'new'
417 end
421 end
418
422
419 def test_post_new
423 def test_post_new
420 @request.session[:user_id] = 2
424 @request.session[:user_id] = 2
421 post :new, :project_id => 1,
425 post :new, :project_id => 1,
422 :issue => {:tracker_id => 3,
426 :issue => {:tracker_id => 3,
423 :subject => 'This is the test_new issue',
427 :subject => 'This is the test_new issue',
424 :description => 'This is the description',
428 :description => 'This is the description',
425 :priority_id => 5,
429 :priority_id => 5,
426 :estimated_hours => '',
430 :estimated_hours => '',
427 :custom_field_values => {'2' => 'Value for field 2'}}
431 :custom_field_values => {'2' => 'Value for field 2'}}
428 assert_redirected_to :action => 'show'
432 assert_redirected_to :action => 'show'
429
433
430 issue = Issue.find_by_subject('This is the test_new issue')
434 issue = Issue.find_by_subject('This is the test_new issue')
431 assert_not_nil issue
435 assert_not_nil issue
432 assert_equal 2, issue.author_id
436 assert_equal 2, issue.author_id
433 assert_equal 3, issue.tracker_id
437 assert_equal 3, issue.tracker_id
434 assert_nil issue.estimated_hours
438 assert_nil issue.estimated_hours
435 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
439 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
436 assert_not_nil v
440 assert_not_nil v
437 assert_equal 'Value for field 2', v.value
441 assert_equal 'Value for field 2', v.value
438 end
442 end
439
443
440 def test_post_new_and_continue
444 def test_post_new_and_continue
441 @request.session[:user_id] = 2
445 @request.session[:user_id] = 2
442 post :new, :project_id => 1,
446 post :new, :project_id => 1,
443 :issue => {:tracker_id => 3,
447 :issue => {:tracker_id => 3,
444 :subject => 'This is first issue',
448 :subject => 'This is first issue',
445 :priority_id => 5},
449 :priority_id => 5},
446 :continue => ''
450 :continue => ''
447 assert_redirected_to :controller => 'issues', :action => 'new', :tracker_id => 3
451 assert_redirected_to :controller => 'issues', :action => 'new', :tracker_id => 3
448 end
452 end
449
453
450 def test_post_new_without_custom_fields_param
454 def test_post_new_without_custom_fields_param
451 @request.session[:user_id] = 2
455 @request.session[:user_id] = 2
452 post :new, :project_id => 1,
456 post :new, :project_id => 1,
453 :issue => {:tracker_id => 1,
457 :issue => {:tracker_id => 1,
454 :subject => 'This is the test_new issue',
458 :subject => 'This is the test_new issue',
455 :description => 'This is the description',
459 :description => 'This is the description',
456 :priority_id => 5}
460 :priority_id => 5}
457 assert_redirected_to :action => 'show'
461 assert_redirected_to :action => 'show'
458 end
462 end
459
463
460 def test_post_new_with_required_custom_field_and_without_custom_fields_param
464 def test_post_new_with_required_custom_field_and_without_custom_fields_param
461 field = IssueCustomField.find_by_name('Database')
465 field = IssueCustomField.find_by_name('Database')
462 field.update_attribute(:is_required, true)
466 field.update_attribute(:is_required, true)
463
467
464 @request.session[:user_id] = 2
468 @request.session[:user_id] = 2
465 post :new, :project_id => 1,
469 post :new, :project_id => 1,
466 :issue => {:tracker_id => 1,
470 :issue => {:tracker_id => 1,
467 :subject => 'This is the test_new issue',
471 :subject => 'This is the test_new issue',
468 :description => 'This is the description',
472 :description => 'This is the description',
469 :priority_id => 5}
473 :priority_id => 5}
470 assert_response :success
474 assert_response :success
471 assert_template 'new'
475 assert_template 'new'
472 issue = assigns(:issue)
476 issue = assigns(:issue)
473 assert_not_nil issue
477 assert_not_nil issue
474 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
478 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
475 end
479 end
476
480
477 def test_post_new_with_watchers
481 def test_post_new_with_watchers
478 @request.session[:user_id] = 2
482 @request.session[:user_id] = 2
479 ActionMailer::Base.deliveries.clear
483 ActionMailer::Base.deliveries.clear
480
484
481 assert_difference 'Watcher.count', 2 do
485 assert_difference 'Watcher.count', 2 do
482 post :new, :project_id => 1,
486 post :new, :project_id => 1,
483 :issue => {:tracker_id => 1,
487 :issue => {:tracker_id => 1,
484 :subject => 'This is a new issue with watchers',
488 :subject => 'This is a new issue with watchers',
485 :description => 'This is the description',
489 :description => 'This is the description',
486 :priority_id => 5,
490 :priority_id => 5,
487 :watcher_user_ids => ['2', '3']}
491 :watcher_user_ids => ['2', '3']}
488 end
492 end
489 issue = Issue.find_by_subject('This is a new issue with watchers')
493 issue = Issue.find_by_subject('This is a new issue with watchers')
490 assert_not_nil issue
494 assert_not_nil issue
491 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
495 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
492
496
493 # Watchers added
497 # Watchers added
494 assert_equal [2, 3], issue.watcher_user_ids.sort
498 assert_equal [2, 3], issue.watcher_user_ids.sort
495 assert issue.watched_by?(User.find(3))
499 assert issue.watched_by?(User.find(3))
496 # Watchers notified
500 # Watchers notified
497 mail = ActionMailer::Base.deliveries.last
501 mail = ActionMailer::Base.deliveries.last
498 assert_kind_of TMail::Mail, mail
502 assert_kind_of TMail::Mail, mail
499 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
503 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
500 end
504 end
501
505
502 def test_post_should_preserve_fields_values_on_validation_failure
506 def test_post_should_preserve_fields_values_on_validation_failure
503 @request.session[:user_id] = 2
507 @request.session[:user_id] = 2
504 post :new, :project_id => 1,
508 post :new, :project_id => 1,
505 :issue => {:tracker_id => 1,
509 :issue => {:tracker_id => 1,
506 # empty subject
510 # empty subject
507 :subject => '',
511 :subject => '',
508 :description => 'This is a description',
512 :description => 'This is a description',
509 :priority_id => 6,
513 :priority_id => 6,
510 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
514 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
511 assert_response :success
515 assert_response :success
512 assert_template 'new'
516 assert_template 'new'
513
517
514 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
518 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
515 :content => 'This is a description'
519 :content => 'This is a description'
516 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
520 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
517 :child => { :tag => 'option', :attributes => { :selected => 'selected',
521 :child => { :tag => 'option', :attributes => { :selected => 'selected',
518 :value => '6' },
522 :value => '6' },
519 :content => 'High' }
523 :content => 'High' }
520 # Custom fields
524 # Custom fields
521 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
525 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
522 :child => { :tag => 'option', :attributes => { :selected => 'selected',
526 :child => { :tag => 'option', :attributes => { :selected => 'selected',
523 :value => 'Oracle' },
527 :value => 'Oracle' },
524 :content => 'Oracle' }
528 :content => 'Oracle' }
525 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
529 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
526 :value => 'Value for field 2'}
530 :value => 'Value for field 2'}
527 end
531 end
528
532
529 def test_copy_routing
533 def test_copy_routing
530 assert_routing(
534 assert_routing(
531 {:method => :get, :path => '/projects/world_domination/issues/567/copy'},
535 {:method => :get, :path => '/projects/world_domination/issues/567/copy'},
532 :controller => 'issues', :action => 'new', :project_id => 'world_domination', :copy_from => '567'
536 :controller => 'issues', :action => 'new', :project_id => 'world_domination', :copy_from => '567'
533 )
537 )
534 end
538 end
535
539
536 def test_copy_issue
540 def test_copy_issue
537 @request.session[:user_id] = 2
541 @request.session[:user_id] = 2
538 get :new, :project_id => 1, :copy_from => 1
542 get :new, :project_id => 1, :copy_from => 1
539 assert_template 'new'
543 assert_template 'new'
540 assert_not_nil assigns(:issue)
544 assert_not_nil assigns(:issue)
541 orig = Issue.find(1)
545 orig = Issue.find(1)
542 assert_equal orig.subject, assigns(:issue).subject
546 assert_equal orig.subject, assigns(:issue).subject
543 end
547 end
544
548
545 def test_edit_routing
549 def test_edit_routing
546 assert_routing(
550 assert_routing(
547 {:method => :get, :path => '/issues/1/edit'},
551 {:method => :get, :path => '/issues/1/edit'},
548 :controller => 'issues', :action => 'edit', :id => '1'
552 :controller => 'issues', :action => 'edit', :id => '1'
549 )
553 )
550 assert_recognizes( #TODO: use a PUT on the issue URI isntead, need to adjust form
554 assert_recognizes( #TODO: use a PUT on the issue URI isntead, need to adjust form
551 {:controller => 'issues', :action => 'edit', :id => '1'},
555 {:controller => 'issues', :action => 'edit', :id => '1'},
552 {:method => :post, :path => '/issues/1/edit'}
556 {:method => :post, :path => '/issues/1/edit'}
553 )
557 )
554 end
558 end
555
559
556 def test_get_edit
560 def test_get_edit
557 @request.session[:user_id] = 2
561 @request.session[:user_id] = 2
558 get :edit, :id => 1
562 get :edit, :id => 1
559 assert_response :success
563 assert_response :success
560 assert_template 'edit'
564 assert_template 'edit'
561 assert_not_nil assigns(:issue)
565 assert_not_nil assigns(:issue)
562 assert_equal Issue.find(1), assigns(:issue)
566 assert_equal Issue.find(1), assigns(:issue)
563 end
567 end
564
568
565 def test_get_edit_with_params
569 def test_get_edit_with_params
566 @request.session[:user_id] = 2
570 @request.session[:user_id] = 2
567 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
571 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
568 assert_response :success
572 assert_response :success
569 assert_template 'edit'
573 assert_template 'edit'
570
574
571 issue = assigns(:issue)
575 issue = assigns(:issue)
572 assert_not_nil issue
576 assert_not_nil issue
573
577
574 assert_equal 5, issue.status_id
578 assert_equal 5, issue.status_id
575 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
579 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
576 :child => { :tag => 'option',
580 :child => { :tag => 'option',
577 :content => 'Closed',
581 :content => 'Closed',
578 :attributes => { :selected => 'selected' } }
582 :attributes => { :selected => 'selected' } }
579
583
580 assert_equal 7, issue.priority_id
584 assert_equal 7, issue.priority_id
581 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
585 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
582 :child => { :tag => 'option',
586 :child => { :tag => 'option',
583 :content => 'Urgent',
587 :content => 'Urgent',
584 :attributes => { :selected => 'selected' } }
588 :attributes => { :selected => 'selected' } }
585 end
589 end
586
590
587 def test_reply_routing
591 def test_reply_routing
588 assert_routing(
592 assert_routing(
589 {:method => :post, :path => '/issues/1/quoted'},
593 {:method => :post, :path => '/issues/1/quoted'},
590 :controller => 'issues', :action => 'reply', :id => '1'
594 :controller => 'issues', :action => 'reply', :id => '1'
591 )
595 )
592 end
596 end
593
597
594 def test_reply_to_issue
598 def test_reply_to_issue
595 @request.session[:user_id] = 2
599 @request.session[:user_id] = 2
596 get :reply, :id => 1
600 get :reply, :id => 1
597 assert_response :success
601 assert_response :success
598 assert_select_rjs :show, "update"
602 assert_select_rjs :show, "update"
599 end
603 end
600
604
601 def test_reply_to_note
605 def test_reply_to_note
602 @request.session[:user_id] = 2
606 @request.session[:user_id] = 2
603 get :reply, :id => 1, :journal_id => 2
607 get :reply, :id => 1, :journal_id => 2
604 assert_response :success
608 assert_response :success
605 assert_select_rjs :show, "update"
609 assert_select_rjs :show, "update"
606 end
610 end
607
611
608 def test_post_edit_without_custom_fields_param
612 def test_post_edit_without_custom_fields_param
609 @request.session[:user_id] = 2
613 @request.session[:user_id] = 2
610 ActionMailer::Base.deliveries.clear
614 ActionMailer::Base.deliveries.clear
611
615
612 issue = Issue.find(1)
616 issue = Issue.find(1)
613 assert_equal '125', issue.custom_value_for(2).value
617 assert_equal '125', issue.custom_value_for(2).value
614 old_subject = issue.subject
618 old_subject = issue.subject
615 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
619 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
616
620
617 assert_difference('Journal.count') do
621 assert_difference('Journal.count') do
618 assert_difference('JournalDetail.count', 2) do
622 assert_difference('JournalDetail.count', 2) do
619 post :edit, :id => 1, :issue => {:subject => new_subject,
623 post :edit, :id => 1, :issue => {:subject => new_subject,
620 :priority_id => '6',
624 :priority_id => '6',
621 :category_id => '1' # no change
625 :category_id => '1' # no change
622 }
626 }
623 end
627 end
624 end
628 end
625 assert_redirected_to :action => 'show', :id => '1'
629 assert_redirected_to :action => 'show', :id => '1'
626 issue.reload
630 issue.reload
627 assert_equal new_subject, issue.subject
631 assert_equal new_subject, issue.subject
628 # Make sure custom fields were not cleared
632 # Make sure custom fields were not cleared
629 assert_equal '125', issue.custom_value_for(2).value
633 assert_equal '125', issue.custom_value_for(2).value
630
634
631 mail = ActionMailer::Base.deliveries.last
635 mail = ActionMailer::Base.deliveries.last
632 assert_kind_of TMail::Mail, mail
636 assert_kind_of TMail::Mail, mail
633 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
637 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
634 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
638 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
635 end
639 end
636
640
637 def test_post_edit_with_custom_field_change
641 def test_post_edit_with_custom_field_change
638 @request.session[:user_id] = 2
642 @request.session[:user_id] = 2
639 issue = Issue.find(1)
643 issue = Issue.find(1)
640 assert_equal '125', issue.custom_value_for(2).value
644 assert_equal '125', issue.custom_value_for(2).value
641
645
642 assert_difference('Journal.count') do
646 assert_difference('Journal.count') do
643 assert_difference('JournalDetail.count', 3) do
647 assert_difference('JournalDetail.count', 3) do
644 post :edit, :id => 1, :issue => {:subject => 'Custom field change',
648 post :edit, :id => 1, :issue => {:subject => 'Custom field change',
645 :priority_id => '6',
649 :priority_id => '6',
646 :category_id => '1', # no change
650 :category_id => '1', # no change
647 :custom_field_values => { '2' => 'New custom value' }
651 :custom_field_values => { '2' => 'New custom value' }
648 }
652 }
649 end
653 end
650 end
654 end
651 assert_redirected_to :action => 'show', :id => '1'
655 assert_redirected_to :action => 'show', :id => '1'
652 issue.reload
656 issue.reload
653 assert_equal 'New custom value', issue.custom_value_for(2).value
657 assert_equal 'New custom value', issue.custom_value_for(2).value
654
658
655 mail = ActionMailer::Base.deliveries.last
659 mail = ActionMailer::Base.deliveries.last
656 assert_kind_of TMail::Mail, mail
660 assert_kind_of TMail::Mail, mail
657 assert mail.body.include?("Searchable field changed from 125 to New custom value")
661 assert mail.body.include?("Searchable field changed from 125 to New custom value")
658 end
662 end
659
663
660 def test_post_edit_with_status_and_assignee_change
664 def test_post_edit_with_status_and_assignee_change
661 issue = Issue.find(1)
665 issue = Issue.find(1)
662 assert_equal 1, issue.status_id
666 assert_equal 1, issue.status_id
663 @request.session[:user_id] = 2
667 @request.session[:user_id] = 2
664 assert_difference('TimeEntry.count', 0) do
668 assert_difference('TimeEntry.count', 0) do
665 post :edit,
669 post :edit,
666 :id => 1,
670 :id => 1,
667 :issue => { :status_id => 2, :assigned_to_id => 3 },
671 :issue => { :status_id => 2, :assigned_to_id => 3 },
668 :notes => 'Assigned to dlopper',
672 :notes => 'Assigned to dlopper',
669 :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.activities.first }
673 :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.activities.first }
670 end
674 end
671 assert_redirected_to :action => 'show', :id => '1'
675 assert_redirected_to :action => 'show', :id => '1'
672 issue.reload
676 issue.reload
673 assert_equal 2, issue.status_id
677 assert_equal 2, issue.status_id
674 j = issue.journals.find(:first, :order => 'id DESC')
678 j = issue.journals.find(:first, :order => 'id DESC')
675 assert_equal 'Assigned to dlopper', j.notes
679 assert_equal 'Assigned to dlopper', j.notes
676 assert_equal 2, j.details.size
680 assert_equal 2, j.details.size
677
681
678 mail = ActionMailer::Base.deliveries.last
682 mail = ActionMailer::Base.deliveries.last
679 assert mail.body.include?("Status changed from New to Assigned")
683 assert mail.body.include?("Status changed from New to Assigned")
680 end
684 end
681
685
682 def test_post_edit_with_note_only
686 def test_post_edit_with_note_only
683 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
687 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
684 # anonymous user
688 # anonymous user
685 post :edit,
689 post :edit,
686 :id => 1,
690 :id => 1,
687 :notes => notes
691 :notes => notes
688 assert_redirected_to :action => 'show', :id => '1'
692 assert_redirected_to :action => 'show', :id => '1'
689 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
693 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
690 assert_equal notes, j.notes
694 assert_equal notes, j.notes
691 assert_equal 0, j.details.size
695 assert_equal 0, j.details.size
692 assert_equal User.anonymous, j.user
696 assert_equal User.anonymous, j.user
693
697
694 mail = ActionMailer::Base.deliveries.last
698 mail = ActionMailer::Base.deliveries.last
695 assert mail.body.include?(notes)
699 assert mail.body.include?(notes)
696 end
700 end
697
701
698 def test_post_edit_with_note_and_spent_time
702 def test_post_edit_with_note_and_spent_time
699 @request.session[:user_id] = 2
703 @request.session[:user_id] = 2
700 spent_hours_before = Issue.find(1).spent_hours
704 spent_hours_before = Issue.find(1).spent_hours
701 assert_difference('TimeEntry.count') do
705 assert_difference('TimeEntry.count') do
702 post :edit,
706 post :edit,
703 :id => 1,
707 :id => 1,
704 :notes => '2.5 hours added',
708 :notes => '2.5 hours added',
705 :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.activities.first }
709 :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.activities.first }
706 end
710 end
707 assert_redirected_to :action => 'show', :id => '1'
711 assert_redirected_to :action => 'show', :id => '1'
708
712
709 issue = Issue.find(1)
713 issue = Issue.find(1)
710
714
711 j = issue.journals.find(:first, :order => 'id DESC')
715 j = issue.journals.find(:first, :order => 'id DESC')
712 assert_equal '2.5 hours added', j.notes
716 assert_equal '2.5 hours added', j.notes
713 assert_equal 0, j.details.size
717 assert_equal 0, j.details.size
714
718
715 t = issue.time_entries.find(:first, :order => 'id DESC')
719 t = issue.time_entries.find(:first, :order => 'id DESC')
716 assert_not_nil t
720 assert_not_nil t
717 assert_equal 2.5, t.hours
721 assert_equal 2.5, t.hours
718 assert_equal spent_hours_before + 2.5, issue.spent_hours
722 assert_equal spent_hours_before + 2.5, issue.spent_hours
719 end
723 end
720
724
721 def test_post_edit_with_attachment_only
725 def test_post_edit_with_attachment_only
722 set_tmp_attachments_directory
726 set_tmp_attachments_directory
723
727
724 # Delete all fixtured journals, a race condition can occur causing the wrong
728 # Delete all fixtured journals, a race condition can occur causing the wrong
725 # journal to get fetched in the next find.
729 # journal to get fetched in the next find.
726 Journal.delete_all
730 Journal.delete_all
727
731
728 # anonymous user
732 # anonymous user
729 post :edit,
733 post :edit,
730 :id => 1,
734 :id => 1,
731 :notes => '',
735 :notes => '',
732 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
736 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
733 assert_redirected_to :action => 'show', :id => '1'
737 assert_redirected_to :action => 'show', :id => '1'
734 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
738 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
735 assert j.notes.blank?
739 assert j.notes.blank?
736 assert_equal 1, j.details.size
740 assert_equal 1, j.details.size
737 assert_equal 'testfile.txt', j.details.first.value
741 assert_equal 'testfile.txt', j.details.first.value
738 assert_equal User.anonymous, j.user
742 assert_equal User.anonymous, j.user
739
743
740 mail = ActionMailer::Base.deliveries.last
744 mail = ActionMailer::Base.deliveries.last
741 assert mail.body.include?('testfile.txt')
745 assert mail.body.include?('testfile.txt')
742 end
746 end
743
747
744 def test_post_edit_with_no_change
748 def test_post_edit_with_no_change
745 issue = Issue.find(1)
749 issue = Issue.find(1)
746 issue.journals.clear
750 issue.journals.clear
747 ActionMailer::Base.deliveries.clear
751 ActionMailer::Base.deliveries.clear
748
752
749 post :edit,
753 post :edit,
750 :id => 1,
754 :id => 1,
751 :notes => ''
755 :notes => ''
752 assert_redirected_to :action => 'show', :id => '1'
756 assert_redirected_to :action => 'show', :id => '1'
753
757
754 issue.reload
758 issue.reload
755 assert issue.journals.empty?
759 assert issue.journals.empty?
756 # No email should be sent
760 # No email should be sent
757 assert ActionMailer::Base.deliveries.empty?
761 assert ActionMailer::Base.deliveries.empty?
758 end
762 end
759
763
760 def test_post_edit_with_invalid_spent_time
764 def test_post_edit_with_invalid_spent_time
761 @request.session[:user_id] = 2
765 @request.session[:user_id] = 2
762 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
766 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
763
767
764 assert_no_difference('Journal.count') do
768 assert_no_difference('Journal.count') do
765 post :edit,
769 post :edit,
766 :id => 1,
770 :id => 1,
767 :notes => notes,
771 :notes => notes,
768 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
772 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
769 end
773 end
770 assert_response :success
774 assert_response :success
771 assert_template 'edit'
775 assert_template 'edit'
772
776
773 assert_tag :textarea, :attributes => { :name => 'notes' },
777 assert_tag :textarea, :attributes => { :name => 'notes' },
774 :content => notes
778 :content => notes
775 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
779 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
776 end
780 end
777
781
778 def test_bulk_edit
782 def test_bulk_edit
779 @request.session[:user_id] = 2
783 @request.session[:user_id] = 2
780 # update issues priority
784 # update issues priority
781 post :bulk_edit, :ids => [1, 2], :priority_id => 7,
785 post :bulk_edit, :ids => [1, 2], :priority_id => 7,
782 :assigned_to_id => '',
786 :assigned_to_id => '',
783 :custom_field_values => {'2' => ''},
787 :custom_field_values => {'2' => ''},
784 :notes => 'Bulk editing'
788 :notes => 'Bulk editing'
785 assert_response 302
789 assert_response 302
786 # check that the issues were updated
790 # check that the issues were updated
787 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
791 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
788
792
789 issue = Issue.find(1)
793 issue = Issue.find(1)
790 journal = issue.journals.find(:first, :order => 'created_on DESC')
794 journal = issue.journals.find(:first, :order => 'created_on DESC')
791 assert_equal '125', issue.custom_value_for(2).value
795 assert_equal '125', issue.custom_value_for(2).value
792 assert_equal 'Bulk editing', journal.notes
796 assert_equal 'Bulk editing', journal.notes
793 assert_equal 1, journal.details.size
797 assert_equal 1, journal.details.size
794 end
798 end
795
799
796 def test_bulk_edit_custom_field
800 def test_bulk_edit_custom_field
797 @request.session[:user_id] = 2
801 @request.session[:user_id] = 2
798 # update issues priority
802 # update issues priority
799 post :bulk_edit, :ids => [1, 2], :priority_id => '',
803 post :bulk_edit, :ids => [1, 2], :priority_id => '',
800 :assigned_to_id => '',
804 :assigned_to_id => '',
801 :custom_field_values => {'2' => '777'},
805 :custom_field_values => {'2' => '777'},
802 :notes => 'Bulk editing custom field'
806 :notes => 'Bulk editing custom field'
803 assert_response 302
807 assert_response 302
804
808
805 issue = Issue.find(1)
809 issue = Issue.find(1)
806 journal = issue.journals.find(:first, :order => 'created_on DESC')
810 journal = issue.journals.find(:first, :order => 'created_on DESC')
807 assert_equal '777', issue.custom_value_for(2).value
811 assert_equal '777', issue.custom_value_for(2).value
808 assert_equal 1, journal.details.size
812 assert_equal 1, journal.details.size
809 assert_equal '125', journal.details.first.old_value
813 assert_equal '125', journal.details.first.old_value
810 assert_equal '777', journal.details.first.value
814 assert_equal '777', journal.details.first.value
811 end
815 end
812
816
813 def test_bulk_unassign
817 def test_bulk_unassign
814 assert_not_nil Issue.find(2).assigned_to
818 assert_not_nil Issue.find(2).assigned_to
815 @request.session[:user_id] = 2
819 @request.session[:user_id] = 2
816 # unassign issues
820 # unassign issues
817 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
821 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
818 assert_response 302
822 assert_response 302
819 # check that the issues were updated
823 # check that the issues were updated
820 assert_nil Issue.find(2).assigned_to
824 assert_nil Issue.find(2).assigned_to
821 end
825 end
822
826
823 def test_move_routing
827 def test_move_routing
824 assert_routing(
828 assert_routing(
825 {:method => :get, :path => '/issues/1/move'},
829 {:method => :get, :path => '/issues/1/move'},
826 :controller => 'issues', :action => 'move', :id => '1'
830 :controller => 'issues', :action => 'move', :id => '1'
827 )
831 )
828 assert_recognizes(
832 assert_recognizes(
829 {:controller => 'issues', :action => 'move', :id => '1'},
833 {:controller => 'issues', :action => 'move', :id => '1'},
830 {:method => :post, :path => '/issues/1/move'}
834 {:method => :post, :path => '/issues/1/move'}
831 )
835 )
832 end
836 end
833
837
834 def test_move_one_issue_to_another_project
838 def test_move_one_issue_to_another_project
835 @request.session[:user_id] = 1
839 @request.session[:user_id] = 1
836 post :move, :id => 1, :new_project_id => 2
840 post :move, :id => 1, :new_project_id => 2
837 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
841 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
838 assert_equal 2, Issue.find(1).project_id
842 assert_equal 2, Issue.find(1).project_id
839 end
843 end
840
844
841 def test_bulk_move_to_another_project
845 def test_bulk_move_to_another_project
842 @request.session[:user_id] = 1
846 @request.session[:user_id] = 1
843 post :move, :ids => [1, 2], :new_project_id => 2
847 post :move, :ids => [1, 2], :new_project_id => 2
844 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
848 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
845 # Issues moved to project 2
849 # Issues moved to project 2
846 assert_equal 2, Issue.find(1).project_id
850 assert_equal 2, Issue.find(1).project_id
847 assert_equal 2, Issue.find(2).project_id
851 assert_equal 2, Issue.find(2).project_id
848 # No tracker change
852 # No tracker change
849 assert_equal 1, Issue.find(1).tracker_id
853 assert_equal 1, Issue.find(1).tracker_id
850 assert_equal 2, Issue.find(2).tracker_id
854 assert_equal 2, Issue.find(2).tracker_id
851 end
855 end
852
856
853 def test_bulk_move_to_another_tracker
857 def test_bulk_move_to_another_tracker
854 @request.session[:user_id] = 1
858 @request.session[:user_id] = 1
855 post :move, :ids => [1, 2], :new_tracker_id => 2
859 post :move, :ids => [1, 2], :new_tracker_id => 2
856 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
860 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
857 assert_equal 2, Issue.find(1).tracker_id
861 assert_equal 2, Issue.find(1).tracker_id
858 assert_equal 2, Issue.find(2).tracker_id
862 assert_equal 2, Issue.find(2).tracker_id
859 end
863 end
860
864
861 def test_bulk_copy_to_another_project
865 def test_bulk_copy_to_another_project
862 @request.session[:user_id] = 1
866 @request.session[:user_id] = 1
863 assert_difference 'Issue.count', 2 do
867 assert_difference 'Issue.count', 2 do
864 assert_no_difference 'Project.find(1).issues.count' do
868 assert_no_difference 'Project.find(1).issues.count' do
865 post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
869 post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
866 end
870 end
867 end
871 end
868 assert_redirected_to 'projects/ecookbook/issues'
872 assert_redirected_to 'projects/ecookbook/issues'
869 end
873 end
870
874
871 def test_context_menu_one_issue
875 def test_context_menu_one_issue
872 @request.session[:user_id] = 2
876 @request.session[:user_id] = 2
873 get :context_menu, :ids => [1]
877 get :context_menu, :ids => [1]
874 assert_response :success
878 assert_response :success
875 assert_template 'context_menu'
879 assert_template 'context_menu'
876 assert_tag :tag => 'a', :content => 'Edit',
880 assert_tag :tag => 'a', :content => 'Edit',
877 :attributes => { :href => '/issues/1/edit',
881 :attributes => { :href => '/issues/1/edit',
878 :class => 'icon-edit' }
882 :class => 'icon-edit' }
879 assert_tag :tag => 'a', :content => 'Closed',
883 assert_tag :tag => 'a', :content => 'Closed',
880 :attributes => { :href => '/issues/1/edit?issue%5Bstatus_id%5D=5',
884 :attributes => { :href => '/issues/1/edit?issue%5Bstatus_id%5D=5',
881 :class => '' }
885 :class => '' }
882 assert_tag :tag => 'a', :content => 'Immediate',
886 assert_tag :tag => 'a', :content => 'Immediate',
883 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;priority_id=8',
887 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;priority_id=8',
884 :class => '' }
888 :class => '' }
885 assert_tag :tag => 'a', :content => 'Dave Lopper',
889 assert_tag :tag => 'a', :content => 'Dave Lopper',
886 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1',
890 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1',
887 :class => '' }
891 :class => '' }
888 assert_tag :tag => 'a', :content => 'Copy',
892 assert_tag :tag => 'a', :content => 'Copy',
889 :attributes => { :href => '/projects/ecookbook/issues/1/copy',
893 :attributes => { :href => '/projects/ecookbook/issues/1/copy',
890 :class => 'icon-copy' }
894 :class => 'icon-copy' }
891 assert_tag :tag => 'a', :content => 'Move',
895 assert_tag :tag => 'a', :content => 'Move',
892 :attributes => { :href => '/issues/move?ids%5B%5D=1',
896 :attributes => { :href => '/issues/move?ids%5B%5D=1',
893 :class => 'icon-move' }
897 :class => 'icon-move' }
894 assert_tag :tag => 'a', :content => 'Delete',
898 assert_tag :tag => 'a', :content => 'Delete',
895 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
899 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
896 :class => 'icon-del' }
900 :class => 'icon-del' }
897 end
901 end
898
902
899 def test_context_menu_one_issue_by_anonymous
903 def test_context_menu_one_issue_by_anonymous
900 get :context_menu, :ids => [1]
904 get :context_menu, :ids => [1]
901 assert_response :success
905 assert_response :success
902 assert_template 'context_menu'
906 assert_template 'context_menu'
903 assert_tag :tag => 'a', :content => 'Delete',
907 assert_tag :tag => 'a', :content => 'Delete',
904 :attributes => { :href => '#',
908 :attributes => { :href => '#',
905 :class => 'icon-del disabled' }
909 :class => 'icon-del disabled' }
906 end
910 end
907
911
908 def test_context_menu_multiple_issues_of_same_project
912 def test_context_menu_multiple_issues_of_same_project
909 @request.session[:user_id] = 2
913 @request.session[:user_id] = 2
910 get :context_menu, :ids => [1, 2]
914 get :context_menu, :ids => [1, 2]
911 assert_response :success
915 assert_response :success
912 assert_template 'context_menu'
916 assert_template 'context_menu'
913 assert_tag :tag => 'a', :content => 'Edit',
917 assert_tag :tag => 'a', :content => 'Edit',
914 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
918 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
915 :class => 'icon-edit' }
919 :class => 'icon-edit' }
916 assert_tag :tag => 'a', :content => 'Immediate',
920 assert_tag :tag => 'a', :content => 'Immediate',
917 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;priority_id=8',
921 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;priority_id=8',
918 :class => '' }
922 :class => '' }
919 assert_tag :tag => 'a', :content => 'Dave Lopper',
923 assert_tag :tag => 'a', :content => 'Dave Lopper',
920 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
924 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
921 :class => '' }
925 :class => '' }
922 assert_tag :tag => 'a', :content => 'Move',
926 assert_tag :tag => 'a', :content => 'Move',
923 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
927 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
924 :class => 'icon-move' }
928 :class => 'icon-move' }
925 assert_tag :tag => 'a', :content => 'Delete',
929 assert_tag :tag => 'a', :content => 'Delete',
926 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
930 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
927 :class => 'icon-del' }
931 :class => 'icon-del' }
928 end
932 end
929
933
930 def test_context_menu_multiple_issues_of_different_project
934 def test_context_menu_multiple_issues_of_different_project
931 @request.session[:user_id] = 2
935 @request.session[:user_id] = 2
932 get :context_menu, :ids => [1, 2, 4]
936 get :context_menu, :ids => [1, 2, 4]
933 assert_response :success
937 assert_response :success
934 assert_template 'context_menu'
938 assert_template 'context_menu'
935 assert_tag :tag => 'a', :content => 'Delete',
939 assert_tag :tag => 'a', :content => 'Delete',
936 :attributes => { :href => '#',
940 :attributes => { :href => '#',
937 :class => 'icon-del disabled' }
941 :class => 'icon-del disabled' }
938 end
942 end
939
943
940 def test_destroy_routing
944 def test_destroy_routing
941 assert_recognizes( #TODO: use DELETE on issue URI (need to change forms)
945 assert_recognizes( #TODO: use DELETE on issue URI (need to change forms)
942 {:controller => 'issues', :action => 'destroy', :id => '1'},
946 {:controller => 'issues', :action => 'destroy', :id => '1'},
943 {:method => :post, :path => '/issues/1/destroy'}
947 {:method => :post, :path => '/issues/1/destroy'}
944 )
948 )
945 end
949 end
946
950
947 def test_destroy_issue_with_no_time_entries
951 def test_destroy_issue_with_no_time_entries
948 assert_nil TimeEntry.find_by_issue_id(2)
952 assert_nil TimeEntry.find_by_issue_id(2)
949 @request.session[:user_id] = 2
953 @request.session[:user_id] = 2
950 post :destroy, :id => 2
954 post :destroy, :id => 2
951 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
955 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
952 assert_nil Issue.find_by_id(2)
956 assert_nil Issue.find_by_id(2)
953 end
957 end
954
958
955 def test_destroy_issues_with_time_entries
959 def test_destroy_issues_with_time_entries
956 @request.session[:user_id] = 2
960 @request.session[:user_id] = 2
957 post :destroy, :ids => [1, 3]
961 post :destroy, :ids => [1, 3]
958 assert_response :success
962 assert_response :success
959 assert_template 'destroy'
963 assert_template 'destroy'
960 assert_not_nil assigns(:hours)
964 assert_not_nil assigns(:hours)
961 assert Issue.find_by_id(1) && Issue.find_by_id(3)
965 assert Issue.find_by_id(1) && Issue.find_by_id(3)
962 end
966 end
963
967
964 def test_destroy_issues_and_destroy_time_entries
968 def test_destroy_issues_and_destroy_time_entries
965 @request.session[:user_id] = 2
969 @request.session[:user_id] = 2
966 post :destroy, :ids => [1, 3], :todo => 'destroy'
970 post :destroy, :ids => [1, 3], :todo => 'destroy'
967 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
971 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
968 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
972 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
969 assert_nil TimeEntry.find_by_id([1, 2])
973 assert_nil TimeEntry.find_by_id([1, 2])
970 end
974 end
971
975
972 def test_destroy_issues_and_assign_time_entries_to_project
976 def test_destroy_issues_and_assign_time_entries_to_project
973 @request.session[:user_id] = 2
977 @request.session[:user_id] = 2
974 post :destroy, :ids => [1, 3], :todo => 'nullify'
978 post :destroy, :ids => [1, 3], :todo => 'nullify'
975 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
979 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
976 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
980 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
977 assert_nil TimeEntry.find(1).issue_id
981 assert_nil TimeEntry.find(1).issue_id
978 assert_nil TimeEntry.find(2).issue_id
982 assert_nil TimeEntry.find(2).issue_id
979 end
983 end
980
984
981 def test_destroy_issues_and_reassign_time_entries_to_another_issue
985 def test_destroy_issues_and_reassign_time_entries_to_another_issue
982 @request.session[:user_id] = 2
986 @request.session[:user_id] = 2
983 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
987 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
984 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
988 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
985 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
989 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
986 assert_equal 2, TimeEntry.find(1).issue_id
990 assert_equal 2, TimeEntry.find(1).issue_id
987 assert_equal 2, TimeEntry.find(2).issue_id
991 assert_equal 2, TimeEntry.find(2).issue_id
988 end
992 end
989 end
993 end
@@ -1,73 +1,85
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 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.dirname(__FILE__) + '/../../test_helper'
18 require File.dirname(__FILE__) + '/../../test_helper'
19
19
20 class SortHelperTest < HelperTestCase
20 class SortHelperTest < HelperTestCase
21 include SortHelper
21 include SortHelper
22
22
23 def setup
24 @session = nil
25 @sort_param = nil
26 end
27
23 def test_default_sort_clause_with_array
28 def test_default_sort_clause_with_array
24 sort_init 'attr1', 'desc'
29 sort_init 'attr1', 'desc'
25 sort_update(['attr1', 'attr2'])
30 sort_update(['attr1', 'attr2'])
26
31
27 assert_equal 'attr1 DESC', sort_clause
32 assert_equal 'attr1 DESC', sort_clause
28 end
33 end
29
34
30 def test_default_sort_clause_with_hash
35 def test_default_sort_clause_with_hash
31 sort_init 'attr1', 'desc'
36 sort_init 'attr1', 'desc'
32 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
37 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
33
38
34 assert_equal 'table1.attr1 DESC', sort_clause
39 assert_equal 'table1.attr1 DESC', sort_clause
35 end
40 end
36
41
42 def test_default_sort_clause_with_multiple_columns
43 sort_init 'attr1', 'desc'
44 sort_update({'attr1' => ['table1.attr1', 'table1.attr2'], 'attr2' => 'table2.attr2'})
45
46 assert_equal 'table1.attr1 DESC, table1.attr2 DESC', sort_clause
47 end
48
37 def test_params_sort
49 def test_params_sort
38 @sort_param = 'attr1,attr2:desc'
50 @sort_param = 'attr1,attr2:desc'
39
51
40 sort_init 'attr1', 'desc'
52 sort_init 'attr1', 'desc'
41 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
53 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
42
54
43 assert_equal 'table1.attr1, table2.attr2 DESC', sort_clause
55 assert_equal 'table1.attr1, table2.attr2 DESC', sort_clause
44 assert_equal 'attr1,attr2:desc', @session['foo_bar_sort']
56 assert_equal 'attr1,attr2:desc', @session['foo_bar_sort']
45 end
57 end
46
58
47 def test_invalid_params_sort
59 def test_invalid_params_sort
48 @sort_param = 'attr3'
60 @sort_param = 'invalid_key'
49
61
50 sort_init 'attr1', 'desc'
62 sort_init 'attr1', 'desc'
51 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
63 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
52
64
53 assert_nil sort_clause
65 assert_equal 'table1.attr1 DESC', sort_clause
54 assert_equal '', @session['foo_bar_sort']
66 assert_equal 'attr1:desc', @session['foo_bar_sort']
55 end
67 end
56
68
57 def test_invalid_order_params_sort
69 def test_invalid_order_params_sort
58 @sort_param = 'attr1:foo:bar,attr2'
70 @sort_param = 'attr1:foo:bar,attr2'
59
71
60 sort_init 'attr1', 'desc'
72 sort_init 'attr1', 'desc'
61 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
73 sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
62
74
63 assert_equal 'table1.attr1, table2.attr2', sort_clause
75 assert_equal 'table1.attr1, table2.attr2', sort_clause
64 assert_equal 'attr1,attr2', @session['foo_bar_sort']
76 assert_equal 'attr1,attr2', @session['foo_bar_sort']
65 end
77 end
66
78
67 private
79 private
68
80
69 def controller_name; 'foo'; end
81 def controller_name; 'foo'; end
70 def action_name; 'bar'; end
82 def action_name; 'bar'; end
71 def params; {:sort => @sort_param}; end
83 def params; {:sort => @sort_param}; end
72 def session; @session ||= {}; end
84 def session; @session ||= {}; end
73 end
85 end
General Comments 0
You need to be logged in to leave comments. Login now