##// END OF EJS Templates
Fixes odd test failures....
Jean-Philippe Lang -
r3098:3b7e7be72aa2
parent child
Show More
@@ -1,1274 +1,1274
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 < ActionController::TestCase
24 class IssuesControllerTest < ActionController::TestCase
25 fixtures :projects,
25 fixtures :projects,
26 :users,
26 :users,
27 :roles,
27 :roles,
28 :members,
28 :members,
29 :member_roles,
29 :member_roles,
30 :issues,
30 :issues,
31 :issue_statuses,
31 :issue_statuses,
32 :versions,
32 :versions,
33 :trackers,
33 :trackers,
34 :projects_trackers,
34 :projects_trackers,
35 :issue_categories,
35 :issue_categories,
36 :enabled_modules,
36 :enabled_modules,
37 :enumerations,
37 :enumerations,
38 :attachments,
38 :attachments,
39 :workflows,
39 :workflows,
40 :custom_fields,
40 :custom_fields,
41 :custom_values,
41 :custom_values,
42 :custom_fields_projects,
42 :custom_fields_projects,
43 :custom_fields_trackers,
43 :custom_fields_trackers,
44 :time_entries,
44 :time_entries,
45 :journals,
45 :journals,
46 :journal_details,
46 :journal_details,
47 :queries
47 :queries
48
48
49 def setup
49 def setup
50 @controller = IssuesController.new
50 @controller = IssuesController.new
51 @request = ActionController::TestRequest.new
51 @request = ActionController::TestRequest.new
52 @response = ActionController::TestResponse.new
52 @response = ActionController::TestResponse.new
53 User.current = nil
53 User.current = nil
54 end
54 end
55
55
56 def test_index_routing
56 def test_index_routing
57 assert_routing(
57 assert_routing(
58 {:method => :get, :path => '/issues'},
58 {:method => :get, :path => '/issues'},
59 :controller => 'issues', :action => 'index'
59 :controller => 'issues', :action => 'index'
60 )
60 )
61 end
61 end
62
62
63 def test_index
63 def test_index
64 Setting.default_language = 'en'
64 Setting.default_language = 'en'
65
65
66 get :index
66 get :index
67 assert_response :success
67 assert_response :success
68 assert_template 'index.rhtml'
68 assert_template 'index.rhtml'
69 assert_not_nil assigns(:issues)
69 assert_not_nil assigns(:issues)
70 assert_nil assigns(:project)
70 assert_nil assigns(:project)
71 assert_tag :tag => 'a', :content => /Can't print recipes/
71 assert_tag :tag => 'a', :content => /Can't print recipes/
72 assert_tag :tag => 'a', :content => /Subproject issue/
72 assert_tag :tag => 'a', :content => /Subproject issue/
73 # private projects hidden
73 # private projects hidden
74 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
74 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
75 assert_no_tag :tag => 'a', :content => /Issue on project 2/
75 assert_no_tag :tag => 'a', :content => /Issue on project 2/
76 # project column
76 # project column
77 assert_tag :tag => 'th', :content => /Project/
77 assert_tag :tag => 'th', :content => /Project/
78 end
78 end
79
79
80 def test_index_should_not_list_issues_when_module_disabled
80 def test_index_should_not_list_issues_when_module_disabled
81 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
81 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
82 get :index
82 get :index
83 assert_response :success
83 assert_response :success
84 assert_template 'index.rhtml'
84 assert_template 'index.rhtml'
85 assert_not_nil assigns(:issues)
85 assert_not_nil assigns(:issues)
86 assert_nil assigns(:project)
86 assert_nil assigns(:project)
87 assert_no_tag :tag => 'a', :content => /Can't print recipes/
87 assert_no_tag :tag => 'a', :content => /Can't print recipes/
88 assert_tag :tag => 'a', :content => /Subproject issue/
88 assert_tag :tag => 'a', :content => /Subproject issue/
89 end
89 end
90
90
91 def test_index_with_project_routing
91 def test_index_with_project_routing
92 assert_routing(
92 assert_routing(
93 {:method => :get, :path => '/projects/23/issues'},
93 {:method => :get, :path => '/projects/23/issues'},
94 :controller => 'issues', :action => 'index', :project_id => '23'
94 :controller => 'issues', :action => 'index', :project_id => '23'
95 )
95 )
96 end
96 end
97
97
98 def test_index_should_not_list_issues_when_module_disabled
98 def test_index_should_not_list_issues_when_module_disabled
99 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
99 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
100 get :index
100 get :index
101 assert_response :success
101 assert_response :success
102 assert_template 'index.rhtml'
102 assert_template 'index.rhtml'
103 assert_not_nil assigns(:issues)
103 assert_not_nil assigns(:issues)
104 assert_nil assigns(:project)
104 assert_nil assigns(:project)
105 assert_no_tag :tag => 'a', :content => /Can't print recipes/
105 assert_no_tag :tag => 'a', :content => /Can't print recipes/
106 assert_tag :tag => 'a', :content => /Subproject issue/
106 assert_tag :tag => 'a', :content => /Subproject issue/
107 end
107 end
108
108
109 def test_index_with_project_routing
109 def test_index_with_project_routing
110 assert_routing(
110 assert_routing(
111 {:method => :get, :path => 'projects/23/issues'},
111 {:method => :get, :path => 'projects/23/issues'},
112 :controller => 'issues', :action => 'index', :project_id => '23'
112 :controller => 'issues', :action => 'index', :project_id => '23'
113 )
113 )
114 end
114 end
115
115
116 def test_index_with_project
116 def test_index_with_project
117 Setting.display_subprojects_issues = 0
117 Setting.display_subprojects_issues = 0
118 get :index, :project_id => 1
118 get :index, :project_id => 1
119 assert_response :success
119 assert_response :success
120 assert_template 'index.rhtml'
120 assert_template 'index.rhtml'
121 assert_not_nil assigns(:issues)
121 assert_not_nil assigns(:issues)
122 assert_tag :tag => 'a', :content => /Can't print recipes/
122 assert_tag :tag => 'a', :content => /Can't print recipes/
123 assert_no_tag :tag => 'a', :content => /Subproject issue/
123 assert_no_tag :tag => 'a', :content => /Subproject issue/
124 end
124 end
125
125
126 def test_index_with_project_and_subprojects
126 def test_index_with_project_and_subprojects
127 Setting.display_subprojects_issues = 1
127 Setting.display_subprojects_issues = 1
128 get :index, :project_id => 1
128 get :index, :project_id => 1
129 assert_response :success
129 assert_response :success
130 assert_template 'index.rhtml'
130 assert_template 'index.rhtml'
131 assert_not_nil assigns(:issues)
131 assert_not_nil assigns(:issues)
132 assert_tag :tag => 'a', :content => /Can't print recipes/
132 assert_tag :tag => 'a', :content => /Can't print recipes/
133 assert_tag :tag => 'a', :content => /Subproject issue/
133 assert_tag :tag => 'a', :content => /Subproject issue/
134 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
134 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
135 end
135 end
136
136
137 def test_index_with_project_and_subprojects_should_show_private_subprojects
137 def test_index_with_project_and_subprojects_should_show_private_subprojects
138 @request.session[:user_id] = 2
138 @request.session[:user_id] = 2
139 Setting.display_subprojects_issues = 1
139 Setting.display_subprojects_issues = 1
140 get :index, :project_id => 1
140 get :index, :project_id => 1
141 assert_response :success
141 assert_response :success
142 assert_template 'index.rhtml'
142 assert_template 'index.rhtml'
143 assert_not_nil assigns(:issues)
143 assert_not_nil assigns(:issues)
144 assert_tag :tag => 'a', :content => /Can't print recipes/
144 assert_tag :tag => 'a', :content => /Can't print recipes/
145 assert_tag :tag => 'a', :content => /Subproject issue/
145 assert_tag :tag => 'a', :content => /Subproject issue/
146 assert_tag :tag => 'a', :content => /Issue of a private subproject/
146 assert_tag :tag => 'a', :content => /Issue of a private subproject/
147 end
147 end
148
148
149 def test_index_with_project_routing_formatted
149 def test_index_with_project_routing_formatted
150 assert_routing(
150 assert_routing(
151 {:method => :get, :path => 'projects/23/issues.pdf'},
151 {:method => :get, :path => 'projects/23/issues.pdf'},
152 :controller => 'issues', :action => 'index', :project_id => '23', :format => 'pdf'
152 :controller => 'issues', :action => 'index', :project_id => '23', :format => 'pdf'
153 )
153 )
154 assert_routing(
154 assert_routing(
155 {:method => :get, :path => 'projects/23/issues.atom'},
155 {:method => :get, :path => 'projects/23/issues.atom'},
156 :controller => 'issues', :action => 'index', :project_id => '23', :format => 'atom'
156 :controller => 'issues', :action => 'index', :project_id => '23', :format => 'atom'
157 )
157 )
158 end
158 end
159
159
160 def test_index_with_project_and_filter
160 def test_index_with_project_and_filter
161 get :index, :project_id => 1, :set_filter => 1
161 get :index, :project_id => 1, :set_filter => 1
162 assert_response :success
162 assert_response :success
163 assert_template 'index.rhtml'
163 assert_template 'index.rhtml'
164 assert_not_nil assigns(:issues)
164 assert_not_nil assigns(:issues)
165 end
165 end
166
166
167 def test_index_with_query
167 def test_index_with_query
168 get :index, :project_id => 1, :query_id => 5
168 get :index, :project_id => 1, :query_id => 5
169 assert_response :success
169 assert_response :success
170 assert_template 'index.rhtml'
170 assert_template 'index.rhtml'
171 assert_not_nil assigns(:issues)
171 assert_not_nil assigns(:issues)
172 assert_nil assigns(:issue_count_by_group)
172 assert_nil assigns(:issue_count_by_group)
173 end
173 end
174
174
175 def test_index_with_query_grouped_by_tracker
175 def test_index_with_query_grouped_by_tracker
176 get :index, :project_id => 1, :query_id => 6
176 get :index, :project_id => 1, :query_id => 6
177 assert_response :success
177 assert_response :success
178 assert_template 'index.rhtml'
178 assert_template 'index.rhtml'
179 assert_not_nil assigns(:issues)
179 assert_not_nil assigns(:issues)
180 assert_not_nil assigns(:issue_count_by_group)
180 assert_not_nil assigns(:issue_count_by_group)
181 end
181 end
182
182
183 def test_index_with_query_grouped_by_list_custom_field
183 def test_index_with_query_grouped_by_list_custom_field
184 get :index, :project_id => 1, :query_id => 9
184 get :index, :project_id => 1, :query_id => 9
185 assert_response :success
185 assert_response :success
186 assert_template 'index.rhtml'
186 assert_template 'index.rhtml'
187 assert_not_nil assigns(:issues)
187 assert_not_nil assigns(:issues)
188 assert_not_nil assigns(:issue_count_by_group)
188 assert_not_nil assigns(:issue_count_by_group)
189 end
189 end
190
190
191 def test_index_sort_by_field_not_included_in_columns
191 def test_index_sort_by_field_not_included_in_columns
192 Setting.issue_list_default_columns = %w(subject author)
192 Setting.issue_list_default_columns = %w(subject author)
193 get :index, :sort => 'tracker'
193 get :index, :sort => 'tracker'
194 end
194 end
195
195
196 def test_index_csv_with_project
196 def test_index_csv_with_project
197 Setting.default_language = 'en'
197 Setting.default_language = 'en'
198
198
199 get :index, :format => 'csv'
199 get :index, :format => 'csv'
200 assert_response :success
200 assert_response :success
201 assert_not_nil assigns(:issues)
201 assert_not_nil assigns(:issues)
202 assert_equal 'text/csv', @response.content_type
202 assert_equal 'text/csv', @response.content_type
203 assert @response.body.starts_with?("#,")
203 assert @response.body.starts_with?("#,")
204
204
205 get :index, :project_id => 1, :format => 'csv'
205 get :index, :project_id => 1, :format => 'csv'
206 assert_response :success
206 assert_response :success
207 assert_not_nil assigns(:issues)
207 assert_not_nil assigns(:issues)
208 assert_equal 'text/csv', @response.content_type
208 assert_equal 'text/csv', @response.content_type
209 end
209 end
210
210
211 def test_index_formatted
211 def test_index_formatted
212 assert_routing(
212 assert_routing(
213 {:method => :get, :path => 'issues.pdf'},
213 {:method => :get, :path => 'issues.pdf'},
214 :controller => 'issues', :action => 'index', :format => 'pdf'
214 :controller => 'issues', :action => 'index', :format => 'pdf'
215 )
215 )
216 assert_routing(
216 assert_routing(
217 {:method => :get, :path => 'issues.atom'},
217 {:method => :get, :path => 'issues.atom'},
218 :controller => 'issues', :action => 'index', :format => 'atom'
218 :controller => 'issues', :action => 'index', :format => 'atom'
219 )
219 )
220 end
220 end
221
221
222 def test_index_pdf
222 def test_index_pdf
223 get :index, :format => 'pdf'
223 get :index, :format => 'pdf'
224 assert_response :success
224 assert_response :success
225 assert_not_nil assigns(:issues)
225 assert_not_nil assigns(:issues)
226 assert_equal 'application/pdf', @response.content_type
226 assert_equal 'application/pdf', @response.content_type
227
227
228 get :index, :project_id => 1, :format => 'pdf'
228 get :index, :project_id => 1, :format => 'pdf'
229 assert_response :success
229 assert_response :success
230 assert_not_nil assigns(:issues)
230 assert_not_nil assigns(:issues)
231 assert_equal 'application/pdf', @response.content_type
231 assert_equal 'application/pdf', @response.content_type
232
232
233 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
233 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
234 assert_response :success
234 assert_response :success
235 assert_not_nil assigns(:issues)
235 assert_not_nil assigns(:issues)
236 assert_equal 'application/pdf', @response.content_type
236 assert_equal 'application/pdf', @response.content_type
237 end
237 end
238
238
239 def test_index_sort
239 def test_index_sort
240 get :index, :sort => 'tracker,id:desc'
240 get :index, :sort => 'tracker,id:desc'
241 assert_response :success
241 assert_response :success
242
242
243 sort_params = @request.session['issues_index_sort']
243 sort_params = @request.session['issues_index_sort']
244 assert sort_params.is_a?(String)
244 assert sort_params.is_a?(String)
245 assert_equal 'tracker,id:desc', sort_params
245 assert_equal 'tracker,id:desc', sort_params
246
246
247 issues = assigns(:issues)
247 issues = assigns(:issues)
248 assert_not_nil issues
248 assert_not_nil issues
249 assert !issues.empty?
249 assert !issues.empty?
250 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
250 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
251 end
251 end
252
252
253 def test_index_with_columns
253 def test_index_with_columns
254 columns = ['tracker', 'subject', 'assigned_to']
254 columns = ['tracker', 'subject', 'assigned_to']
255 get :index, :set_filter => 1, :query => { 'column_names' => columns}
255 get :index, :set_filter => 1, :query => { 'column_names' => columns}
256 assert_response :success
256 assert_response :success
257
257
258 # query should use specified columns
258 # query should use specified columns
259 query = assigns(:query)
259 query = assigns(:query)
260 assert_kind_of Query, query
260 assert_kind_of Query, query
261 assert_equal columns, query.column_names.map(&:to_s)
261 assert_equal columns, query.column_names.map(&:to_s)
262
262
263 # columns should be stored in session
263 # columns should be stored in session
264 assert_kind_of Hash, session[:query]
264 assert_kind_of Hash, session[:query]
265 assert_kind_of Array, session[:query][:column_names]
265 assert_kind_of Array, session[:query][:column_names]
266 assert_equal columns, session[:query][:column_names].map(&:to_s)
266 assert_equal columns, session[:query][:column_names].map(&:to_s)
267 end
267 end
268
268
269 def test_gantt
269 def test_gantt
270 get :gantt, :project_id => 1
270 get :gantt, :project_id => 1
271 assert_response :success
271 assert_response :success
272 assert_template 'gantt.rhtml'
272 assert_template 'gantt.rhtml'
273 assert_not_nil assigns(:gantt)
273 assert_not_nil assigns(:gantt)
274 events = assigns(:gantt).events
274 events = assigns(:gantt).events
275 assert_not_nil events
275 assert_not_nil events
276 # Issue with start and due dates
276 # Issue with start and due dates
277 i = Issue.find(1)
277 i = Issue.find(1)
278 assert_not_nil i.due_date
278 assert_not_nil i.due_date
279 assert events.include?(Issue.find(1))
279 assert events.include?(Issue.find(1))
280 # Issue with without due date but targeted to a version with date
280 # Issue with without due date but targeted to a version with date
281 i = Issue.find(2)
281 i = Issue.find(2)
282 assert_nil i.due_date
282 assert_nil i.due_date
283 assert events.include?(i)
283 assert events.include?(i)
284 end
284 end
285
285
286 def test_cross_project_gantt
286 def test_cross_project_gantt
287 get :gantt
287 get :gantt
288 assert_response :success
288 assert_response :success
289 assert_template 'gantt.rhtml'
289 assert_template 'gantt.rhtml'
290 assert_not_nil assigns(:gantt)
290 assert_not_nil assigns(:gantt)
291 events = assigns(:gantt).events
291 events = assigns(:gantt).events
292 assert_not_nil events
292 assert_not_nil events
293 end
293 end
294
294
295 def test_gantt_export_to_pdf
295 def test_gantt_export_to_pdf
296 get :gantt, :project_id => 1, :format => 'pdf'
296 get :gantt, :project_id => 1, :format => 'pdf'
297 assert_response :success
297 assert_response :success
298 assert_equal 'application/pdf', @response.content_type
298 assert_equal 'application/pdf', @response.content_type
299 assert @response.body.starts_with?('%PDF')
299 assert @response.body.starts_with?('%PDF')
300 assert_not_nil assigns(:gantt)
300 assert_not_nil assigns(:gantt)
301 end
301 end
302
302
303 def test_cross_project_gantt_export_to_pdf
303 def test_cross_project_gantt_export_to_pdf
304 get :gantt, :format => 'pdf'
304 get :gantt, :format => 'pdf'
305 assert_response :success
305 assert_response :success
306 assert_equal 'application/pdf', @response.content_type
306 assert_equal 'application/pdf', @response.content_type
307 assert @response.body.starts_with?('%PDF')
307 assert @response.body.starts_with?('%PDF')
308 assert_not_nil assigns(:gantt)
308 assert_not_nil assigns(:gantt)
309 end
309 end
310
310
311 if Object.const_defined?(:Magick)
311 if Object.const_defined?(:Magick)
312 def test_gantt_image
312 def test_gantt_image
313 get :gantt, :project_id => 1, :format => 'png'
313 get :gantt, :project_id => 1, :format => 'png'
314 assert_response :success
314 assert_response :success
315 assert_equal 'image/png', @response.content_type
315 assert_equal 'image/png', @response.content_type
316 end
316 end
317 else
317 else
318 puts "RMagick not installed. Skipping tests !!!"
318 puts "RMagick not installed. Skipping tests !!!"
319 end
319 end
320
320
321 def test_calendar
321 def test_calendar
322 get :calendar, :project_id => 1
322 get :calendar, :project_id => 1
323 assert_response :success
323 assert_response :success
324 assert_template 'calendar'
324 assert_template 'calendar'
325 assert_not_nil assigns(:calendar)
325 assert_not_nil assigns(:calendar)
326 end
326 end
327
327
328 def test_cross_project_calendar
328 def test_cross_project_calendar
329 get :calendar
329 get :calendar
330 assert_response :success
330 assert_response :success
331 assert_template 'calendar'
331 assert_template 'calendar'
332 assert_not_nil assigns(:calendar)
332 assert_not_nil assigns(:calendar)
333 end
333 end
334
334
335 def test_changes
335 def test_changes
336 get :changes, :project_id => 1
336 get :changes, :project_id => 1
337 assert_response :success
337 assert_response :success
338 assert_not_nil assigns(:journals)
338 assert_not_nil assigns(:journals)
339 assert_equal 'application/atom+xml', @response.content_type
339 assert_equal 'application/atom+xml', @response.content_type
340 end
340 end
341
341
342 def test_show_routing
342 def test_show_routing
343 assert_routing(
343 assert_routing(
344 {:method => :get, :path => '/issues/64'},
344 {:method => :get, :path => '/issues/64'},
345 :controller => 'issues', :action => 'show', :id => '64'
345 :controller => 'issues', :action => 'show', :id => '64'
346 )
346 )
347 end
347 end
348
348
349 def test_show_routing_formatted
349 def test_show_routing_formatted
350 assert_routing(
350 assert_routing(
351 {:method => :get, :path => '/issues/2332.pdf'},
351 {:method => :get, :path => '/issues/2332.pdf'},
352 :controller => 'issues', :action => 'show', :id => '2332', :format => 'pdf'
352 :controller => 'issues', :action => 'show', :id => '2332', :format => 'pdf'
353 )
353 )
354 assert_routing(
354 assert_routing(
355 {:method => :get, :path => '/issues/23123.atom'},
355 {:method => :get, :path => '/issues/23123.atom'},
356 :controller => 'issues', :action => 'show', :id => '23123', :format => 'atom'
356 :controller => 'issues', :action => 'show', :id => '23123', :format => 'atom'
357 )
357 )
358 end
358 end
359
359
360 def test_show_by_anonymous
360 def test_show_by_anonymous
361 get :show, :id => 1
361 get :show, :id => 1
362 assert_response :success
362 assert_response :success
363 assert_template 'show.rhtml'
363 assert_template 'show.rhtml'
364 assert_not_nil assigns(:issue)
364 assert_not_nil assigns(:issue)
365 assert_equal Issue.find(1), assigns(:issue)
365 assert_equal Issue.find(1), assigns(:issue)
366
366
367 # anonymous role is allowed to add a note
367 # anonymous role is allowed to add a note
368 assert_tag :tag => 'form',
368 assert_tag :tag => 'form',
369 :descendant => { :tag => 'fieldset',
369 :descendant => { :tag => 'fieldset',
370 :child => { :tag => 'legend',
370 :child => { :tag => 'legend',
371 :content => /Notes/ } }
371 :content => /Notes/ } }
372 end
372 end
373
373
374 def test_show_by_manager
374 def test_show_by_manager
375 @request.session[:user_id] = 2
375 @request.session[:user_id] = 2
376 get :show, :id => 1
376 get :show, :id => 1
377 assert_response :success
377 assert_response :success
378
378
379 assert_tag :tag => 'form',
379 assert_tag :tag => 'form',
380 :descendant => { :tag => 'fieldset',
380 :descendant => { :tag => 'fieldset',
381 :child => { :tag => 'legend',
381 :child => { :tag => 'legend',
382 :content => /Change properties/ } },
382 :content => /Change properties/ } },
383 :descendant => { :tag => 'fieldset',
383 :descendant => { :tag => 'fieldset',
384 :child => { :tag => 'legend',
384 :child => { :tag => 'legend',
385 :content => /Log time/ } },
385 :content => /Log time/ } },
386 :descendant => { :tag => 'fieldset',
386 :descendant => { :tag => 'fieldset',
387 :child => { :tag => 'legend',
387 :child => { :tag => 'legend',
388 :content => /Notes/ } }
388 :content => /Notes/ } }
389 end
389 end
390
390
391 def test_show_should_deny_anonymous_access_without_permission
391 def test_show_should_deny_anonymous_access_without_permission
392 Role.anonymous.remove_permission!(:view_issues)
392 Role.anonymous.remove_permission!(:view_issues)
393 get :show, :id => 1
393 get :show, :id => 1
394 assert_response :redirect
394 assert_response :redirect
395 end
395 end
396
396
397 def test_show_should_deny_non_member_access_without_permission
397 def test_show_should_deny_non_member_access_without_permission
398 Role.non_member.remove_permission!(:view_issues)
398 Role.non_member.remove_permission!(:view_issues)
399 @request.session[:user_id] = 9
399 @request.session[:user_id] = 9
400 get :show, :id => 1
400 get :show, :id => 1
401 assert_response 403
401 assert_response 403
402 end
402 end
403
403
404 def test_show_should_deny_member_access_without_permission
404 def test_show_should_deny_member_access_without_permission
405 Role.find(1).remove_permission!(:view_issues)
405 Role.find(1).remove_permission!(:view_issues)
406 @request.session[:user_id] = 2
406 @request.session[:user_id] = 2
407 get :show, :id => 1
407 get :show, :id => 1
408 assert_response 403
408 assert_response 403
409 end
409 end
410
410
411 def test_show_should_not_disclose_relations_to_invisible_issues
411 def test_show_should_not_disclose_relations_to_invisible_issues
412 Setting.cross_project_issue_relations = '1'
412 Setting.cross_project_issue_relations = '1'
413 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
413 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
414 # Relation to a private project issue
414 # Relation to a private project issue
415 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
415 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
416
416
417 get :show, :id => 1
417 get :show, :id => 1
418 assert_response :success
418 assert_response :success
419
419
420 assert_tag :div, :attributes => { :id => 'relations' },
420 assert_tag :div, :attributes => { :id => 'relations' },
421 :descendant => { :tag => 'a', :content => /#2$/ }
421 :descendant => { :tag => 'a', :content => /#2$/ }
422 assert_no_tag :div, :attributes => { :id => 'relations' },
422 assert_no_tag :div, :attributes => { :id => 'relations' },
423 :descendant => { :tag => 'a', :content => /#4$/ }
423 :descendant => { :tag => 'a', :content => /#4$/ }
424 end
424 end
425
425
426 def test_show_atom
426 def test_show_atom
427 get :show, :id => 2, :format => 'atom'
427 get :show, :id => 2, :format => 'atom'
428 assert_response :success
428 assert_response :success
429 assert_template 'changes.rxml'
429 assert_template 'changes.rxml'
430 # Inline image
430 # Inline image
431 assert @response.body.include?("&lt;img src=\"http://test.host/attachments/download/10\" alt=\"\" /&gt;"), "Body did not match. Body: #{@response.body}"
431 assert @response.body.include?("&lt;img src=\"http://test.host/attachments/download/10\" alt=\"\" /&gt;"), "Body did not match. Body: #{@response.body}"
432 end
432 end
433
433
434 def test_new_routing
434 def test_new_routing
435 assert_routing(
435 assert_routing(
436 {:method => :get, :path => '/projects/1/issues/new'},
436 {:method => :get, :path => '/projects/1/issues/new'},
437 :controller => 'issues', :action => 'new', :project_id => '1'
437 :controller => 'issues', :action => 'new', :project_id => '1'
438 )
438 )
439 assert_recognizes(
439 assert_recognizes(
440 {:controller => 'issues', :action => 'new', :project_id => '1'},
440 {:controller => 'issues', :action => 'new', :project_id => '1'},
441 {:method => :post, :path => '/projects/1/issues'}
441 {:method => :post, :path => '/projects/1/issues'}
442 )
442 )
443 end
443 end
444
444
445 def test_show_export_to_pdf
445 def test_show_export_to_pdf
446 get :show, :id => 3, :format => 'pdf'
446 get :show, :id => 3, :format => 'pdf'
447 assert_response :success
447 assert_response :success
448 assert_equal 'application/pdf', @response.content_type
448 assert_equal 'application/pdf', @response.content_type
449 assert @response.body.starts_with?('%PDF')
449 assert @response.body.starts_with?('%PDF')
450 assert_not_nil assigns(:issue)
450 assert_not_nil assigns(:issue)
451 end
451 end
452
452
453 def test_get_new
453 def test_get_new
454 @request.session[:user_id] = 2
454 @request.session[:user_id] = 2
455 get :new, :project_id => 1, :tracker_id => 1
455 get :new, :project_id => 1, :tracker_id => 1
456 assert_response :success
456 assert_response :success
457 assert_template 'new'
457 assert_template 'new'
458
458
459 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
459 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
460 :value => 'Default string' }
460 :value => 'Default string' }
461 end
461 end
462
462
463 def test_get_new_without_tracker_id
463 def test_get_new_without_tracker_id
464 @request.session[:user_id] = 2
464 @request.session[:user_id] = 2
465 get :new, :project_id => 1
465 get :new, :project_id => 1
466 assert_response :success
466 assert_response :success
467 assert_template 'new'
467 assert_template 'new'
468
468
469 issue = assigns(:issue)
469 issue = assigns(:issue)
470 assert_not_nil issue
470 assert_not_nil issue
471 assert_equal Project.find(1).trackers.first, issue.tracker
471 assert_equal Project.find(1).trackers.first, issue.tracker
472 end
472 end
473
473
474 def test_get_new_with_no_default_status_should_display_an_error
474 def test_get_new_with_no_default_status_should_display_an_error
475 @request.session[:user_id] = 2
475 @request.session[:user_id] = 2
476 IssueStatus.delete_all
476 IssueStatus.delete_all
477
477
478 get :new, :project_id => 1
478 get :new, :project_id => 1
479 assert_response 500
479 assert_response 500
480 assert_not_nil flash[:error]
480 assert_not_nil flash[:error]
481 assert_tag :tag => 'div', :attributes => { :class => /error/ },
481 assert_tag :tag => 'div', :attributes => { :class => /error/ },
482 :content => /No default issue/
482 :content => /No default issue/
483 end
483 end
484
484
485 def test_get_new_with_no_tracker_should_display_an_error
485 def test_get_new_with_no_tracker_should_display_an_error
486 @request.session[:user_id] = 2
486 @request.session[:user_id] = 2
487 Tracker.delete_all
487 Tracker.delete_all
488
488
489 get :new, :project_id => 1
489 get :new, :project_id => 1
490 assert_response 500
490 assert_response 500
491 assert_not_nil flash[:error]
491 assert_not_nil flash[:error]
492 assert_tag :tag => 'div', :attributes => { :class => /error/ },
492 assert_tag :tag => 'div', :attributes => { :class => /error/ },
493 :content => /No tracker/
493 :content => /No tracker/
494 end
494 end
495
495
496 def test_update_new_form
496 def test_update_new_form
497 @request.session[:user_id] = 2
497 @request.session[:user_id] = 2
498 xhr :post, :update_form, :project_id => 1,
498 xhr :post, :update_form, :project_id => 1,
499 :issue => {:tracker_id => 2,
499 :issue => {:tracker_id => 2,
500 :subject => 'This is the test_new issue',
500 :subject => 'This is the test_new issue',
501 :description => 'This is the description',
501 :description => 'This is the description',
502 :priority_id => 5}
502 :priority_id => 5}
503 assert_response :success
503 assert_response :success
504 assert_template 'attributes'
504 assert_template 'attributes'
505
505
506 issue = assigns(:issue)
506 issue = assigns(:issue)
507 assert_kind_of Issue, issue
507 assert_kind_of Issue, issue
508 assert_equal 1, issue.project_id
508 assert_equal 1, issue.project_id
509 assert_equal 2, issue.tracker_id
509 assert_equal 2, issue.tracker_id
510 assert_equal 'This is the test_new issue', issue.subject
510 assert_equal 'This is the test_new issue', issue.subject
511 end
511 end
512
512
513 def test_post_new
513 def test_post_new
514 @request.session[:user_id] = 2
514 @request.session[:user_id] = 2
515 assert_difference 'Issue.count' do
515 assert_difference 'Issue.count' do
516 post :new, :project_id => 1,
516 post :new, :project_id => 1,
517 :issue => {:tracker_id => 3,
517 :issue => {:tracker_id => 3,
518 :subject => 'This is the test_new issue',
518 :subject => 'This is the test_new issue',
519 :description => 'This is the description',
519 :description => 'This is the description',
520 :priority_id => 5,
520 :priority_id => 5,
521 :estimated_hours => '',
521 :estimated_hours => '',
522 :custom_field_values => {'2' => 'Value for field 2'}}
522 :custom_field_values => {'2' => 'Value for field 2'}}
523 end
523 end
524 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
524 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
525
525
526 issue = Issue.find_by_subject('This is the test_new issue')
526 issue = Issue.find_by_subject('This is the test_new issue')
527 assert_not_nil issue
527 assert_not_nil issue
528 assert_equal 2, issue.author_id
528 assert_equal 2, issue.author_id
529 assert_equal 3, issue.tracker_id
529 assert_equal 3, issue.tracker_id
530 assert_nil issue.estimated_hours
530 assert_nil issue.estimated_hours
531 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
531 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
532 assert_not_nil v
532 assert_not_nil v
533 assert_equal 'Value for field 2', v.value
533 assert_equal 'Value for field 2', v.value
534 end
534 end
535
535
536 def test_post_new_and_continue
536 def test_post_new_and_continue
537 @request.session[:user_id] = 2
537 @request.session[:user_id] = 2
538 post :new, :project_id => 1,
538 post :new, :project_id => 1,
539 :issue => {:tracker_id => 3,
539 :issue => {:tracker_id => 3,
540 :subject => 'This is first issue',
540 :subject => 'This is first issue',
541 :priority_id => 5},
541 :priority_id => 5},
542 :continue => ''
542 :continue => ''
543 assert_redirected_to :controller => 'issues', :action => 'new', :tracker_id => 3
543 assert_redirected_to :controller => 'issues', :action => 'new', :tracker_id => 3
544 end
544 end
545
545
546 def test_post_new_without_custom_fields_param
546 def test_post_new_without_custom_fields_param
547 @request.session[:user_id] = 2
547 @request.session[:user_id] = 2
548 assert_difference 'Issue.count' do
548 assert_difference 'Issue.count' do
549 post :new, :project_id => 1,
549 post :new, :project_id => 1,
550 :issue => {:tracker_id => 1,
550 :issue => {:tracker_id => 1,
551 :subject => 'This is the test_new issue',
551 :subject => 'This is the test_new issue',
552 :description => 'This is the description',
552 :description => 'This is the description',
553 :priority_id => 5}
553 :priority_id => 5}
554 end
554 end
555 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
555 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
556 end
556 end
557
557
558 def test_post_new_with_required_custom_field_and_without_custom_fields_param
558 def test_post_new_with_required_custom_field_and_without_custom_fields_param
559 field = IssueCustomField.find_by_name('Database')
559 field = IssueCustomField.find_by_name('Database')
560 field.update_attribute(:is_required, true)
560 field.update_attribute(:is_required, true)
561
561
562 @request.session[:user_id] = 2
562 @request.session[:user_id] = 2
563 post :new, :project_id => 1,
563 post :new, :project_id => 1,
564 :issue => {:tracker_id => 1,
564 :issue => {:tracker_id => 1,
565 :subject => 'This is the test_new issue',
565 :subject => 'This is the test_new issue',
566 :description => 'This is the description',
566 :description => 'This is the description',
567 :priority_id => 5}
567 :priority_id => 5}
568 assert_response :success
568 assert_response :success
569 assert_template 'new'
569 assert_template 'new'
570 issue = assigns(:issue)
570 issue = assigns(:issue)
571 assert_not_nil issue
571 assert_not_nil issue
572 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
572 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
573 end
573 end
574
574
575 def test_post_new_with_watchers
575 def test_post_new_with_watchers
576 @request.session[:user_id] = 2
576 @request.session[:user_id] = 2
577 ActionMailer::Base.deliveries.clear
577 ActionMailer::Base.deliveries.clear
578
578
579 assert_difference 'Watcher.count', 2 do
579 assert_difference 'Watcher.count', 2 do
580 post :new, :project_id => 1,
580 post :new, :project_id => 1,
581 :issue => {:tracker_id => 1,
581 :issue => {:tracker_id => 1,
582 :subject => 'This is a new issue with watchers',
582 :subject => 'This is a new issue with watchers',
583 :description => 'This is the description',
583 :description => 'This is the description',
584 :priority_id => 5,
584 :priority_id => 5,
585 :watcher_user_ids => ['2', '3']}
585 :watcher_user_ids => ['2', '3']}
586 end
586 end
587 issue = Issue.find_by_subject('This is a new issue with watchers')
587 issue = Issue.find_by_subject('This is a new issue with watchers')
588 assert_not_nil issue
588 assert_not_nil issue
589 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
589 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
590
590
591 # Watchers added
591 # Watchers added
592 assert_equal [2, 3], issue.watcher_user_ids.sort
592 assert_equal [2, 3], issue.watcher_user_ids.sort
593 assert issue.watched_by?(User.find(3))
593 assert issue.watched_by?(User.find(3))
594 # Watchers notified
594 # Watchers notified
595 mail = ActionMailer::Base.deliveries.last
595 mail = ActionMailer::Base.deliveries.last
596 assert_kind_of TMail::Mail, mail
596 assert_kind_of TMail::Mail, mail
597 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
597 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
598 end
598 end
599
599
600 def test_post_new_should_send_a_notification
600 def test_post_new_should_send_a_notification
601 ActionMailer::Base.deliveries.clear
601 ActionMailer::Base.deliveries.clear
602 @request.session[:user_id] = 2
602 @request.session[:user_id] = 2
603 assert_difference 'Issue.count' do
603 assert_difference 'Issue.count' do
604 post :new, :project_id => 1,
604 post :new, :project_id => 1,
605 :issue => {:tracker_id => 3,
605 :issue => {:tracker_id => 3,
606 :subject => 'This is the test_new issue',
606 :subject => 'This is the test_new issue',
607 :description => 'This is the description',
607 :description => 'This is the description',
608 :priority_id => 5,
608 :priority_id => 5,
609 :estimated_hours => '',
609 :estimated_hours => '',
610 :custom_field_values => {'2' => 'Value for field 2'}}
610 :custom_field_values => {'2' => 'Value for field 2'}}
611 end
611 end
612 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
612 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
613
613
614 assert_equal 1, ActionMailer::Base.deliveries.size
614 assert_equal 1, ActionMailer::Base.deliveries.size
615 end
615 end
616
616
617 def test_post_should_preserve_fields_values_on_validation_failure
617 def test_post_should_preserve_fields_values_on_validation_failure
618 @request.session[:user_id] = 2
618 @request.session[:user_id] = 2
619 post :new, :project_id => 1,
619 post :new, :project_id => 1,
620 :issue => {:tracker_id => 1,
620 :issue => {:tracker_id => 1,
621 # empty subject
621 # empty subject
622 :subject => '',
622 :subject => '',
623 :description => 'This is a description',
623 :description => 'This is a description',
624 :priority_id => 6,
624 :priority_id => 6,
625 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
625 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
626 assert_response :success
626 assert_response :success
627 assert_template 'new'
627 assert_template 'new'
628
628
629 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
629 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
630 :content => 'This is a description'
630 :content => 'This is a description'
631 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
631 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
632 :child => { :tag => 'option', :attributes => { :selected => 'selected',
632 :child => { :tag => 'option', :attributes => { :selected => 'selected',
633 :value => '6' },
633 :value => '6' },
634 :content => 'High' }
634 :content => 'High' }
635 # Custom fields
635 # Custom fields
636 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
636 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
637 :child => { :tag => 'option', :attributes => { :selected => 'selected',
637 :child => { :tag => 'option', :attributes => { :selected => 'selected',
638 :value => 'Oracle' },
638 :value => 'Oracle' },
639 :content => 'Oracle' }
639 :content => 'Oracle' }
640 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
640 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
641 :value => 'Value for field 2'}
641 :value => 'Value for field 2'}
642 end
642 end
643
643
644 def test_copy_routing
644 def test_copy_routing
645 assert_routing(
645 assert_routing(
646 {:method => :get, :path => '/projects/world_domination/issues/567/copy'},
646 {:method => :get, :path => '/projects/world_domination/issues/567/copy'},
647 :controller => 'issues', :action => 'new', :project_id => 'world_domination', :copy_from => '567'
647 :controller => 'issues', :action => 'new', :project_id => 'world_domination', :copy_from => '567'
648 )
648 )
649 end
649 end
650
650
651 def test_copy_issue
651 def test_copy_issue
652 @request.session[:user_id] = 2
652 @request.session[:user_id] = 2
653 get :new, :project_id => 1, :copy_from => 1
653 get :new, :project_id => 1, :copy_from => 1
654 assert_template 'new'
654 assert_template 'new'
655 assert_not_nil assigns(:issue)
655 assert_not_nil assigns(:issue)
656 orig = Issue.find(1)
656 orig = Issue.find(1)
657 assert_equal orig.subject, assigns(:issue).subject
657 assert_equal orig.subject, assigns(:issue).subject
658 end
658 end
659
659
660 def test_edit_routing
660 def test_edit_routing
661 assert_routing(
661 assert_routing(
662 {:method => :get, :path => '/issues/1/edit'},
662 {:method => :get, :path => '/issues/1/edit'},
663 :controller => 'issues', :action => 'edit', :id => '1'
663 :controller => 'issues', :action => 'edit', :id => '1'
664 )
664 )
665 assert_recognizes( #TODO: use a PUT on the issue URI isntead, need to adjust form
665 assert_recognizes( #TODO: use a PUT on the issue URI isntead, need to adjust form
666 {:controller => 'issues', :action => 'edit', :id => '1'},
666 {:controller => 'issues', :action => 'edit', :id => '1'},
667 {:method => :post, :path => '/issues/1/edit'}
667 {:method => :post, :path => '/issues/1/edit'}
668 )
668 )
669 end
669 end
670
670
671 def test_get_edit
671 def test_get_edit
672 @request.session[:user_id] = 2
672 @request.session[:user_id] = 2
673 get :edit, :id => 1
673 get :edit, :id => 1
674 assert_response :success
674 assert_response :success
675 assert_template 'edit'
675 assert_template 'edit'
676 assert_not_nil assigns(:issue)
676 assert_not_nil assigns(:issue)
677 assert_equal Issue.find(1), assigns(:issue)
677 assert_equal Issue.find(1), assigns(:issue)
678 end
678 end
679
679
680 def test_get_edit_with_params
680 def test_get_edit_with_params
681 @request.session[:user_id] = 2
681 @request.session[:user_id] = 2
682 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
682 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
683 assert_response :success
683 assert_response :success
684 assert_template 'edit'
684 assert_template 'edit'
685
685
686 issue = assigns(:issue)
686 issue = assigns(:issue)
687 assert_not_nil issue
687 assert_not_nil issue
688
688
689 assert_equal 5, issue.status_id
689 assert_equal 5, issue.status_id
690 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
690 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
691 :child => { :tag => 'option',
691 :child => { :tag => 'option',
692 :content => 'Closed',
692 :content => 'Closed',
693 :attributes => { :selected => 'selected' } }
693 :attributes => { :selected => 'selected' } }
694
694
695 assert_equal 7, issue.priority_id
695 assert_equal 7, issue.priority_id
696 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
696 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
697 :child => { :tag => 'option',
697 :child => { :tag => 'option',
698 :content => 'Urgent',
698 :content => 'Urgent',
699 :attributes => { :selected => 'selected' } }
699 :attributes => { :selected => 'selected' } }
700 end
700 end
701
701
702 def test_update_edit_form
702 def test_update_edit_form
703 @request.session[:user_id] = 2
703 @request.session[:user_id] = 2
704 xhr :post, :update_form, :project_id => 1,
704 xhr :post, :update_form, :project_id => 1,
705 :id => 1,
705 :id => 1,
706 :issue => {:tracker_id => 2,
706 :issue => {:tracker_id => 2,
707 :subject => 'This is the test_new issue',
707 :subject => 'This is the test_new issue',
708 :description => 'This is the description',
708 :description => 'This is the description',
709 :priority_id => 5}
709 :priority_id => 5}
710 assert_response :success
710 assert_response :success
711 assert_template 'attributes'
711 assert_template 'attributes'
712
712
713 issue = assigns(:issue)
713 issue = assigns(:issue)
714 assert_kind_of Issue, issue
714 assert_kind_of Issue, issue
715 assert_equal 1, issue.id
715 assert_equal 1, issue.id
716 assert_equal 1, issue.project_id
716 assert_equal 1, issue.project_id
717 assert_equal 2, issue.tracker_id
717 assert_equal 2, issue.tracker_id
718 assert_equal 'This is the test_new issue', issue.subject
718 assert_equal 'This is the test_new issue', issue.subject
719 end
719 end
720
720
721 def test_reply_routing
721 def test_reply_routing
722 assert_routing(
722 assert_routing(
723 {:method => :post, :path => '/issues/1/quoted'},
723 {:method => :post, :path => '/issues/1/quoted'},
724 :controller => 'issues', :action => 'reply', :id => '1'
724 :controller => 'issues', :action => 'reply', :id => '1'
725 )
725 )
726 end
726 end
727
727
728 def test_reply_to_issue
728 def test_reply_to_issue
729 @request.session[:user_id] = 2
729 @request.session[:user_id] = 2
730 get :reply, :id => 1
730 get :reply, :id => 1
731 assert_response :success
731 assert_response :success
732 assert_select_rjs :show, "update"
732 assert_select_rjs :show, "update"
733 end
733 end
734
734
735 def test_reply_to_note
735 def test_reply_to_note
736 @request.session[:user_id] = 2
736 @request.session[:user_id] = 2
737 get :reply, :id => 1, :journal_id => 2
737 get :reply, :id => 1, :journal_id => 2
738 assert_response :success
738 assert_response :success
739 assert_select_rjs :show, "update"
739 assert_select_rjs :show, "update"
740 end
740 end
741
741
742 def test_post_edit_without_custom_fields_param
742 def test_post_edit_without_custom_fields_param
743 @request.session[:user_id] = 2
743 @request.session[:user_id] = 2
744 ActionMailer::Base.deliveries.clear
744 ActionMailer::Base.deliveries.clear
745
745
746 issue = Issue.find(1)
746 issue = Issue.find(1)
747 assert_equal '125', issue.custom_value_for(2).value
747 assert_equal '125', issue.custom_value_for(2).value
748 old_subject = issue.subject
748 old_subject = issue.subject
749 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
749 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
750
750
751 assert_difference('Journal.count') do
751 assert_difference('Journal.count') do
752 assert_difference('JournalDetail.count', 2) do
752 assert_difference('JournalDetail.count', 2) do
753 post :edit, :id => 1, :issue => {:subject => new_subject,
753 post :edit, :id => 1, :issue => {:subject => new_subject,
754 :priority_id => '6',
754 :priority_id => '6',
755 :category_id => '1' # no change
755 :category_id => '1' # no change
756 }
756 }
757 end
757 end
758 end
758 end
759 assert_redirected_to :action => 'show', :id => '1'
759 assert_redirected_to :action => 'show', :id => '1'
760 issue.reload
760 issue.reload
761 assert_equal new_subject, issue.subject
761 assert_equal new_subject, issue.subject
762 # Make sure custom fields were not cleared
762 # Make sure custom fields were not cleared
763 assert_equal '125', issue.custom_value_for(2).value
763 assert_equal '125', issue.custom_value_for(2).value
764
764
765 mail = ActionMailer::Base.deliveries.last
765 mail = ActionMailer::Base.deliveries.last
766 assert_kind_of TMail::Mail, mail
766 assert_kind_of TMail::Mail, mail
767 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
767 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
768 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
768 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
769 end
769 end
770
770
771 def test_post_edit_with_custom_field_change
771 def test_post_edit_with_custom_field_change
772 @request.session[:user_id] = 2
772 @request.session[:user_id] = 2
773 issue = Issue.find(1)
773 issue = Issue.find(1)
774 assert_equal '125', issue.custom_value_for(2).value
774 assert_equal '125', issue.custom_value_for(2).value
775
775
776 assert_difference('Journal.count') do
776 assert_difference('Journal.count') do
777 assert_difference('JournalDetail.count', 3) do
777 assert_difference('JournalDetail.count', 3) do
778 post :edit, :id => 1, :issue => {:subject => 'Custom field change',
778 post :edit, :id => 1, :issue => {:subject => 'Custom field change',
779 :priority_id => '6',
779 :priority_id => '6',
780 :category_id => '1', # no change
780 :category_id => '1', # no change
781 :custom_field_values => { '2' => 'New custom value' }
781 :custom_field_values => { '2' => 'New custom value' }
782 }
782 }
783 end
783 end
784 end
784 end
785 assert_redirected_to :action => 'show', :id => '1'
785 assert_redirected_to :action => 'show', :id => '1'
786 issue.reload
786 issue.reload
787 assert_equal 'New custom value', issue.custom_value_for(2).value
787 assert_equal 'New custom value', issue.custom_value_for(2).value
788
788
789 mail = ActionMailer::Base.deliveries.last
789 mail = ActionMailer::Base.deliveries.last
790 assert_kind_of TMail::Mail, mail
790 assert_kind_of TMail::Mail, mail
791 assert mail.body.include?("Searchable field changed from 125 to New custom value")
791 assert mail.body.include?("Searchable field changed from 125 to New custom value")
792 end
792 end
793
793
794 def test_post_edit_with_status_and_assignee_change
794 def test_post_edit_with_status_and_assignee_change
795 issue = Issue.find(1)
795 issue = Issue.find(1)
796 assert_equal 1, issue.status_id
796 assert_equal 1, issue.status_id
797 @request.session[:user_id] = 2
797 @request.session[:user_id] = 2
798 assert_difference('TimeEntry.count', 0) do
798 assert_difference('TimeEntry.count', 0) do
799 post :edit,
799 post :edit,
800 :id => 1,
800 :id => 1,
801 :issue => { :status_id => 2, :assigned_to_id => 3 },
801 :issue => { :status_id => 2, :assigned_to_id => 3 },
802 :notes => 'Assigned to dlopper',
802 :notes => 'Assigned to dlopper',
803 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
803 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
804 end
804 end
805 assert_redirected_to :action => 'show', :id => '1'
805 assert_redirected_to :action => 'show', :id => '1'
806 issue.reload
806 issue.reload
807 assert_equal 2, issue.status_id
807 assert_equal 2, issue.status_id
808 j = issue.journals.find(:first, :order => 'id DESC')
808 j = Journal.find(:first, :order => 'id DESC')
809 assert_equal 'Assigned to dlopper', j.notes
809 assert_equal 'Assigned to dlopper', j.notes
810 assert_equal 2, j.details.size
810 assert_equal 2, j.details.size
811
811
812 mail = ActionMailer::Base.deliveries.last
812 mail = ActionMailer::Base.deliveries.last
813 assert mail.body.include?("Status changed from New to Assigned")
813 assert mail.body.include?("Status changed from New to Assigned")
814 # subject should contain the new status
814 # subject should contain the new status
815 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
815 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
816 end
816 end
817
817
818 def test_post_edit_with_note_only
818 def test_post_edit_with_note_only
819 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
819 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
820 # anonymous user
820 # anonymous user
821 post :edit,
821 post :edit,
822 :id => 1,
822 :id => 1,
823 :notes => notes
823 :notes => notes
824 assert_redirected_to :action => 'show', :id => '1'
824 assert_redirected_to :action => 'show', :id => '1'
825 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
825 j = Journal.find(:first, :order => 'id DESC')
826 assert_equal notes, j.notes
826 assert_equal notes, j.notes
827 assert_equal 0, j.details.size
827 assert_equal 0, j.details.size
828 assert_equal User.anonymous, j.user
828 assert_equal User.anonymous, j.user
829
829
830 mail = ActionMailer::Base.deliveries.last
830 mail = ActionMailer::Base.deliveries.last
831 assert mail.body.include?(notes)
831 assert mail.body.include?(notes)
832 end
832 end
833
833
834 def test_post_edit_with_note_and_spent_time
834 def test_post_edit_with_note_and_spent_time
835 @request.session[:user_id] = 2
835 @request.session[:user_id] = 2
836 spent_hours_before = Issue.find(1).spent_hours
836 spent_hours_before = Issue.find(1).spent_hours
837 assert_difference('TimeEntry.count') do
837 assert_difference('TimeEntry.count') do
838 post :edit,
838 post :edit,
839 :id => 1,
839 :id => 1,
840 :notes => '2.5 hours added',
840 :notes => '2.5 hours added',
841 :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first }
841 :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first }
842 end
842 end
843 assert_redirected_to :action => 'show', :id => '1'
843 assert_redirected_to :action => 'show', :id => '1'
844
844
845 issue = Issue.find(1)
845 issue = Issue.find(1)
846
846
847 j = issue.journals.find(:first, :order => 'id DESC')
847 j = Journal.find(:first, :order => 'id DESC')
848 assert_equal '2.5 hours added', j.notes
848 assert_equal '2.5 hours added', j.notes
849 assert_equal 0, j.details.size
849 assert_equal 0, j.details.size
850
850
851 t = issue.time_entries.find(:first, :order => 'id DESC')
851 t = issue.time_entries.find(:first, :order => 'id DESC')
852 assert_not_nil t
852 assert_not_nil t
853 assert_equal 2.5, t.hours
853 assert_equal 2.5, t.hours
854 assert_equal spent_hours_before + 2.5, issue.spent_hours
854 assert_equal spent_hours_before + 2.5, issue.spent_hours
855 end
855 end
856
856
857 def test_post_edit_with_attachment_only
857 def test_post_edit_with_attachment_only
858 set_tmp_attachments_directory
858 set_tmp_attachments_directory
859
859
860 # Delete all fixtured journals, a race condition can occur causing the wrong
860 # Delete all fixtured journals, a race condition can occur causing the wrong
861 # journal to get fetched in the next find.
861 # journal to get fetched in the next find.
862 Journal.delete_all
862 Journal.delete_all
863
863
864 # anonymous user
864 # anonymous user
865 post :edit,
865 post :edit,
866 :id => 1,
866 :id => 1,
867 :notes => '',
867 :notes => '',
868 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
868 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
869 assert_redirected_to :action => 'show', :id => '1'
869 assert_redirected_to :action => 'show', :id => '1'
870 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
870 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
871 assert j.notes.blank?
871 assert j.notes.blank?
872 assert_equal 1, j.details.size
872 assert_equal 1, j.details.size
873 assert_equal 'testfile.txt', j.details.first.value
873 assert_equal 'testfile.txt', j.details.first.value
874 assert_equal User.anonymous, j.user
874 assert_equal User.anonymous, j.user
875
875
876 mail = ActionMailer::Base.deliveries.last
876 mail = ActionMailer::Base.deliveries.last
877 assert mail.body.include?('testfile.txt')
877 assert mail.body.include?('testfile.txt')
878 end
878 end
879
879
880 def test_post_edit_with_no_change
880 def test_post_edit_with_no_change
881 issue = Issue.find(1)
881 issue = Issue.find(1)
882 issue.journals.clear
882 issue.journals.clear
883 ActionMailer::Base.deliveries.clear
883 ActionMailer::Base.deliveries.clear
884
884
885 post :edit,
885 post :edit,
886 :id => 1,
886 :id => 1,
887 :notes => ''
887 :notes => ''
888 assert_redirected_to :action => 'show', :id => '1'
888 assert_redirected_to :action => 'show', :id => '1'
889
889
890 issue.reload
890 issue.reload
891 assert issue.journals.empty?
891 assert issue.journals.empty?
892 # No email should be sent
892 # No email should be sent
893 assert ActionMailer::Base.deliveries.empty?
893 assert ActionMailer::Base.deliveries.empty?
894 end
894 end
895
895
896 def test_post_edit_should_send_a_notification
896 def test_post_edit_should_send_a_notification
897 @request.session[:user_id] = 2
897 @request.session[:user_id] = 2
898 ActionMailer::Base.deliveries.clear
898 ActionMailer::Base.deliveries.clear
899 issue = Issue.find(1)
899 issue = Issue.find(1)
900 old_subject = issue.subject
900 old_subject = issue.subject
901 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
901 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
902
902
903 post :edit, :id => 1, :issue => {:subject => new_subject,
903 post :edit, :id => 1, :issue => {:subject => new_subject,
904 :priority_id => '6',
904 :priority_id => '6',
905 :category_id => '1' # no change
905 :category_id => '1' # no change
906 }
906 }
907 assert_equal 1, ActionMailer::Base.deliveries.size
907 assert_equal 1, ActionMailer::Base.deliveries.size
908 end
908 end
909
909
910 def test_post_edit_with_invalid_spent_time
910 def test_post_edit_with_invalid_spent_time
911 @request.session[:user_id] = 2
911 @request.session[:user_id] = 2
912 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
912 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
913
913
914 assert_no_difference('Journal.count') do
914 assert_no_difference('Journal.count') do
915 post :edit,
915 post :edit,
916 :id => 1,
916 :id => 1,
917 :notes => notes,
917 :notes => notes,
918 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
918 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
919 end
919 end
920 assert_response :success
920 assert_response :success
921 assert_template 'edit'
921 assert_template 'edit'
922
922
923 assert_tag :textarea, :attributes => { :name => 'notes' },
923 assert_tag :textarea, :attributes => { :name => 'notes' },
924 :content => notes
924 :content => notes
925 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
925 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
926 end
926 end
927
927
928 def test_post_edit_should_allow_fixed_version_to_be_set_to_a_subproject
928 def test_post_edit_should_allow_fixed_version_to_be_set_to_a_subproject
929 issue = Issue.find(2)
929 issue = Issue.find(2)
930 @request.session[:user_id] = 2
930 @request.session[:user_id] = 2
931
931
932 post :edit,
932 post :edit,
933 :id => issue.id,
933 :id => issue.id,
934 :issue => {
934 :issue => {
935 :fixed_version_id => 4
935 :fixed_version_id => 4
936 }
936 }
937
937
938 assert_response :redirect
938 assert_response :redirect
939 issue.reload
939 issue.reload
940 assert_equal 4, issue.fixed_version_id
940 assert_equal 4, issue.fixed_version_id
941 assert_not_equal issue.project_id, issue.fixed_version.project_id
941 assert_not_equal issue.project_id, issue.fixed_version.project_id
942 end
942 end
943
943
944 def test_get_bulk_edit
944 def test_get_bulk_edit
945 @request.session[:user_id] = 2
945 @request.session[:user_id] = 2
946 get :bulk_edit, :ids => [1, 2]
946 get :bulk_edit, :ids => [1, 2]
947 assert_response :success
947 assert_response :success
948 assert_template 'bulk_edit'
948 assert_template 'bulk_edit'
949 end
949 end
950
950
951 def test_bulk_edit
951 def test_bulk_edit
952 @request.session[:user_id] = 2
952 @request.session[:user_id] = 2
953 # update issues priority
953 # update issues priority
954 post :bulk_edit, :ids => [1, 2], :priority_id => 7,
954 post :bulk_edit, :ids => [1, 2], :priority_id => 7,
955 :assigned_to_id => '',
955 :assigned_to_id => '',
956 :custom_field_values => {'2' => ''},
956 :custom_field_values => {'2' => ''},
957 :notes => 'Bulk editing'
957 :notes => 'Bulk editing'
958 assert_response 302
958 assert_response 302
959 # check that the issues were updated
959 # check that the issues were updated
960 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
960 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
961
961
962 issue = Issue.find(1)
962 issue = Issue.find(1)
963 journal = issue.journals.find(:first, :order => 'created_on DESC')
963 journal = issue.journals.find(:first, :order => 'created_on DESC')
964 assert_equal '125', issue.custom_value_for(2).value
964 assert_equal '125', issue.custom_value_for(2).value
965 assert_equal 'Bulk editing', journal.notes
965 assert_equal 'Bulk editing', journal.notes
966 assert_equal 1, journal.details.size
966 assert_equal 1, journal.details.size
967 end
967 end
968
968
969 def test_bullk_edit_should_send_a_notification
969 def test_bullk_edit_should_send_a_notification
970 @request.session[:user_id] = 2
970 @request.session[:user_id] = 2
971 ActionMailer::Base.deliveries.clear
971 ActionMailer::Base.deliveries.clear
972 post(:bulk_edit,
972 post(:bulk_edit,
973 {
973 {
974 :ids => [1, 2],
974 :ids => [1, 2],
975 :priority_id => 7,
975 :priority_id => 7,
976 :assigned_to_id => '',
976 :assigned_to_id => '',
977 :custom_field_values => {'2' => ''},
977 :custom_field_values => {'2' => ''},
978 :notes => 'Bulk editing'
978 :notes => 'Bulk editing'
979 })
979 })
980
980
981 assert_response 302
981 assert_response 302
982 assert_equal 2, ActionMailer::Base.deliveries.size
982 assert_equal 2, ActionMailer::Base.deliveries.size
983 end
983 end
984
984
985 def test_bulk_edit_status
985 def test_bulk_edit_status
986 @request.session[:user_id] = 2
986 @request.session[:user_id] = 2
987 # update issues priority
987 # update issues priority
988 post :bulk_edit, :ids => [1, 2], :priority_id => '',
988 post :bulk_edit, :ids => [1, 2], :priority_id => '',
989 :assigned_to_id => '',
989 :assigned_to_id => '',
990 :status_id => '5',
990 :status_id => '5',
991 :notes => 'Bulk editing status'
991 :notes => 'Bulk editing status'
992 assert_response 302
992 assert_response 302
993 issue = Issue.find(1)
993 issue = Issue.find(1)
994 assert issue.closed?
994 assert issue.closed?
995 end
995 end
996
996
997 def test_bulk_edit_custom_field
997 def test_bulk_edit_custom_field
998 @request.session[:user_id] = 2
998 @request.session[:user_id] = 2
999 # update issues priority
999 # update issues priority
1000 post :bulk_edit, :ids => [1, 2], :priority_id => '',
1000 post :bulk_edit, :ids => [1, 2], :priority_id => '',
1001 :assigned_to_id => '',
1001 :assigned_to_id => '',
1002 :custom_field_values => {'2' => '777'},
1002 :custom_field_values => {'2' => '777'},
1003 :notes => 'Bulk editing custom field'
1003 :notes => 'Bulk editing custom field'
1004 assert_response 302
1004 assert_response 302
1005
1005
1006 issue = Issue.find(1)
1006 issue = Issue.find(1)
1007 journal = issue.journals.find(:first, :order => 'created_on DESC')
1007 journal = issue.journals.find(:first, :order => 'created_on DESC')
1008 assert_equal '777', issue.custom_value_for(2).value
1008 assert_equal '777', issue.custom_value_for(2).value
1009 assert_equal 1, journal.details.size
1009 assert_equal 1, journal.details.size
1010 assert_equal '125', journal.details.first.old_value
1010 assert_equal '125', journal.details.first.old_value
1011 assert_equal '777', journal.details.first.value
1011 assert_equal '777', journal.details.first.value
1012 end
1012 end
1013
1013
1014 def test_bulk_unassign
1014 def test_bulk_unassign
1015 assert_not_nil Issue.find(2).assigned_to
1015 assert_not_nil Issue.find(2).assigned_to
1016 @request.session[:user_id] = 2
1016 @request.session[:user_id] = 2
1017 # unassign issues
1017 # unassign issues
1018 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
1018 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
1019 assert_response 302
1019 assert_response 302
1020 # check that the issues were updated
1020 # check that the issues were updated
1021 assert_nil Issue.find(2).assigned_to
1021 assert_nil Issue.find(2).assigned_to
1022 end
1022 end
1023
1023
1024 def test_post_bulk_edit_should_allow_fixed_version_to_be_set_to_a_subproject
1024 def test_post_bulk_edit_should_allow_fixed_version_to_be_set_to_a_subproject
1025 @request.session[:user_id] = 2
1025 @request.session[:user_id] = 2
1026
1026
1027 post :bulk_edit,
1027 post :bulk_edit,
1028 :ids => [1,2],
1028 :ids => [1,2],
1029 :fixed_version_id => 4
1029 :fixed_version_id => 4
1030
1030
1031 assert_response :redirect
1031 assert_response :redirect
1032 issues = Issue.find([1,2])
1032 issues = Issue.find([1,2])
1033 issues.each do |issue|
1033 issues.each do |issue|
1034 assert_equal 4, issue.fixed_version_id
1034 assert_equal 4, issue.fixed_version_id
1035 assert_not_equal issue.project_id, issue.fixed_version.project_id
1035 assert_not_equal issue.project_id, issue.fixed_version.project_id
1036 end
1036 end
1037 end
1037 end
1038
1038
1039 def test_move_routing
1039 def test_move_routing
1040 assert_routing(
1040 assert_routing(
1041 {:method => :get, :path => '/issues/1/move'},
1041 {:method => :get, :path => '/issues/1/move'},
1042 :controller => 'issues', :action => 'move', :id => '1'
1042 :controller => 'issues', :action => 'move', :id => '1'
1043 )
1043 )
1044 assert_recognizes(
1044 assert_recognizes(
1045 {:controller => 'issues', :action => 'move', :id => '1'},
1045 {:controller => 'issues', :action => 'move', :id => '1'},
1046 {:method => :post, :path => '/issues/1/move'}
1046 {:method => :post, :path => '/issues/1/move'}
1047 )
1047 )
1048 end
1048 end
1049
1049
1050 def test_move_one_issue_to_another_project
1050 def test_move_one_issue_to_another_project
1051 @request.session[:user_id] = 2
1051 @request.session[:user_id] = 2
1052 post :move, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
1052 post :move, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
1053 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1053 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1054 assert_equal 2, Issue.find(1).project_id
1054 assert_equal 2, Issue.find(1).project_id
1055 end
1055 end
1056
1056
1057 def test_move_one_issue_to_another_project_should_follow_when_needed
1057 def test_move_one_issue_to_another_project_should_follow_when_needed
1058 @request.session[:user_id] = 2
1058 @request.session[:user_id] = 2
1059 post :move, :id => 1, :new_project_id => 2, :follow => '1'
1059 post :move, :id => 1, :new_project_id => 2, :follow => '1'
1060 assert_redirected_to '/issues/1'
1060 assert_redirected_to '/issues/1'
1061 end
1061 end
1062
1062
1063 def test_bulk_move_to_another_project
1063 def test_bulk_move_to_another_project
1064 @request.session[:user_id] = 2
1064 @request.session[:user_id] = 2
1065 post :move, :ids => [1, 2], :new_project_id => 2
1065 post :move, :ids => [1, 2], :new_project_id => 2
1066 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1066 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1067 # Issues moved to project 2
1067 # Issues moved to project 2
1068 assert_equal 2, Issue.find(1).project_id
1068 assert_equal 2, Issue.find(1).project_id
1069 assert_equal 2, Issue.find(2).project_id
1069 assert_equal 2, Issue.find(2).project_id
1070 # No tracker change
1070 # No tracker change
1071 assert_equal 1, Issue.find(1).tracker_id
1071 assert_equal 1, Issue.find(1).tracker_id
1072 assert_equal 2, Issue.find(2).tracker_id
1072 assert_equal 2, Issue.find(2).tracker_id
1073 end
1073 end
1074
1074
1075 def test_bulk_move_to_another_tracker
1075 def test_bulk_move_to_another_tracker
1076 @request.session[:user_id] = 2
1076 @request.session[:user_id] = 2
1077 post :move, :ids => [1, 2], :new_tracker_id => 2
1077 post :move, :ids => [1, 2], :new_tracker_id => 2
1078 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1078 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1079 assert_equal 2, Issue.find(1).tracker_id
1079 assert_equal 2, Issue.find(1).tracker_id
1080 assert_equal 2, Issue.find(2).tracker_id
1080 assert_equal 2, Issue.find(2).tracker_id
1081 end
1081 end
1082
1082
1083 def test_bulk_copy_to_another_project
1083 def test_bulk_copy_to_another_project
1084 @request.session[:user_id] = 2
1084 @request.session[:user_id] = 2
1085 assert_difference 'Issue.count', 2 do
1085 assert_difference 'Issue.count', 2 do
1086 assert_no_difference 'Project.find(1).issues.count' do
1086 assert_no_difference 'Project.find(1).issues.count' do
1087 post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
1087 post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
1088 end
1088 end
1089 end
1089 end
1090 assert_redirected_to 'projects/ecookbook/issues'
1090 assert_redirected_to 'projects/ecookbook/issues'
1091 end
1091 end
1092
1092
1093 context "#move via bulk copy" do
1093 context "#move via bulk copy" do
1094 should "allow not changing the issue's attributes" do
1094 should "allow not changing the issue's attributes" do
1095 @request.session[:user_id] = 2
1095 @request.session[:user_id] = 2
1096 issue_before_move = Issue.find(1)
1096 issue_before_move = Issue.find(1)
1097 assert_difference 'Issue.count', 1 do
1097 assert_difference 'Issue.count', 1 do
1098 assert_no_difference 'Project.find(1).issues.count' do
1098 assert_no_difference 'Project.find(1).issues.count' do
1099 post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
1099 post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
1100 end
1100 end
1101 end
1101 end
1102 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
1102 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
1103 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
1103 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
1104 assert_equal issue_before_move.status_id, issue_after_move.status_id
1104 assert_equal issue_before_move.status_id, issue_after_move.status_id
1105 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
1105 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
1106 end
1106 end
1107
1107
1108 should "allow changing the issue's attributes" do
1108 should "allow changing the issue's attributes" do
1109 @request.session[:user_id] = 2
1109 @request.session[:user_id] = 2
1110 assert_difference 'Issue.count', 2 do
1110 assert_difference 'Issue.count', 2 do
1111 assert_no_difference 'Project.find(1).issues.count' do
1111 assert_no_difference 'Project.find(1).issues.count' do
1112 post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31'
1112 post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31'
1113 end
1113 end
1114 end
1114 end
1115
1115
1116 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
1116 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
1117 assert_equal 2, copied_issues.size
1117 assert_equal 2, copied_issues.size
1118 copied_issues.each do |issue|
1118 copied_issues.each do |issue|
1119 assert_equal 2, issue.project_id, "Project is incorrect"
1119 assert_equal 2, issue.project_id, "Project is incorrect"
1120 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
1120 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
1121 assert_equal 3, issue.status_id, "Status is incorrect"
1121 assert_equal 3, issue.status_id, "Status is incorrect"
1122 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
1122 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
1123 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
1123 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
1124 end
1124 end
1125 end
1125 end
1126 end
1126 end
1127
1127
1128 def test_copy_to_another_project_should_follow_when_needed
1128 def test_copy_to_another_project_should_follow_when_needed
1129 @request.session[:user_id] = 2
1129 @request.session[:user_id] = 2
1130 post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
1130 post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
1131 issue = Issue.first(:order => 'id DESC')
1131 issue = Issue.first(:order => 'id DESC')
1132 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1132 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1133 end
1133 end
1134
1134
1135 def test_context_menu_one_issue
1135 def test_context_menu_one_issue
1136 @request.session[:user_id] = 2
1136 @request.session[:user_id] = 2
1137 get :context_menu, :ids => [1]
1137 get :context_menu, :ids => [1]
1138 assert_response :success
1138 assert_response :success
1139 assert_template 'context_menu'
1139 assert_template 'context_menu'
1140 assert_tag :tag => 'a', :content => 'Edit',
1140 assert_tag :tag => 'a', :content => 'Edit',
1141 :attributes => { :href => '/issues/1/edit',
1141 :attributes => { :href => '/issues/1/edit',
1142 :class => 'icon-edit' }
1142 :class => 'icon-edit' }
1143 assert_tag :tag => 'a', :content => 'Closed',
1143 assert_tag :tag => 'a', :content => 'Closed',
1144 :attributes => { :href => '/issues/1/edit?issue%5Bstatus_id%5D=5',
1144 :attributes => { :href => '/issues/1/edit?issue%5Bstatus_id%5D=5',
1145 :class => '' }
1145 :class => '' }
1146 assert_tag :tag => 'a', :content => 'Immediate',
1146 assert_tag :tag => 'a', :content => 'Immediate',
1147 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;priority_id=8',
1147 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;priority_id=8',
1148 :class => '' }
1148 :class => '' }
1149 # Versions
1149 # Versions
1150 assert_tag :tag => 'a', :content => '2.0',
1150 assert_tag :tag => 'a', :content => '2.0',
1151 :attributes => { :href => '/issues/bulk_edit?fixed_version_id=3&amp;ids%5B%5D=1',
1151 :attributes => { :href => '/issues/bulk_edit?fixed_version_id=3&amp;ids%5B%5D=1',
1152 :class => '' }
1152 :class => '' }
1153 assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0',
1153 assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0',
1154 :attributes => { :href => '/issues/bulk_edit?fixed_version_id=4&amp;ids%5B%5D=1',
1154 :attributes => { :href => '/issues/bulk_edit?fixed_version_id=4&amp;ids%5B%5D=1',
1155 :class => '' }
1155 :class => '' }
1156
1156
1157 assert_tag :tag => 'a', :content => 'Dave Lopper',
1157 assert_tag :tag => 'a', :content => 'Dave Lopper',
1158 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1',
1158 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1',
1159 :class => '' }
1159 :class => '' }
1160 assert_tag :tag => 'a', :content => 'Duplicate',
1160 assert_tag :tag => 'a', :content => 'Duplicate',
1161 :attributes => { :href => '/projects/ecookbook/issues/1/copy',
1161 :attributes => { :href => '/projects/ecookbook/issues/1/copy',
1162 :class => 'icon-duplicate' }
1162 :class => 'icon-duplicate' }
1163 assert_tag :tag => 'a', :content => 'Copy',
1163 assert_tag :tag => 'a', :content => 'Copy',
1164 :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&amp;ids%5B%5D=1',
1164 :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&amp;ids%5B%5D=1',
1165 :class => 'icon-copy' }
1165 :class => 'icon-copy' }
1166 assert_tag :tag => 'a', :content => 'Move',
1166 assert_tag :tag => 'a', :content => 'Move',
1167 :attributes => { :href => '/issues/move?ids%5B%5D=1',
1167 :attributes => { :href => '/issues/move?ids%5B%5D=1',
1168 :class => 'icon-move' }
1168 :class => 'icon-move' }
1169 assert_tag :tag => 'a', :content => 'Delete',
1169 assert_tag :tag => 'a', :content => 'Delete',
1170 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
1170 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
1171 :class => 'icon-del' }
1171 :class => 'icon-del' }
1172 end
1172 end
1173
1173
1174 def test_context_menu_one_issue_by_anonymous
1174 def test_context_menu_one_issue_by_anonymous
1175 get :context_menu, :ids => [1]
1175 get :context_menu, :ids => [1]
1176 assert_response :success
1176 assert_response :success
1177 assert_template 'context_menu'
1177 assert_template 'context_menu'
1178 assert_tag :tag => 'a', :content => 'Delete',
1178 assert_tag :tag => 'a', :content => 'Delete',
1179 :attributes => { :href => '#',
1179 :attributes => { :href => '#',
1180 :class => 'icon-del disabled' }
1180 :class => 'icon-del disabled' }
1181 end
1181 end
1182
1182
1183 def test_context_menu_multiple_issues_of_same_project
1183 def test_context_menu_multiple_issues_of_same_project
1184 @request.session[:user_id] = 2
1184 @request.session[:user_id] = 2
1185 get :context_menu, :ids => [1, 2]
1185 get :context_menu, :ids => [1, 2]
1186 assert_response :success
1186 assert_response :success
1187 assert_template 'context_menu'
1187 assert_template 'context_menu'
1188 assert_tag :tag => 'a', :content => 'Edit',
1188 assert_tag :tag => 'a', :content => 'Edit',
1189 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
1189 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
1190 :class => 'icon-edit' }
1190 :class => 'icon-edit' }
1191 assert_tag :tag => 'a', :content => 'Immediate',
1191 assert_tag :tag => 'a', :content => 'Immediate',
1192 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;priority_id=8',
1192 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;priority_id=8',
1193 :class => '' }
1193 :class => '' }
1194 assert_tag :tag => 'a', :content => 'Dave Lopper',
1194 assert_tag :tag => 'a', :content => 'Dave Lopper',
1195 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
1195 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
1196 :class => '' }
1196 :class => '' }
1197 assert_tag :tag => 'a', :content => 'Copy',
1197 assert_tag :tag => 'a', :content => 'Copy',
1198 :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
1198 :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
1199 :class => 'icon-copy' }
1199 :class => 'icon-copy' }
1200 assert_tag :tag => 'a', :content => 'Move',
1200 assert_tag :tag => 'a', :content => 'Move',
1201 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
1201 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
1202 :class => 'icon-move' }
1202 :class => 'icon-move' }
1203 assert_tag :tag => 'a', :content => 'Delete',
1203 assert_tag :tag => 'a', :content => 'Delete',
1204 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
1204 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
1205 :class => 'icon-del' }
1205 :class => 'icon-del' }
1206 end
1206 end
1207
1207
1208 def test_context_menu_multiple_issues_of_different_project
1208 def test_context_menu_multiple_issues_of_different_project
1209 @request.session[:user_id] = 2
1209 @request.session[:user_id] = 2
1210 get :context_menu, :ids => [1, 2, 4]
1210 get :context_menu, :ids => [1, 2, 4]
1211 assert_response :success
1211 assert_response :success
1212 assert_template 'context_menu'
1212 assert_template 'context_menu'
1213 assert_tag :tag => 'a', :content => 'Delete',
1213 assert_tag :tag => 'a', :content => 'Delete',
1214 :attributes => { :href => '#',
1214 :attributes => { :href => '#',
1215 :class => 'icon-del disabled' }
1215 :class => 'icon-del disabled' }
1216 end
1216 end
1217
1217
1218 def test_destroy_routing
1218 def test_destroy_routing
1219 assert_recognizes( #TODO: use DELETE on issue URI (need to change forms)
1219 assert_recognizes( #TODO: use DELETE on issue URI (need to change forms)
1220 {:controller => 'issues', :action => 'destroy', :id => '1'},
1220 {:controller => 'issues', :action => 'destroy', :id => '1'},
1221 {:method => :post, :path => '/issues/1/destroy'}
1221 {:method => :post, :path => '/issues/1/destroy'}
1222 )
1222 )
1223 end
1223 end
1224
1224
1225 def test_destroy_issue_with_no_time_entries
1225 def test_destroy_issue_with_no_time_entries
1226 assert_nil TimeEntry.find_by_issue_id(2)
1226 assert_nil TimeEntry.find_by_issue_id(2)
1227 @request.session[:user_id] = 2
1227 @request.session[:user_id] = 2
1228 post :destroy, :id => 2
1228 post :destroy, :id => 2
1229 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1229 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1230 assert_nil Issue.find_by_id(2)
1230 assert_nil Issue.find_by_id(2)
1231 end
1231 end
1232
1232
1233 def test_destroy_issues_with_time_entries
1233 def test_destroy_issues_with_time_entries
1234 @request.session[:user_id] = 2
1234 @request.session[:user_id] = 2
1235 post :destroy, :ids => [1, 3]
1235 post :destroy, :ids => [1, 3]
1236 assert_response :success
1236 assert_response :success
1237 assert_template 'destroy'
1237 assert_template 'destroy'
1238 assert_not_nil assigns(:hours)
1238 assert_not_nil assigns(:hours)
1239 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1239 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1240 end
1240 end
1241
1241
1242 def test_destroy_issues_and_destroy_time_entries
1242 def test_destroy_issues_and_destroy_time_entries
1243 @request.session[:user_id] = 2
1243 @request.session[:user_id] = 2
1244 post :destroy, :ids => [1, 3], :todo => 'destroy'
1244 post :destroy, :ids => [1, 3], :todo => 'destroy'
1245 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1245 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1246 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1246 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1247 assert_nil TimeEntry.find_by_id([1, 2])
1247 assert_nil TimeEntry.find_by_id([1, 2])
1248 end
1248 end
1249
1249
1250 def test_destroy_issues_and_assign_time_entries_to_project
1250 def test_destroy_issues_and_assign_time_entries_to_project
1251 @request.session[:user_id] = 2
1251 @request.session[:user_id] = 2
1252 post :destroy, :ids => [1, 3], :todo => 'nullify'
1252 post :destroy, :ids => [1, 3], :todo => 'nullify'
1253 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1253 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1254 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1254 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1255 assert_nil TimeEntry.find(1).issue_id
1255 assert_nil TimeEntry.find(1).issue_id
1256 assert_nil TimeEntry.find(2).issue_id
1256 assert_nil TimeEntry.find(2).issue_id
1257 end
1257 end
1258
1258
1259 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1259 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1260 @request.session[:user_id] = 2
1260 @request.session[:user_id] = 2
1261 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1261 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1262 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1262 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1263 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1263 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1264 assert_equal 2, TimeEntry.find(1).issue_id
1264 assert_equal 2, TimeEntry.find(1).issue_id
1265 assert_equal 2, TimeEntry.find(2).issue_id
1265 assert_equal 2, TimeEntry.find(2).issue_id
1266 end
1266 end
1267
1267
1268 def test_default_search_scope
1268 def test_default_search_scope
1269 get :index
1269 get :index
1270 assert_tag :div, :attributes => {:id => 'quick-search'},
1270 assert_tag :div, :attributes => {:id => 'quick-search'},
1271 :child => {:tag => 'form',
1271 :child => {:tag => 'form',
1272 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
1272 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
1273 end
1273 end
1274 end
1274 end
General Comments 0
You need to be logged in to leave comments. Login now