3 class UsersControllerTest < ActionDispatch::IntegrationTest
5 # test all routes which lead to this controller
8 { :path => "/login", :method => :get },
9 { :controller => "users", :action => "login" }
12 { :path => "/login", :method => :post },
13 { :controller => "users", :action => "login" }
16 { :controller => "users", :action => "login", :format => "html" },
17 { :path => "/login.html", :method => :get }
21 { :path => "/logout", :method => :get },
22 { :controller => "users", :action => "logout" }
25 { :path => "/logout", :method => :post },
26 { :controller => "users", :action => "logout" }
29 { :controller => "users", :action => "logout", :format => "html" },
30 { :path => "/logout.html", :method => :get }
34 { :path => "/user/new", :method => :get },
35 { :controller => "users", :action => "new" }
39 { :path => "/user/new", :method => :post },
40 { :controller => "users", :action => "create" }
44 { :path => "/user/terms", :method => :get },
45 { :controller => "users", :action => "terms" }
49 { :path => "/user/save", :method => :post },
50 { :controller => "users", :action => "save" }
54 { :path => "/user/username/confirm", :method => :get },
55 { :controller => "users", :action => "confirm", :display_name => "username" }
58 { :path => "/user/username/confirm", :method => :post },
59 { :controller => "users", :action => "confirm", :display_name => "username" }
62 { :path => "/user/username/confirm/resend", :method => :get },
63 { :controller => "users", :action => "confirm_resend", :display_name => "username" }
67 { :path => "/user/confirm", :method => :get },
68 { :controller => "users", :action => "confirm" }
71 { :path => "/user/confirm", :method => :post },
72 { :controller => "users", :action => "confirm" }
75 { :path => "/user/confirm-email", :method => :get },
76 { :controller => "users", :action => "confirm_email" }
79 { :path => "/user/confirm-email", :method => :post },
80 { :controller => "users", :action => "confirm_email" }
84 { :path => "/user/go_public", :method => :post },
85 { :controller => "users", :action => "go_public" }
89 { :path => "/user/forgot-password", :method => :get },
90 { :controller => "users", :action => "lost_password" }
93 { :path => "/user/forgot-password", :method => :post },
94 { :controller => "users", :action => "lost_password" }
97 { :path => "/user/reset-password", :method => :get },
98 { :controller => "users", :action => "reset_password" }
101 { :path => "/user/reset-password", :method => :post },
102 { :controller => "users", :action => "reset_password" }
106 { :path => "/user/suspended", :method => :get },
107 { :controller => "users", :action => "suspended" }
111 { :path => "/user/username", :method => :get },
112 { :controller => "users", :action => "show", :display_name => "username" }
116 { :path => "/user/username/account", :method => :get },
117 { :controller => "users", :action => "account", :display_name => "username" }
120 { :path => "/user/username/account", :method => :post },
121 { :controller => "users", :action => "account", :display_name => "username" }
125 { :path => "/user/username/set_status", :method => :post },
126 { :controller => "users", :action => "set_status", :display_name => "username" }
129 { :path => "/user/username", :method => :delete },
130 { :controller => "users", :action => "destroy", :display_name => "username" }
134 { :path => "/users", :method => :get },
135 { :controller => "users", :action => "index" }
138 { :path => "/users", :method => :post },
139 { :controller => "users", :action => "index" }
142 { :path => "/users/status", :method => :get },
143 { :controller => "users", :action => "index", :status => "status" }
146 { :path => "/users/status", :method => :post },
147 { :controller => "users", :action => "index", :status => "status" }
151 # The user creation page loads
154 assert_response :redirect
155 assert_redirected_to user_new_path(:cookie_test => "true")
157 get user_new_path, :params => { :cookie_test => "true" }
158 assert_response :success
160 assert_select "html", :count => 1 do
161 assert_select "head", :count => 1 do
162 assert_select "title", :text => /Sign Up/, :count => 1
164 assert_select "body", :count => 1 do
165 assert_select "div#content", :count => 1 do
166 assert_select "form[action='/user/new'][method='post']", :count => 1 do
167 assert_select "input[id='user_email']", :count => 1
168 assert_select "input[id='user_email_confirmation']", :count => 1
169 assert_select "input[id='user_display_name']", :count => 1
170 assert_select "input[id='user_pass_crypt'][type='password']", :count => 1
171 assert_select "input[id='user_pass_crypt_confirmation'][type='password']", :count => 1
172 assert_select "input[type='submit'][value='Sign Up']", :count => 1
179 def test_new_view_logged_in
180 session_for(create(:user))
183 assert_response :redirect
184 assert_redirected_to root_path
186 get user_new_path, :params => { :referer => "/test" }
187 assert_response :redirect
188 assert_redirected_to "/test"
192 user = build(:user, :pending)
194 assert_no_difference "User.count" do
195 assert_no_difference "ActionMailer::Base.deliveries.size" do
196 perform_enqueued_jobs do
197 post user_new_path, :params => { :user => user.attributes }
202 assert_difference "User.count", 1 do
203 assert_difference "ActionMailer::Base.deliveries.size", 1 do
204 perform_enqueued_jobs do
205 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
211 register_email = ActionMailer::Base.deliveries.first
213 assert_equal register_email.to[0], user.email
214 assert_match(/#{@url}/, register_email.body.to_s)
217 assert_redirected_to :action => "confirm", :display_name => user.display_name
219 ActionMailer::Base.deliveries.clear
222 def test_new_duplicate_email
223 user = build(:user, :pending)
224 create(:user, :email => user.email)
226 assert_no_difference "User.count" do
227 assert_no_difference "ActionMailer::Base.deliveries.size" do
228 perform_enqueued_jobs do
229 post user_new_path, :params => { :user => user.attributes }
234 assert_response :success
235 assert_template "new"
236 assert_select "form > div.form-group > input.is-invalid#user_email"
239 def test_save_duplicate_email
240 user = build(:user, :pending)
242 # Set up our user as being half-way through registration
243 assert_no_difference "User.count" do
244 assert_no_difference "ActionMailer::Base.deliveries.size" do
245 perform_enqueued_jobs do
246 post user_new_path, :params => { :user => user.attributes }
251 # Now create another user with that email
252 create(:user, :email => user.email)
254 # Check that the second half of registration fails
255 assert_no_difference "User.count" do
256 assert_no_difference "ActionMailer::Base.deliveries.size" do
257 perform_enqueued_jobs do
258 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
263 assert_response :success
264 assert_template "new"
265 assert_select "form > div.form-group > input.is-invalid#user_email"
268 def test_save_duplicate_email_uppercase
269 user = build(:user, :pending)
271 # Set up our user as being half-way through registration
272 assert_no_difference "User.count" do
273 assert_no_difference "ActionMailer::Base.deliveries.size" do
274 perform_enqueued_jobs do
275 post user_new_path, :params => { :user => user.attributes }
280 # Now create another user with that email, but uppercased
281 create(:user, :email => user.email.upcase)
283 # Check that the second half of registration fails
284 assert_no_difference "User.count" do
285 assert_no_difference "ActionMailer::Base.deliveries.size" do
286 perform_enqueued_jobs do
287 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
292 assert_response :success
293 assert_template "new"
294 assert_select "form > div.form-group > input.is-invalid#user_email"
297 def test_save_duplicate_name
298 user = build(:user, :pending)
300 # Set up our user as being half-way through registration
301 assert_no_difference "User.count" do
302 assert_no_difference "ActionMailer::Base.deliveries.size" do
303 perform_enqueued_jobs do
304 post user_new_path, :params => { :user => user.attributes }
309 # Now create another user with that display name
310 create(:user, :display_name => user.display_name)
312 # Check that the second half of registration fails
313 assert_no_difference "User.count" do
314 assert_no_difference "ActionMailer::Base.deliveries.size" do
315 perform_enqueued_jobs do
316 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
321 assert_response :success
322 assert_template "new"
323 assert_select "form > div.form-group > input.is-invalid#user_display_name"
326 def test_save_duplicate_name_uppercase
327 user = build(:user, :pending)
329 # Set up our user as being half-way through registration
330 assert_no_difference "User.count" do
331 assert_no_difference "ActionMailer::Base.deliveries.size" do
332 perform_enqueued_jobs do
333 post user_new_path, :params => { :user => user.attributes }
338 # Now create another user with that display_name, but uppercased
339 create(:user, :display_name => user.display_name.upcase)
341 # Check that the second half of registration fails
342 assert_no_difference "User.count" do
343 assert_no_difference "ActionMailer::Base.deliveries.size" do
344 perform_enqueued_jobs do
345 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
350 assert_response :success
351 assert_template "new"
352 assert_select "form > div.form-group > input.is-invalid#user_display_name"
355 def test_save_blocked_domain
356 user = build(:user, :pending, :email => "user@example.net")
358 # Set up our user as being half-way through registration
359 assert_no_difference "User.count" do
360 assert_no_difference "ActionMailer::Base.deliveries.size" do
361 perform_enqueued_jobs do
362 post user_new_path, :params => { :user => user.attributes }
367 # Now block that domain
368 create(:acl, :domain => "example.net", :k => "no_account_creation")
370 # Check that the second half of registration fails
371 assert_no_difference "User.count" do
372 assert_no_difference "ActionMailer::Base.deliveries.size" do
373 perform_enqueued_jobs do
374 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
379 assert_response :success
380 assert_template "blocked"
383 def test_save_referer_params
384 user = build(:user, :pending)
386 # Set up our user as being half-way through registration
387 assert_no_difference "User.count" do
388 assert_no_difference "ActionMailer::Base.deliveries.size" do
389 perform_enqueued_jobs do
390 post user_new_path, :params => { :user => user.attributes, :referer => "/edit?editor=id#map=1/2/3" }
395 assert_difference "User.count", 1 do
396 assert_difference "ActionMailer::Base.deliveries.size", 1 do
397 perform_enqueued_jobs do
398 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
403 assert_equal welcome_path(:editor => "id", :zoom => 1, :lat => 2, :lon => 3),
404 User.find_by(:email => user.email).tokens.order("id DESC").first.referer
406 ActionMailer::Base.deliveries.clear
409 def test_logout_without_referer
411 assert_response :redirect
412 assert_redirected_to root_path
415 def test_logout_with_referer
416 post logout_path, :params => { :referer => "/test" }
417 assert_response :redirect
418 assert_redirected_to "/test"
421 def test_logout_fallback_without_referer
423 assert_response :success
424 assert_template :logout
425 assert_select "input[name=referer]:not([value])"
428 def test_logout_fallback_with_referer
429 get logout_path, :params => { :referer => "/test" }
430 assert_response :success
431 assert_template :logout
432 assert_select "input[name=referer][value=?]", "/test"
435 def test_logout_removes_session_token
436 user = build(:user, :pending)
437 post user_new_path, :params => { :user => user.attributes }
438 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
440 assert_difference "User.find_by(:email => user.email).tokens.count", -1 do
443 assert_response :redirect
444 assert_redirected_to root_path
448 user = build(:user, :pending)
449 post user_new_path, :params => { :user => user.attributes }
450 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
451 confirm_string = User.find_by(:email => user.email).tokens.create.token
453 get user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
454 assert_response :success
455 assert_template :confirm
458 def test_confirm_get_already_confirmed
459 user = build(:user, :pending)
460 stub_gravatar_request(user.email)
461 post user_new_path, :params => { :user => user.attributes }
462 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
463 confirm_string = User.find_by(:email => user.email).tokens.create.token
465 # Get the confirmation page
466 get user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
467 assert_response :success
468 assert_template :confirm
471 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
472 assert_redirected_to welcome_path
474 # Now try to get the confirmation page again
475 get user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
476 assert_response :redirect
477 assert_redirected_to root_path
480 def test_confirm_success_no_token_no_referer
481 user = build(:user, :pending)
482 stub_gravatar_request(user.email)
483 post user_new_path, :params => { :user => user.attributes }
484 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
485 confirm_string = User.find_by(:email => user.email).tokens.create.token
489 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
490 assert_redirected_to login_path
491 assert_match(/Confirmed your account/, flash[:notice])
494 def test_confirm_success_good_token_no_referer
495 user = build(:user, :pending)
496 stub_gravatar_request(user.email)
497 post user_new_path, :params => { :user => user.attributes }
498 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
499 confirm_string = User.find_by(:email => user.email).tokens.create.token
501 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
502 assert_redirected_to welcome_path
505 def test_confirm_success_bad_token_no_referer
506 user = build(:user, :pending)
507 stub_gravatar_request(user.email)
508 post user_new_path, :params => { :user => user.attributes }
509 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
510 confirm_string = User.find_by(:email => user.email).tokens.create.token
513 session_for(create(:user))
515 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
516 assert_redirected_to login_path
517 assert_match(/Confirmed your account/, flash[:notice])
520 def test_confirm_success_no_token_with_referer
521 user = build(:user, :pending)
522 stub_gravatar_request(user.email)
523 post user_new_path, :params => { :user => user.attributes }
524 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
525 confirm_string = User.find_by(:email => user.email).tokens.create(:referer => new_diary_entry_path).token
529 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
530 assert_redirected_to login_path(:referer => new_diary_entry_path)
531 assert_match(/Confirmed your account/, flash[:notice])
534 def test_confirm_success_good_token_with_referer
535 user = build(:user, :pending)
536 stub_gravatar_request(user.email)
537 post user_new_path, :params => { :user => user.attributes }
538 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
539 confirm_string = User.find_by(:email => user.email).tokens.create(:referer => new_diary_entry_path).token
541 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
542 assert_redirected_to new_diary_entry_path
545 def test_confirm_success_bad_token_with_referer
546 user = build(:user, :pending)
547 stub_gravatar_request(user.email)
548 post user_new_path, :params => { :user => user.attributes }
549 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
550 confirm_string = User.find_by(:email => user.email).tokens.create(:referer => new_diary_entry_path).token
553 session_for(create(:user))
555 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
556 assert_redirected_to login_path(:referer => new_diary_entry_path)
557 assert_match(/Confirmed your account/, flash[:notice])
560 def test_confirm_expired_token
561 user = build(:user, :pending)
562 stub_gravatar_request(user.email)
563 post user_new_path, :params => { :user => user.attributes }
564 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
565 confirm_string = User.find_by(:email => user.email).tokens.create(:expiry => 1.day.ago).token
567 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
568 assert_redirected_to :action => "confirm"
569 assert_match(/confirmation code has expired/, flash[:error])
572 def test_confirm_already_confirmed
573 user = build(:user, :pending)
574 stub_gravatar_request(user.email)
575 post user_new_path, :params => { :user => user.attributes }
576 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
577 confirm_string = User.find_by(:email => user.email).tokens.create(:referer => new_diary_entry_path).token
579 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
580 assert_redirected_to new_diary_entry_path
584 confirm_string = User.find_by(:email => user.email).tokens.create(:referer => new_diary_entry_path).token
585 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
586 assert_redirected_to :action => "login"
587 assert_match(/already been confirmed/, flash[:error])
590 def test_confirm_resend_success
591 user = build(:user, :pending)
592 post user_new_path, :params => { :user => user.attributes }
593 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
595 assert_difference "ActionMailer::Base.deliveries.size", 1 do
596 perform_enqueued_jobs do
597 get user_confirm_resend_path(user)
601 assert_response :redirect
602 assert_redirected_to login_path
603 assert_match(/sent a new confirmation/, flash[:notice])
605 email = ActionMailer::Base.deliveries.last
607 assert_equal user.email, email.to.first
609 ActionMailer::Base.deliveries.clear
612 def test_confirm_resend_no_token
613 user = build(:user, :pending)
614 # only complete first half of registration
615 post user_new_path, :params => { :user => user.attributes }
617 assert_no_difference "ActionMailer::Base.deliveries.size" do
618 perform_enqueued_jobs do
619 get user_confirm_resend_path(user)
623 assert_response :redirect
624 assert_redirected_to login_path
625 assert_match "User #{user.display_name} not found.", flash[:error]
628 def test_confirm_resend_unknown_user
629 assert_no_difference "ActionMailer::Base.deliveries.size" do
630 perform_enqueued_jobs do
631 get user_confirm_resend_path(:display_name => "No Such User")
635 assert_response :redirect
636 assert_redirected_to login_path
637 assert_match "User No Such User not found.", flash[:error]
640 def test_confirm_email_get
642 confirm_string = user.tokens.create.token
644 get user_confirm_email_path, :params => { :confirm_string => confirm_string }
645 assert_response :success
646 assert_template :confirm_email
649 def test_confirm_email_success
650 user = create(:user, :new_email => "test-new@example.com")
651 stub_gravatar_request(user.new_email)
652 confirm_string = user.tokens.create.token
654 post user_confirm_email_path, :params => { :confirm_string => confirm_string }
655 assert_response :redirect
656 assert_redirected_to :action => :account, :display_name => user.display_name
657 assert_match(/Confirmed your change of email address/, flash[:notice])
660 def test_confirm_email_already_confirmed
662 confirm_string = user.tokens.create.token
664 post user_confirm_email_path, :params => { :confirm_string => confirm_string }
665 assert_response :redirect
666 assert_redirected_to :action => :account, :display_name => user.display_name
667 assert_match(/already been confirmed/, flash[:error])
670 def test_confirm_email_bad_token
671 post user_confirm_email_path, :params => { :confirm_string => "XXXXX" }
672 assert_response :success
673 assert_template :confirm_email
674 assert_match(/confirmation code has expired or does not exist/, flash[:error])
678 # test if testing for a gravatar works
679 # this happens when the email is actually changed
680 # which is triggered by the confirmation mail
681 def test_gravatar_auto_enable
682 # switch to email that has a gravatar
683 user = create(:user, :new_email => "test-new@example.com")
684 stub_gravatar_request(user.new_email, 200)
685 confirm_string = user.tokens.create.token
686 # precondition gravatar should be turned off
687 assert_not user.image_use_gravatar
688 post user_confirm_email_path, :params => { :confirm_string => confirm_string }
689 assert_response :redirect
690 assert_redirected_to :action => :account, :display_name => user.display_name
691 assert_match(/Confirmed your change of email address/, flash[:notice])
692 # gravatar use should now be enabled
693 assert User.find(user.id).image_use_gravatar
696 def test_gravatar_auto_disable
697 # switch to email without a gravatar
698 user = create(:user, :new_email => "test-new@example.com", :image_use_gravatar => true)
699 stub_gravatar_request(user.new_email, 404)
700 confirm_string = user.tokens.create.token
701 # precondition gravatar should be turned on
702 assert user.image_use_gravatar
703 post user_confirm_email_path, :params => { :confirm_string => confirm_string }
704 assert_response :redirect
705 assert_redirected_to :action => :account, :display_name => user.display_name
706 assert_match(/Confirmed your change of email address/, flash[:notice])
707 # gravatar use should now be disabled
708 assert_not User.find(user.id).image_use_gravatar
711 def test_terms_new_user
712 user = build(:user, :pending)
714 # Set up our user as being half-way through registration
715 assert_no_difference "User.count" do
716 assert_no_difference "ActionMailer::Base.deliveries.size" do
717 perform_enqueued_jobs do
718 post user_new_path, :params => { :user => user.attributes }
725 assert_response :success
726 assert_template :terms
729 def test_terms_agreed
730 user = create(:user, :terms_seen => true, :terms_agreed => Date.yesterday)
735 assert_response :redirect
736 assert_redirected_to :action => :account, :display_name => user.display_name
739 def test_terms_not_seen_without_referer
740 user = create(:user, :terms_seen => false, :terms_agreed => nil)
745 assert_response :success
746 assert_template :terms
748 post user_save_path, :params => { :user => { :consider_pd => true }, :read_ct => 1, :read_tou => 1 }
749 assert_response :redirect
750 assert_redirected_to :action => :account, :display_name => user.display_name
751 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
755 assert user.consider_pd
756 assert_not_nil user.terms_agreed
757 assert user.terms_seen
760 def test_terms_not_seen_with_referer
761 user = create(:user, :terms_seen => false, :terms_agreed => nil)
765 get user_terms_path, :params => { :referer => "/test" }
766 assert_response :success
767 assert_template :terms
769 post user_save_path, :params => { :user => { :consider_pd => true }, :referer => "/test", :read_ct => 1, :read_tou => 1 }
770 assert_response :redirect
771 assert_redirected_to "/test"
772 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
776 assert user.consider_pd
777 assert_not_nil user.terms_agreed
778 assert user.terms_seen
781 # Check that if you haven't seen the terms, and make a request that requires authentication,
782 # that your request is redirected to view the terms
783 def test_terms_not_seen_redirection
784 user = create(:user, :terms_seen => false, :terms_agreed => nil)
787 get user_account_path(user)
788 assert_response :redirect
789 assert_redirected_to :action => :terms, :referer => "/user/#{ERB::Util.u(user.display_name)}/account"
793 user = create(:user, :data_public => false)
796 post user_go_public_path
798 assert_response :redirect
799 assert_redirected_to :action => :account, :display_name => user.display_name
800 assert User.find(user.id).data_public
803 def test_lost_password
804 # Test fetching the lost password page
805 get user_forgot_password_path
806 assert_response :success
807 assert_template :lost_password
808 assert_select "div#notice", false
810 # Test resetting using the address as recorded for a user that has an
811 # address which is duplicated in a different case by another user
813 uppercase_user = build(:user, :email => user.email.upcase).tap { |u| u.save(:validate => false) }
815 assert_difference "ActionMailer::Base.deliveries.size", 1 do
816 perform_enqueued_jobs do
817 post user_forgot_password_path, :params => { :email => user.email }
820 assert_response :redirect
821 assert_redirected_to :action => :login
822 assert_match(/^Sorry you lost it/, flash[:notice])
823 email = ActionMailer::Base.deliveries.first
824 assert_equal 1, email.to.count
825 assert_equal user.email, email.to.first
826 ActionMailer::Base.deliveries.clear
828 # Test resetting using an address that matches a different user
829 # that has the same address in a different case
830 assert_difference "ActionMailer::Base.deliveries.size", 1 do
831 perform_enqueued_jobs do
832 post user_forgot_password_path, :params => { :email => user.email.upcase }
835 assert_response :redirect
836 assert_redirected_to :action => :login
837 assert_match(/^Sorry you lost it/, flash[:notice])
838 email = ActionMailer::Base.deliveries.first
839 assert_equal 1, email.to.count
840 assert_equal uppercase_user.email, email.to.first
841 ActionMailer::Base.deliveries.clear
843 # Test resetting using an address that is a case insensitive match
844 # for more than one user but not an exact match for either
845 assert_no_difference "ActionMailer::Base.deliveries.size" do
846 perform_enqueued_jobs do
847 post user_forgot_password_path, :params => { :email => user.email.titlecase }
850 assert_response :success
851 assert_template :lost_password
852 assert_select ".error", /^Could not find that email address/
854 # Test resetting using the address as recorded for a user that has an
855 # address which is case insensitively unique
856 third_user = create(:user)
857 assert_difference "ActionMailer::Base.deliveries.size", 1 do
858 perform_enqueued_jobs do
859 post user_forgot_password_path, :params => { :email => third_user.email }
862 assert_response :redirect
863 assert_redirected_to :action => :login
864 assert_match(/^Sorry you lost it/, flash[:notice])
865 email = ActionMailer::Base.deliveries.first
866 assert_equal 1, email.to.count
867 assert_equal third_user.email, email.to.first
868 ActionMailer::Base.deliveries.clear
870 # Test resetting using an address that matches a user that has the
871 # same (case insensitively unique) address in a different case
872 assert_difference "ActionMailer::Base.deliveries.size", 1 do
873 perform_enqueued_jobs do
874 post user_forgot_password_path, :params => { :email => third_user.email.upcase }
877 assert_response :redirect
878 assert_redirected_to :action => :login
879 assert_match(/^Sorry you lost it/, flash[:notice])
880 email = ActionMailer::Base.deliveries.first
881 assert_equal 1, email.to.count
882 assert_equal third_user.email, email.to.first
883 ActionMailer::Base.deliveries.clear
886 def test_reset_password
887 user = create(:user, :pending)
888 # Test a request with no token
889 get user_reset_password_path
890 assert_response :bad_request
892 # Test a request with a bogus token
893 get user_reset_password_path, :params => { :token => "made_up_token" }
894 assert_response :redirect
895 assert_redirected_to :action => :lost_password
897 # Create a valid token for a user
898 token = user.tokens.create
900 # Test a request with a valid token
901 get user_reset_password_path, :params => { :token => token.token }
902 assert_response :success
903 assert_template :reset_password
905 # Test that errors are reported for erroneous submissions
906 post user_reset_password_path, :params => { :token => token.token, :user => { :pass_crypt => "new_password", :pass_crypt_confirmation => "different_password" } }
907 assert_response :success
908 assert_template :reset_password
909 assert_select "div.invalid-feedback"
911 # Test setting a new password
912 post user_reset_password_path, :params => { :token => token.token, :user => { :pass_crypt => "new_password", :pass_crypt_confirmation => "new_password" } }
913 assert_response :redirect
914 assert_redirected_to root_path
915 assert_equal user.id, session[:user]
917 assert_equal "active", user.status
918 assert user.email_valid
919 assert_equal user, User.authenticate(:username => user.email, :password => "new_password")
923 # Get a user to work with - note that this user deliberately
924 # conflicts with uppercase_user in the email and display name
925 # fields to test that we can change other fields without any
926 # validation errors being reported
927 user = create(:user, :languages => [])
928 _uppercase_user = build(:user, :email => user.email.upcase, :display_name => user.display_name.upcase).tap { |u| u.save(:validate => false) }
930 # Make sure that you are redirected to the login page when
931 # you are not logged in
932 get user_account_path(user)
933 assert_response :redirect
934 assert_redirected_to :action => "login", :referer => "/user/#{ERB::Util.u(user.display_name)}/account"
936 # Make sure that you are blocked when not logged in as the right user
937 session_for(create(:user))
938 get user_account_path(user)
939 assert_response :forbidden
941 # Make sure we get the page when we are logged in as the right user
943 get user_account_path(user)
944 assert_response :success
945 assert_template :account
946 assert_select "form#accountForm" do |form|
947 assert_equal "post", form.attr("method").to_s
948 assert_select "input[name='_method']", false
949 assert_equal "/user/#{ERB::Util.u(user.display_name)}/account", form.attr("action").to_s
952 # Updating the description should work
953 user.description = "new description"
954 user.preferred_editor = "default"
955 post user_account_path(user), :params => { :user => user.attributes }
956 assert_response :redirect
957 assert_redirected_to user_account_url(user)
958 get user_account_path(user)
959 assert_response :success
960 assert_template :account
961 assert_select "div#errorExplanation", false
962 assert_select ".notice", /^User information updated successfully/
963 assert_select "form#accountForm > fieldset > div.standard-form-row > div#user_description_container > div#user_description_content > textarea#user_description", user.description
965 # Changing to a invalid editor should fail
966 user.preferred_editor = "unknown"
967 post user_account_path(user), :params => { :user => user.attributes }
968 assert_response :success
969 assert_template :account
970 assert_select ".notice", false
971 assert_select "div#errorExplanation"
972 assert_select "form#accountForm > fieldset > div.standard-form-row > select#user_preferred_editor > option[selected]", false
974 # Changing to a valid editor should work
975 user.preferred_editor = "id"
976 post user_account_path(user), :params => { :user => user.attributes }
977 assert_response :redirect
978 assert_redirected_to user_account_url(user)
979 get user_account_path(user)
980 assert_response :success
981 assert_template :account
982 assert_select "div#errorExplanation", false
983 assert_select ".notice", /^User information updated successfully/
984 assert_select "form#accountForm > fieldset > div.standard-form-row > select#user_preferred_editor > option[selected][value=?]", "id"
986 # Changing to the default editor should work
987 user.preferred_editor = "default"
988 post user_account_path(user), :params => { :user => user.attributes }
989 assert_response :redirect
990 assert_redirected_to user_account_url(user)
991 get user_account_path(user)
992 assert_response :success
993 assert_template :account
994 assert_select "div#errorExplanation", false
995 assert_select ".notice", /^User information updated successfully/
996 assert_select "form#accountForm > fieldset > div.standard-form-row > select#user_preferred_editor > option[selected]", false
998 # Changing to an uploaded image should work
999 image = Rack::Test::UploadedFile.new("test/gpx/fixtures/a.gif", "image/gif")
1000 post user_account_path(user), :params => { :avatar_action => "new", :user => user.attributes.merge(:avatar => image) }
1001 assert_response :redirect
1002 assert_redirected_to user_account_url(user)
1003 get user_account_path(user)
1004 assert_response :success
1005 assert_template :account
1006 assert_select "div#errorExplanation", false
1007 assert_select ".notice", /^User information updated successfully/
1008 assert_select "form#accountForm > fieldset > div.standard-form-row.accountImage input[name=avatar_action][checked][value=?]", "keep"
1010 # Changing to a gravatar image should work
1011 post user_account_path(user), :params => { :avatar_action => "gravatar", :user => user.attributes }
1012 assert_response :redirect
1013 assert_redirected_to user_account_url(user)
1014 get user_account_path(user)
1015 assert_response :success
1016 assert_template :account
1017 assert_select "div#errorExplanation", false
1018 assert_select ".notice", /^User information updated successfully/
1019 assert_select "form#accountForm > fieldset > div.standard-form-row.accountImage input[name=avatar_action][checked][value=?]", "gravatar"
1021 # Removing the image should work
1022 post user_account_path(user), :params => { :avatar_action => "delete", :user => user.attributes }
1023 assert_response :redirect
1024 assert_redirected_to user_account_url(user)
1025 get user_account_path(user)
1026 assert_response :success
1027 assert_template :account
1028 assert_select "div#errorExplanation", false
1029 assert_select ".notice", /^User information updated successfully/
1030 assert_select "form#accountForm > fieldset > div.standard-form-row.accountImage input[name=avatar_action][checked]", false
1032 # Adding external authentication should redirect to the auth provider
1033 post user_account_path(user), :params => { :user => user.attributes.merge(:auth_provider => "openid", :auth_uid => "gmail.com") }
1034 assert_response :redirect
1035 assert_redirected_to auth_path(:provider => "openid", :openid_url => "https://www.google.com/accounts/o8/id", :origin => "/user/#{ERB::Util.u(user.display_name)}/account")
1037 # Changing name to one that exists should fail
1038 new_attributes = user.attributes.dup.merge(:display_name => create(:user).display_name)
1039 post user_account_path(user), :params => { :user => new_attributes }
1040 assert_response :success
1041 assert_template :account
1042 assert_select ".notice", false
1043 assert_select "div#errorExplanation"
1044 assert_select "form#accountForm > fieldset > div.standard-form-row > input.field_with_errors#user_display_name"
1046 # Changing name to one that exists should fail, regardless of case
1047 new_attributes = user.attributes.dup.merge(:display_name => create(:user).display_name.upcase)
1048 post user_account_path(user), :params => { :user => new_attributes }
1049 assert_response :success
1050 assert_template :account
1051 assert_select ".notice", false
1052 assert_select "div#errorExplanation"
1053 assert_select "form#accountForm > fieldset > div.standard-form-row > input.field_with_errors#user_display_name"
1055 # Changing name to one that doesn't exist should work
1056 new_attributes = user.attributes.dup.merge(:display_name => "new tester")
1057 post user_account_path(user), :params => { :user => new_attributes }
1058 assert_response :redirect
1059 assert_redirected_to user_account_url(:display_name => "new tester")
1060 get user_account_path(:display_name => "new tester")
1061 assert_response :success
1062 assert_template :account
1063 assert_select "div#errorExplanation", false
1064 assert_select ".notice", /^User information updated successfully/
1065 assert_select "form#accountForm > fieldset > div.standard-form-row > input#user_display_name[value=?]", "new tester"
1067 # Record the change of name
1068 user.display_name = "new tester"
1070 # Changing email to one that exists should fail
1071 user.new_email = create(:user).email
1072 assert_no_difference "ActionMailer::Base.deliveries.size" do
1073 perform_enqueued_jobs do
1074 post user_account_path(user), :params => { :user => user.attributes }
1077 assert_response :success
1078 assert_template :account
1079 assert_select ".notice", false
1080 assert_select "div#errorExplanation"
1081 assert_select "form#accountForm > fieldset > div.standard-form-row > input.field_with_errors#user_new_email"
1083 # Changing email to one that exists should fail, regardless of case
1084 user.new_email = create(:user).email.upcase
1085 assert_no_difference "ActionMailer::Base.deliveries.size" do
1086 perform_enqueued_jobs do
1087 post user_account_path(user), :params => { :user => user.attributes }
1090 assert_response :success
1091 assert_template :account
1092 assert_select ".notice", false
1093 assert_select "div#errorExplanation"
1094 assert_select "form#accountForm > fieldset > div.standard-form-row > input.field_with_errors#user_new_email"
1096 # Changing email to one that doesn't exist should work
1097 user.new_email = "new_tester@example.com"
1098 assert_difference "ActionMailer::Base.deliveries.size", 1 do
1099 perform_enqueued_jobs do
1100 post user_account_path(user), :params => { :user => user.attributes }
1103 assert_response :redirect
1104 assert_redirected_to user_account_url(user)
1105 get user_account_path(user)
1106 assert_response :success
1107 assert_template :account
1108 assert_select "div#errorExplanation", false
1109 assert_select ".notice", /^User information updated successfully/
1110 assert_select "form#accountForm > fieldset > div.standard-form-row > input#user_new_email[value=?]", user.new_email
1111 email = ActionMailer::Base.deliveries.first
1112 assert_equal 1, email.to.count
1113 assert_equal user.new_email, email.to.first
1114 ActionMailer::Base.deliveries.clear
1117 # Check that the user account page will display and contains some relevant
1118 # information for the user
1120 # Test a non-existent user
1121 get user_path(:display_name => "unknown")
1122 assert_response :not_found
1124 # Test a normal user
1125 user = create(:user, :home_lon => 1.1, :home_lat => 1.1)
1126 friend_user = create(:user, :home_lon => 1.2, :home_lat => 1.2)
1127 create(:friendship, :befriender => user, :befriendee => friend_user)
1128 create(:changeset, :user => friend_user)
1131 assert_response :success
1132 assert_select "div#userinformation" do
1133 assert_select "a[href^='/user/#{ERB::Util.u(user.display_name)}/history']", 1
1134 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/traces']", 1
1135 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary']", 1
1136 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary/comments']", 1
1137 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/account']", 0
1138 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks']", 0
1139 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks_by']", 0
1140 assert_select "a[href='/blocks/new/#{ERB::Util.u(user.display_name)}']", 0
1143 # Friends shouldn't be visible as we're not logged in
1144 assert_select "div#friends-container", :count => 0
1146 # Test a user who has been blocked
1147 blocked_user = create(:user)
1148 create(:user_block, :user => blocked_user)
1149 get user_path(blocked_user)
1150 assert_response :success
1151 assert_select "div#userinformation" do
1152 assert_select "a[href^='/user/#{ERB::Util.u(blocked_user.display_name)}/history']", 1
1153 assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/traces']", 1
1154 assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/diary']", 1
1155 assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/diary/comments']", 1
1156 assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/account']", 0
1157 assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/blocks']", 1
1158 assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/blocks_by']", 0
1159 assert_select "a[href='/blocks/new/#{ERB::Util.u(blocked_user.display_name)}']", 0
1162 # Test a moderator who has applied blocks
1163 moderator_user = create(:moderator_user)
1164 create(:user_block, :creator => moderator_user)
1165 get user_path(moderator_user)
1166 assert_response :success
1167 assert_select "div#userinformation" do
1168 assert_select "a[href^='/user/#{ERB::Util.u(moderator_user.display_name)}/history']", 1
1169 assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/traces']", 1
1170 assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/diary']", 1
1171 assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/diary/comments']", 1
1172 assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/account']", 0
1173 assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/blocks']", 0
1174 assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/blocks_by']", 1
1175 assert_select "a[href='/blocks/new/#{ERB::Util.u(moderator_user.display_name)}']", 0
1178 # Login as a normal user
1181 # Test the normal user
1183 assert_response :success
1184 assert_select "div#userinformation" do
1185 assert_select "a[href^='/user/#{ERB::Util.u(user.display_name)}/history']", 1
1186 assert_select "a[href='/traces/mine']", 1
1187 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary']", 1
1188 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary/comments']", 1
1189 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/account']", 1
1190 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks']", 0
1191 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks_by']", 0
1192 assert_select "a[href='/blocks/new/#{ERB::Util.u(user.display_name)}']", 0
1195 # Friends should be visible as we're now logged in
1196 assert_select "div#friends-container" do
1197 assert_select "div.contact-activity", :count => 1
1200 # Login as a moderator
1201 session_for(create(:moderator_user))
1203 # Test the normal user
1205 assert_response :success
1206 assert_select "div#userinformation" do
1207 assert_select "a[href^='/user/#{ERB::Util.u(user.display_name)}/history']", 1
1208 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/traces']", 1
1209 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary']", 1
1210 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary/comments']", 1
1211 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/account']", 0
1212 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks']", 0
1213 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks_by']", 0
1214 assert_select "a[href='/blocks/new/#{ERB::Util.u(user.display_name)}']", 1
1218 # Test whether information about contributor terms is shown for users who haven't agreed
1219 def test_terms_not_agreed
1220 agreed_user = create(:user, :terms_agreed => 3.days.ago)
1221 seen_user = create(:user, :terms_seen => true, :terms_agreed => nil)
1222 not_seen_user = create(:user, :terms_seen => false, :terms_agreed => nil)
1224 get user_path(agreed_user)
1225 assert_response :success
1226 assert_select "div#userinformation" do
1227 assert_select "p", :count => 0, :text => /Contributor terms/
1230 get user_path(seen_user)
1231 assert_response :success
1232 # put @response.body
1233 assert_select "div#userinformation" do
1234 assert_select "p", :count => 1, :text => /Contributor terms/
1235 assert_select "p", /Declined/
1238 get user_path(not_seen_user)
1239 assert_response :success
1240 assert_select "div#userinformation" do
1241 assert_select "p", :count => 1, :text => /Contributor terms/
1242 assert_select "p", /Undecided/
1247 user = create(:user)
1249 # Try without logging in
1250 post set_status_user_path(user), :params => { :status => "suspended" }
1251 assert_response :forbidden
1253 # Now try as a normal user
1255 post set_status_user_path(user), :params => { :status => "suspended" }
1256 assert_response :redirect
1257 assert_redirected_to :controller => :errors, :action => :forbidden
1259 # Finally try as an administrator
1260 session_for(create(:administrator_user))
1261 post set_status_user_path(user), :params => { :status => "suspended" }
1262 assert_response :redirect
1263 assert_redirected_to :action => :show, :display_name => user.display_name
1264 assert_equal "suspended", User.find(user.id).status
1268 user = create(:user, :home_lat => 12.1, :home_lon => 12.1, :description => "test")
1270 # Try without logging in
1271 delete user_path(user), :params => { :status => "suspended" }
1272 assert_response :forbidden
1274 # Now try as a normal user
1276 delete user_path(user), :params => { :status => "suspended" }
1277 assert_response :redirect
1278 assert_redirected_to :controller => :errors, :action => :forbidden
1280 # Finally try as an administrator
1281 session_for(create(:administrator_user))
1282 delete user_path(user), :params => { :status => "suspended" }
1283 assert_response :redirect
1284 assert_redirected_to :action => :show, :display_name => user.display_name
1286 # Check that the user was deleted properly
1288 assert_equal "user_#{user.id}", user.display_name
1289 assert_equal "", user.description
1290 assert_nil user.home_lat
1291 assert_nil user.home_lon
1292 assert_not user.avatar.attached?
1293 assert_not user.email_valid
1294 assert_nil user.new_email
1295 assert_nil user.auth_provider
1296 assert_nil user.auth_uid
1297 assert_equal "deleted", user.status
1301 user = create(:user)
1302 moderator_user = create(:moderator_user)
1303 administrator_user = create(:administrator_user)
1304 _suspended_user = create(:user, :suspended)
1305 _ip_user = create(:user, :creation_ip => "1.2.3.4")
1307 # There are now 7 users - the five above, plus two extra "granters" for the
1308 # moderator_user and administrator_user
1309 assert_equal 7, User.count
1311 # Shouldn't work when not logged in
1313 assert_response :redirect
1314 assert_redirected_to :action => :login, :referer => users_path
1318 # Shouldn't work when logged in as a normal user
1320 assert_response :redirect
1321 assert_redirected_to :controller => :errors, :action => :forbidden
1323 session_for(moderator_user)
1325 # Shouldn't work when logged in as a moderator
1327 assert_response :redirect
1328 assert_redirected_to :controller => :errors, :action => :forbidden
1330 session_for(administrator_user)
1332 # Note there is a header row, so all row counts are users + 1
1333 # Should work when logged in as an administrator
1335 assert_response :success
1336 assert_template :index
1337 assert_select "table#user_list tr", :count => 7 + 1
1339 # Should be able to limit by status
1340 get users_path, :params => { :status => "suspended" }
1341 assert_response :success
1342 assert_template :index
1343 assert_select "table#user_list tr", :count => 1 + 1
1345 # Should be able to limit by IP address
1346 get users_path, :params => { :ip => "1.2.3.4" }
1347 assert_response :success
1348 assert_template :index
1349 assert_select "table#user_list tr", :count => 1 + 1
1352 def test_index_get_paginated
1353 1.upto(100).each do |n|
1354 User.create(:display_name => "extra_#{n}",
1355 :email => "extra#{n}@example.com",
1356 :pass_crypt => "extraextra")
1359 session_for(create(:administrator_user))
1361 # 100 examples, an administrator, and a granter for the admin.
1362 assert_equal 102, User.count
1365 assert_response :success
1366 assert_template :index
1367 assert_select "table#user_list tr", :count => 51
1369 get users_path, :params => { :page => 2 }
1370 assert_response :success
1371 assert_template :index
1372 assert_select "table#user_list tr", :count => 51
1374 get users_path, :params => { :page => 3 }
1375 assert_response :success
1376 assert_template :index
1377 assert_select "table#user_list tr", :count => 3
1380 def test_index_post_confirm
1381 inactive_user = create(:user, :pending)
1382 suspended_user = create(:user, :suspended)
1384 # Shouldn't work when not logged in
1385 assert_no_difference "User.active.count" do
1386 post users_path, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } }
1388 assert_response :forbidden
1390 assert_equal "pending", inactive_user.reload.status
1391 assert_equal "suspended", suspended_user.reload.status
1393 session_for(create(:user))
1395 # Shouldn't work when logged in as a normal user
1396 assert_no_difference "User.active.count" do
1397 post users_path, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } }
1399 assert_response :redirect
1400 assert_redirected_to :controller => :errors, :action => :forbidden
1401 assert_equal "pending", inactive_user.reload.status
1402 assert_equal "suspended", suspended_user.reload.status
1404 session_for(create(:moderator_user))
1406 # Shouldn't work when logged in as a moderator
1407 assert_no_difference "User.active.count" do
1408 post users_path, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } }
1410 assert_response :redirect
1411 assert_redirected_to :controller => :errors, :action => :forbidden
1412 assert_equal "pending", inactive_user.reload.status
1413 assert_equal "suspended", suspended_user.reload.status
1415 session_for(create(:administrator_user))
1417 # Should work when logged in as an administrator
1418 assert_difference "User.active.count", 2 do
1419 post users_path, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } }
1421 assert_response :redirect
1422 assert_redirected_to :action => :index
1423 assert_equal "confirmed", inactive_user.reload.status
1424 assert_equal "confirmed", suspended_user.reload.status
1427 def test_index_post_hide
1428 normal_user = create(:user)
1429 confirmed_user = create(:user, :confirmed)
1431 # Shouldn't work when not logged in
1432 assert_no_difference "User.active.count" do
1433 post users_path, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } }
1435 assert_response :forbidden
1437 assert_equal "active", normal_user.reload.status
1438 assert_equal "confirmed", confirmed_user.reload.status
1440 session_for(create(:user))
1442 # Shouldn't work when logged in as a normal user
1443 assert_no_difference "User.active.count" do
1444 post users_path, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } }
1446 assert_response :redirect
1447 assert_redirected_to :controller => :errors, :action => :forbidden
1448 assert_equal "active", normal_user.reload.status
1449 assert_equal "confirmed", confirmed_user.reload.status
1451 session_for(create(:moderator_user))
1453 # Shouldn't work when logged in as a moderator
1454 assert_no_difference "User.active.count" do
1455 post users_path, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } }
1457 assert_response :redirect
1458 assert_redirected_to :controller => :errors, :action => :forbidden
1459 assert_equal "active", normal_user.reload.status
1460 assert_equal "confirmed", confirmed_user.reload.status
1462 session_for(create(:administrator_user))
1464 # Should work when logged in as an administrator
1465 assert_difference "User.active.count", -2 do
1466 post users_path, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } }
1468 assert_response :redirect
1469 assert_redirected_to :action => :index
1470 assert_equal "deleted", normal_user.reload.status
1471 assert_equal "deleted", confirmed_user.reload.status