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