@@ -1,501 +1,501 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2013 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 | |
|
20 | 20 | class UsersControllerTest < ActionController::TestCase |
|
21 | 21 | include Redmine::I18n |
|
22 | 22 | |
|
23 | 23 | fixtures :users, :projects, :members, :member_roles, :roles, |
|
24 | 24 | :custom_fields, :custom_values, :groups_users, |
|
25 | 25 | :auth_sources |
|
26 | 26 | |
|
27 | 27 | def setup |
|
28 | 28 | User.current = nil |
|
29 | 29 | @request.session[:user_id] = 1 # admin |
|
30 | 30 | end |
|
31 | 31 | |
|
32 | 32 | def test_index |
|
33 | 33 | get :index |
|
34 | 34 | assert_response :success |
|
35 | 35 | assert_template 'index' |
|
36 | 36 | assert_not_nil assigns(:users) |
|
37 | 37 | # active users only |
|
38 | 38 | assert_nil assigns(:users).detect {|u| !u.active?} |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def test_index_with_status_filter |
|
42 | 42 | get :index, :status => 3 |
|
43 | 43 | assert_response :success |
|
44 | 44 | assert_template 'index' |
|
45 | 45 | assert_not_nil assigns(:users) |
|
46 | 46 | assert_equal [3], assigns(:users).map(&:status).uniq |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | def test_index_with_name_filter |
|
50 | 50 | get :index, :name => 'john' |
|
51 | 51 | assert_response :success |
|
52 | 52 | assert_template 'index' |
|
53 | 53 | users = assigns(:users) |
|
54 | 54 | assert_not_nil users |
|
55 | 55 | assert_equal 1, users.size |
|
56 | 56 | assert_equal 'John', users.first.firstname |
|
57 | 57 | end |
|
58 | 58 | |
|
59 | 59 | def test_index_with_group_filter |
|
60 | 60 | get :index, :group_id => '10' |
|
61 | 61 | assert_response :success |
|
62 | 62 | assert_template 'index' |
|
63 | 63 | users = assigns(:users) |
|
64 | 64 | assert users.any? |
|
65 | 65 | assert_equal([], (users - Group.find(10).users)) |
|
66 | 66 | assert_select 'select[name=group_id]' do |
|
67 | 67 | assert_select 'option[value=10][selected=selected]' |
|
68 | 68 | end |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | 71 | def test_show |
|
72 | 72 | @request.session[:user_id] = nil |
|
73 | 73 | get :show, :id => 2 |
|
74 | 74 | assert_response :success |
|
75 | 75 | assert_template 'show' |
|
76 | 76 | assert_not_nil assigns(:user) |
|
77 | 77 | |
|
78 | 78 | assert_tag 'li', :content => /Phone number/ |
|
79 | 79 | end |
|
80 | 80 | |
|
81 | 81 | def test_show_should_not_display_hidden_custom_fields |
|
82 | 82 | @request.session[:user_id] = nil |
|
83 | 83 | UserCustomField.find_by_name('Phone number').update_attribute :visible, false |
|
84 | 84 | get :show, :id => 2 |
|
85 | 85 | assert_response :success |
|
86 | 86 | assert_template 'show' |
|
87 | 87 | assert_not_nil assigns(:user) |
|
88 | 88 | |
|
89 | 89 | assert_no_tag 'li', :content => /Phone number/ |
|
90 | 90 | end |
|
91 | 91 | |
|
92 | 92 | def test_show_should_not_fail_when_custom_values_are_nil |
|
93 | 93 | user = User.find(2) |
|
94 | 94 | |
|
95 | 95 | # Create a custom field to illustrate the issue |
|
96 | 96 | custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text') |
|
97 | 97 | custom_value = user.custom_values.build(:custom_field => custom_field).save! |
|
98 | 98 | |
|
99 | 99 | get :show, :id => 2 |
|
100 | 100 | assert_response :success |
|
101 | 101 | end |
|
102 | 102 | |
|
103 | 103 | def test_show_inactive |
|
104 | 104 | @request.session[:user_id] = nil |
|
105 | 105 | get :show, :id => 5 |
|
106 | 106 | assert_response 404 |
|
107 | 107 | end |
|
108 | 108 | |
|
109 | 109 | def test_show_should_not_reveal_users_with_no_visible_activity_or_project |
|
110 | 110 | @request.session[:user_id] = nil |
|
111 | 111 | get :show, :id => 9 |
|
112 | 112 | assert_response 404 |
|
113 | 113 | end |
|
114 | 114 | |
|
115 | 115 | def test_show_inactive_by_admin |
|
116 | 116 | @request.session[:user_id] = 1 |
|
117 | 117 | get :show, :id => 5 |
|
118 | 118 | assert_response 200 |
|
119 | 119 | assert_not_nil assigns(:user) |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | def test_show_displays_memberships_based_on_project_visibility |
|
123 | 123 | @request.session[:user_id] = 1 |
|
124 | 124 | get :show, :id => 2 |
|
125 | 125 | assert_response :success |
|
126 | 126 | memberships = assigns(:memberships) |
|
127 | 127 | assert_not_nil memberships |
|
128 | 128 | project_ids = memberships.map(&:project_id) |
|
129 | 129 | assert project_ids.include?(2) #private project admin can see |
|
130 | 130 | end |
|
131 | 131 | |
|
132 | 132 | def test_show_current_should_require_authentication |
|
133 | 133 | @request.session[:user_id] = nil |
|
134 | 134 | get :show, :id => 'current' |
|
135 | 135 | assert_response 302 |
|
136 | 136 | end |
|
137 | 137 | |
|
138 | 138 | def test_show_current |
|
139 | 139 | @request.session[:user_id] = 2 |
|
140 | 140 | get :show, :id => 'current' |
|
141 | 141 | assert_response :success |
|
142 | 142 | assert_template 'show' |
|
143 | 143 | assert_equal User.find(2), assigns(:user) |
|
144 | 144 | end |
|
145 | 145 | |
|
146 | 146 | def test_new |
|
147 | 147 | get :new |
|
148 | 148 | assert_response :success |
|
149 | 149 | assert_template :new |
|
150 | 150 | assert assigns(:user) |
|
151 | 151 | end |
|
152 | 152 | |
|
153 | 153 | def test_create |
|
154 | 154 | Setting.bcc_recipients = '1' |
|
155 | 155 | |
|
156 | 156 | assert_difference 'User.count' do |
|
157 | 157 | assert_difference 'ActionMailer::Base.deliveries.size' do |
|
158 | 158 | post :create, |
|
159 | 159 | :user => { |
|
160 | 160 | :firstname => 'John', |
|
161 | 161 | :lastname => 'Doe', |
|
162 | 162 | :login => 'jdoe', |
|
163 | 163 | :password => 'secret123', |
|
164 | 164 | :password_confirmation => 'secret123', |
|
165 | 165 | :mail => 'jdoe@gmail.com', |
|
166 | 166 | :mail_notification => 'none' |
|
167 | 167 | }, |
|
168 | 168 | :send_information => '1' |
|
169 | 169 | end |
|
170 | 170 | end |
|
171 | 171 | |
|
172 |
user = User. |
|
|
172 | user = User.order('id DESC').first | |
|
173 | 173 | assert_redirected_to :controller => 'users', :action => 'edit', :id => user.id |
|
174 | 174 | |
|
175 | 175 | assert_equal 'John', user.firstname |
|
176 | 176 | assert_equal 'Doe', user.lastname |
|
177 | 177 | assert_equal 'jdoe', user.login |
|
178 | 178 | assert_equal 'jdoe@gmail.com', user.mail |
|
179 | 179 | assert_equal 'none', user.mail_notification |
|
180 | 180 | assert user.check_password?('secret123') |
|
181 | 181 | |
|
182 | 182 | mail = ActionMailer::Base.deliveries.last |
|
183 | 183 | assert_not_nil mail |
|
184 | 184 | assert_equal [user.mail], mail.bcc |
|
185 | 185 | assert_mail_body_match 'secret', mail |
|
186 | 186 | end |
|
187 | 187 | |
|
188 | 188 | def test_create_with_preferences |
|
189 | 189 | assert_difference 'User.count' do |
|
190 | 190 | post :create, |
|
191 | 191 | :user => { |
|
192 | 192 | :firstname => 'John', |
|
193 | 193 | :lastname => 'Doe', |
|
194 | 194 | :login => 'jdoe', |
|
195 | 195 | :password => 'secret123', |
|
196 | 196 | :password_confirmation => 'secret123', |
|
197 | 197 | :mail => 'jdoe@gmail.com', |
|
198 | 198 | :mail_notification => 'none' |
|
199 | 199 | }, |
|
200 | 200 | :pref => { |
|
201 | 201 | 'hide_mail' => '1', |
|
202 | 202 | 'time_zone' => 'Paris', |
|
203 | 203 | 'comments_sorting' => 'desc', |
|
204 | 204 | 'warn_on_leaving_unsaved' => '0' |
|
205 | 205 | } |
|
206 | 206 | end |
|
207 |
user = User. |
|
|
207 | user = User.order('id DESC').first | |
|
208 | 208 | assert_equal 'jdoe', user.login |
|
209 | 209 | assert_equal true, user.pref.hide_mail |
|
210 | 210 | assert_equal 'Paris', user.pref.time_zone |
|
211 | 211 | assert_equal 'desc', user.pref[:comments_sorting] |
|
212 | 212 | assert_equal '0', user.pref[:warn_on_leaving_unsaved] |
|
213 | 213 | end |
|
214 | 214 | |
|
215 | 215 | def test_create_with_generate_password_should_email_the_password |
|
216 | 216 | assert_difference 'User.count' do |
|
217 | 217 | post :create, :user => { |
|
218 | 218 | :login => 'randompass', |
|
219 | 219 | :firstname => 'Random', |
|
220 | 220 | :lastname => 'Pass', |
|
221 | 221 | :mail => 'randompass@example.net', |
|
222 | 222 | :language => 'en', |
|
223 | 223 | :generate_password => '1', |
|
224 | 224 | :password => '', |
|
225 | 225 | :password_confirmation => '' |
|
226 | 226 | }, :send_information => 1 |
|
227 | 227 | end |
|
228 | 228 | user = User.order('id DESC').first |
|
229 | 229 | assert_equal 'randompass', user.login |
|
230 | 230 | |
|
231 | 231 | mail = ActionMailer::Base.deliveries.last |
|
232 | 232 | assert_not_nil mail |
|
233 | 233 | m = mail_body(mail).match(/Password: ([a-zA-Z0-9]+)/) |
|
234 | 234 | assert m |
|
235 | 235 | password = m[1] |
|
236 | 236 | assert user.check_password?(password) |
|
237 | 237 | end |
|
238 | 238 | |
|
239 | 239 | def test_create_with_failure |
|
240 | 240 | assert_no_difference 'User.count' do |
|
241 | 241 | post :create, :user => {} |
|
242 | 242 | end |
|
243 | 243 | assert_response :success |
|
244 | 244 | assert_template 'new' |
|
245 | 245 | end |
|
246 | 246 | |
|
247 | 247 | def test_create_with_failure_sould_preserve_preference |
|
248 | 248 | assert_no_difference 'User.count' do |
|
249 | 249 | post :create, |
|
250 | 250 | :user => {}, |
|
251 | 251 | :pref => { |
|
252 | 252 | 'no_self_notified' => '1', |
|
253 | 253 | 'hide_mail' => '1', |
|
254 | 254 | 'time_zone' => 'Paris', |
|
255 | 255 | 'comments_sorting' => 'desc', |
|
256 | 256 | 'warn_on_leaving_unsaved' => '0' |
|
257 | 257 | } |
|
258 | 258 | end |
|
259 | 259 | assert_response :success |
|
260 | 260 | assert_template 'new' |
|
261 | 261 | |
|
262 | 262 | assert_select 'select#pref_time_zone option[selected=selected]', :text => /Paris/ |
|
263 | 263 | assert_select 'input#pref_no_self_notified[value=1][checked=checked]' |
|
264 | 264 | end |
|
265 | 265 | |
|
266 | 266 | def test_edit |
|
267 | 267 | get :edit, :id => 2 |
|
268 | 268 | assert_response :success |
|
269 | 269 | assert_template 'edit' |
|
270 | 270 | assert_equal User.find(2), assigns(:user) |
|
271 | 271 | end |
|
272 | 272 | |
|
273 | 273 | def test_update |
|
274 | 274 | ActionMailer::Base.deliveries.clear |
|
275 | 275 | put :update, :id => 2, |
|
276 | 276 | :user => {:firstname => 'Changed', :mail_notification => 'only_assigned'}, |
|
277 | 277 | :pref => {:hide_mail => '1', :comments_sorting => 'desc'} |
|
278 | 278 | user = User.find(2) |
|
279 | 279 | assert_equal 'Changed', user.firstname |
|
280 | 280 | assert_equal 'only_assigned', user.mail_notification |
|
281 | 281 | assert_equal true, user.pref[:hide_mail] |
|
282 | 282 | assert_equal 'desc', user.pref[:comments_sorting] |
|
283 | 283 | assert ActionMailer::Base.deliveries.empty? |
|
284 | 284 | end |
|
285 | 285 | |
|
286 | 286 | def test_update_with_failure |
|
287 | 287 | assert_no_difference 'User.count' do |
|
288 | 288 | put :update, :id => 2, :user => {:firstname => ''} |
|
289 | 289 | end |
|
290 | 290 | assert_response :success |
|
291 | 291 | assert_template 'edit' |
|
292 | 292 | end |
|
293 | 293 | |
|
294 | 294 | def test_update_with_group_ids_should_assign_groups |
|
295 | 295 | put :update, :id => 2, :user => {:group_ids => ['10']} |
|
296 | 296 | user = User.find(2) |
|
297 | 297 | assert_equal [10], user.group_ids |
|
298 | 298 | end |
|
299 | 299 | |
|
300 | 300 | def test_update_with_activation_should_send_a_notification |
|
301 | 301 | u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr') |
|
302 | 302 | u.login = 'foo' |
|
303 | 303 | u.status = User::STATUS_REGISTERED |
|
304 | 304 | u.save! |
|
305 | 305 | ActionMailer::Base.deliveries.clear |
|
306 | 306 | Setting.bcc_recipients = '1' |
|
307 | 307 | |
|
308 | 308 | put :update, :id => u.id, :user => {:status => User::STATUS_ACTIVE} |
|
309 | 309 | assert u.reload.active? |
|
310 | 310 | mail = ActionMailer::Base.deliveries.last |
|
311 | 311 | assert_not_nil mail |
|
312 | 312 | assert_equal ['foo.bar@somenet.foo'], mail.bcc |
|
313 | 313 | assert_mail_body_match ll('fr', :notice_account_activated), mail |
|
314 | 314 | end |
|
315 | 315 | |
|
316 | 316 | def test_update_with_password_change_should_send_a_notification |
|
317 | 317 | ActionMailer::Base.deliveries.clear |
|
318 | 318 | Setting.bcc_recipients = '1' |
|
319 | 319 | |
|
320 | 320 | put :update, :id => 2, :user => {:password => 'newpass123', :password_confirmation => 'newpass123'}, :send_information => '1' |
|
321 | 321 | u = User.find(2) |
|
322 | 322 | assert u.check_password?('newpass123') |
|
323 | 323 | |
|
324 | 324 | mail = ActionMailer::Base.deliveries.last |
|
325 | 325 | assert_not_nil mail |
|
326 | 326 | assert_equal [u.mail], mail.bcc |
|
327 | 327 | assert_mail_body_match 'newpass123', mail |
|
328 | 328 | end |
|
329 | 329 | |
|
330 | 330 | def test_update_with_generate_password_should_email_the_password |
|
331 | 331 | ActionMailer::Base.deliveries.clear |
|
332 | 332 | Setting.bcc_recipients = '1' |
|
333 | 333 | |
|
334 | 334 | put :update, :id => 2, :user => { |
|
335 | 335 | :generate_password => '1', |
|
336 | 336 | :password => '', |
|
337 | 337 | :password_confirmation => '' |
|
338 | 338 | }, :send_information => '1' |
|
339 | 339 | |
|
340 | 340 | mail = ActionMailer::Base.deliveries.last |
|
341 | 341 | assert_not_nil mail |
|
342 | 342 | m = mail_body(mail).match(/Password: ([a-zA-Z0-9]+)/) |
|
343 | 343 | assert m |
|
344 | 344 | password = m[1] |
|
345 | 345 | assert User.find(2).check_password?(password) |
|
346 | 346 | end |
|
347 | 347 | |
|
348 | 348 | def test_update_without_generate_password_should_not_change_password |
|
349 | 349 | put :update, :id => 2, :user => { |
|
350 | 350 | :firstname => 'changed', |
|
351 | 351 | :generate_password => '0', |
|
352 | 352 | :password => '', |
|
353 | 353 | :password_confirmation => '' |
|
354 | 354 | }, :send_information => '1' |
|
355 | 355 | |
|
356 | 356 | user = User.find(2) |
|
357 | 357 | assert_equal 'changed', user.firstname |
|
358 | 358 | assert user.check_password?('jsmith') |
|
359 | 359 | end |
|
360 | 360 | |
|
361 | 361 | def test_update_user_switchin_from_auth_source_to_password_authentication |
|
362 | 362 | # Configure as auth source |
|
363 | 363 | u = User.find(2) |
|
364 | 364 | u.auth_source = AuthSource.find(1) |
|
365 | 365 | u.save! |
|
366 | 366 | |
|
367 | 367 | put :update, :id => u.id, :user => {:auth_source_id => '', :password => 'newpass123', :password_confirmation => 'newpass123'} |
|
368 | 368 | |
|
369 | 369 | assert_equal nil, u.reload.auth_source |
|
370 | 370 | assert u.check_password?('newpass123') |
|
371 | 371 | end |
|
372 | 372 | |
|
373 | 373 | def test_update_notified_project |
|
374 | 374 | get :edit, :id => 2 |
|
375 | 375 | assert_response :success |
|
376 | 376 | assert_template 'edit' |
|
377 | 377 | u = User.find(2) |
|
378 | 378 | assert_equal [1, 2, 5], u.projects.collect{|p| p.id}.sort |
|
379 | 379 | assert_equal [1, 2, 5], u.notified_projects_ids.sort |
|
380 | 380 | assert_select 'input[name=?][value=?]', 'user[notified_project_ids][]', '1' |
|
381 | 381 | assert_equal 'all', u.mail_notification |
|
382 | 382 | put :update, :id => 2, |
|
383 | 383 | :user => { |
|
384 | 384 | :mail_notification => 'selected', |
|
385 | 385 | :notified_project_ids => [1, 2] |
|
386 | 386 | } |
|
387 | 387 | u = User.find(2) |
|
388 | 388 | assert_equal 'selected', u.mail_notification |
|
389 | 389 | assert_equal [1, 2], u.notified_projects_ids.sort |
|
390 | 390 | end |
|
391 | 391 | |
|
392 | 392 | def test_update_status_should_not_update_attributes |
|
393 | 393 | user = User.find(2) |
|
394 | 394 | user.pref[:no_self_notified] = '1' |
|
395 | 395 | user.pref.save |
|
396 | 396 | |
|
397 | 397 | put :update, :id => 2, :user => {:status => 3} |
|
398 | 398 | assert_response 302 |
|
399 | 399 | user = User.find(2) |
|
400 | 400 | assert_equal 3, user.status |
|
401 | 401 | assert_equal '1', user.pref[:no_self_notified] |
|
402 | 402 | end |
|
403 | 403 | |
|
404 | 404 | def test_destroy |
|
405 | 405 | assert_difference 'User.count', -1 do |
|
406 | 406 | delete :destroy, :id => 2 |
|
407 | 407 | end |
|
408 | 408 | assert_redirected_to '/users' |
|
409 | 409 | assert_nil User.find_by_id(2) |
|
410 | 410 | end |
|
411 | 411 | |
|
412 | 412 | def test_destroy_should_be_denied_for_non_admin_users |
|
413 | 413 | @request.session[:user_id] = 3 |
|
414 | 414 | |
|
415 | 415 | assert_no_difference 'User.count' do |
|
416 | 416 | get :destroy, :id => 2 |
|
417 | 417 | end |
|
418 | 418 | assert_response 403 |
|
419 | 419 | end |
|
420 | 420 | |
|
421 | 421 | def test_destroy_should_redirect_to_back_url_param |
|
422 | 422 | assert_difference 'User.count', -1 do |
|
423 | 423 | delete :destroy, :id => 2, :back_url => '/users?name=foo' |
|
424 | 424 | end |
|
425 | 425 | assert_redirected_to '/users?name=foo' |
|
426 | 426 | end |
|
427 | 427 | |
|
428 | 428 | def test_create_membership |
|
429 | 429 | assert_difference 'Member.count' do |
|
430 | 430 | post :edit_membership, :id => 7, :membership => { :project_id => 3, :role_ids => [2]} |
|
431 | 431 | end |
|
432 | 432 | assert_redirected_to :action => 'edit', :id => '7', :tab => 'memberships' |
|
433 |
member = Member. |
|
|
433 | member = Member.order('id DESC').first | |
|
434 | 434 | assert_equal User.find(7), member.principal |
|
435 | 435 | assert_equal [2], member.role_ids |
|
436 | 436 | assert_equal 3, member.project_id |
|
437 | 437 | end |
|
438 | 438 | |
|
439 | 439 | def test_create_membership_js_format |
|
440 | 440 | assert_difference 'Member.count' do |
|
441 | 441 | post :edit_membership, :id => 7, :membership => {:project_id => 3, :role_ids => [2]}, :format => 'js' |
|
442 | 442 | assert_response :success |
|
443 | 443 | assert_template 'edit_membership' |
|
444 | 444 | assert_equal 'text/javascript', response.content_type |
|
445 | 445 | end |
|
446 |
member = Member. |
|
|
446 | member = Member.order('id DESC').first | |
|
447 | 447 | assert_equal User.find(7), member.principal |
|
448 | 448 | assert_equal [2], member.role_ids |
|
449 | 449 | assert_equal 3, member.project_id |
|
450 | 450 | assert_include 'tab-content-memberships', response.body |
|
451 | 451 | end |
|
452 | 452 | |
|
453 | 453 | def test_create_membership_js_format_with_failure |
|
454 | 454 | assert_no_difference 'Member.count' do |
|
455 | 455 | post :edit_membership, :id => 7, :membership => {:project_id => 3}, :format => 'js' |
|
456 | 456 | assert_response :success |
|
457 | 457 | assert_template 'edit_membership' |
|
458 | 458 | assert_equal 'text/javascript', response.content_type |
|
459 | 459 | end |
|
460 | 460 | assert_include 'alert', response.body, "Alert message not sent" |
|
461 | 461 | assert_include 'Role can\\\'t be empty', response.body, "Error message not sent" |
|
462 | 462 | end |
|
463 | 463 | |
|
464 | 464 | def test_update_membership |
|
465 | 465 | assert_no_difference 'Member.count' do |
|
466 | 466 | put :edit_membership, :id => 2, :membership_id => 1, :membership => { :role_ids => [2]} |
|
467 | 467 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' |
|
468 | 468 | end |
|
469 | 469 | assert_equal [2], Member.find(1).role_ids |
|
470 | 470 | end |
|
471 | 471 | |
|
472 | 472 | def test_update_membership_js_format |
|
473 | 473 | assert_no_difference 'Member.count' do |
|
474 | 474 | put :edit_membership, :id => 2, :membership_id => 1, :membership => {:role_ids => [2]}, :format => 'js' |
|
475 | 475 | assert_response :success |
|
476 | 476 | assert_template 'edit_membership' |
|
477 | 477 | assert_equal 'text/javascript', response.content_type |
|
478 | 478 | end |
|
479 | 479 | assert_equal [2], Member.find(1).role_ids |
|
480 | 480 | assert_include 'tab-content-memberships', response.body |
|
481 | 481 | end |
|
482 | 482 | |
|
483 | 483 | def test_destroy_membership |
|
484 | 484 | assert_difference 'Member.count', -1 do |
|
485 | 485 | delete :destroy_membership, :id => 2, :membership_id => 1 |
|
486 | 486 | end |
|
487 | 487 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' |
|
488 | 488 | assert_nil Member.find_by_id(1) |
|
489 | 489 | end |
|
490 | 490 | |
|
491 | 491 | def test_destroy_membership_js_format |
|
492 | 492 | assert_difference 'Member.count', -1 do |
|
493 | 493 | delete :destroy_membership, :id => 2, :membership_id => 1, :format => 'js' |
|
494 | 494 | assert_response :success |
|
495 | 495 | assert_template 'destroy_membership' |
|
496 | 496 | assert_equal 'text/javascript', response.content_type |
|
497 | 497 | end |
|
498 | 498 | assert_nil Member.find_by_id(1) |
|
499 | 499 | assert_include 'tab-content-memberships', response.body |
|
500 | 500 | end |
|
501 | 501 | end |
General Comments 0
You need to be logged in to leave comments.
Login now