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