3 class UsersControllerTest < ActionDispatch::IntegrationTest
5 # test all routes which lead to this controller
8 { :path => "/login", :method => :get },
9 { :controller => "sessions", :action => "new" }
12 { :path => "/login", :method => :post },
13 { :controller => "sessions", :action => "create" }
16 { :controller => "sessions", :action => "new", :format => "html" },
17 { :path => "/login.html", :method => :get }
21 { :path => "/logout", :method => :get },
22 { :controller => "sessions", :action => "destroy" }
25 { :path => "/logout", :method => :post },
26 { :controller => "sessions", :action => "destroy" }
29 { :controller => "sessions", :action => "destroy", :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
413 assert_response :redirect
414 assert_redirected_to login_path(:cookie_test => true)
416 assert_response :success
417 assert_template "sessions/new"
419 get login_path, :params => { :username => user.display_name, :password => "test" }
420 assert_response :success
421 assert_template "sessions/new"
423 post login_path, :params => { :username => user.display_name, :password => "test" }
424 assert_response :redirect
425 assert_redirected_to root_path
428 def test_logout_without_referer
430 assert_response :redirect
431 assert_redirected_to root_path
434 def test_logout_with_referer
435 post logout_path, :params => { :referer => "/test" }
436 assert_response :redirect
437 assert_redirected_to "/test"
440 def test_logout_fallback_without_referer
442 assert_response :success
443 assert_template "sessions/destroy"
444 assert_select "input[name=referer]:not([value])"
447 def test_logout_fallback_with_referer
448 get logout_path, :params => { :referer => "/test" }
449 assert_response :success
450 assert_template "sessions/destroy"
451 assert_select "input[name=referer][value=?]", "/test"
454 def test_logout_removes_session_token
455 user = build(:user, :pending)
456 post user_new_path, :params => { :user => user.attributes }
457 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
459 assert_difference "User.find_by(:email => user.email).tokens.count", -1 do
462 assert_response :redirect
463 assert_redirected_to root_path
467 user = build(:user, :pending)
468 post user_new_path, :params => { :user => user.attributes }
469 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
470 confirm_string = User.find_by(:email => user.email).tokens.create.token
472 get user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
473 assert_response :success
474 assert_template :confirm
477 def test_confirm_get_already_confirmed
478 user = build(:user, :pending)
479 stub_gravatar_request(user.email)
480 post user_new_path, :params => { :user => user.attributes }
481 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
482 confirm_string = User.find_by(:email => user.email).tokens.create.token
484 # Get the confirmation page
485 get user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
486 assert_response :success
487 assert_template :confirm
490 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
491 assert_redirected_to welcome_path
493 # Now try to get the confirmation page again
494 get user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
495 assert_response :redirect
496 assert_redirected_to root_path
499 def test_confirm_success_no_token_no_referer
500 user = build(:user, :pending)
501 stub_gravatar_request(user.email)
502 post user_new_path, :params => { :user => user.attributes }
503 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
504 confirm_string = User.find_by(:email => user.email).tokens.create.token
508 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
509 assert_redirected_to login_path
510 assert_match(/Confirmed your account/, flash[:notice])
513 def test_confirm_success_good_token_no_referer
514 user = build(:user, :pending)
515 stub_gravatar_request(user.email)
516 post user_new_path, :params => { :user => user.attributes }
517 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
518 confirm_string = User.find_by(:email => user.email).tokens.create.token
520 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
521 assert_redirected_to welcome_path
524 def test_confirm_success_bad_token_no_referer
525 user = build(:user, :pending)
526 stub_gravatar_request(user.email)
527 post user_new_path, :params => { :user => user.attributes }
528 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
529 confirm_string = User.find_by(:email => user.email).tokens.create.token
532 session_for(create(:user))
534 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
535 assert_redirected_to login_path
536 assert_match(/Confirmed your account/, flash[:notice])
539 def test_confirm_success_no_token_with_referer
540 user = build(:user, :pending)
541 stub_gravatar_request(user.email)
542 post user_new_path, :params => { :user => user.attributes }
543 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
544 confirm_string = User.find_by(:email => user.email).tokens.create(:referer => new_diary_entry_path).token
548 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
549 assert_redirected_to login_path(:referer => new_diary_entry_path)
550 assert_match(/Confirmed your account/, flash[:notice])
553 def test_confirm_success_good_token_with_referer
554 user = build(:user, :pending)
555 stub_gravatar_request(user.email)
556 post user_new_path, :params => { :user => user.attributes }
557 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
558 confirm_string = User.find_by(:email => user.email).tokens.create(:referer => new_diary_entry_path).token
560 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
561 assert_redirected_to new_diary_entry_path
564 def test_confirm_success_bad_token_with_referer
565 user = build(:user, :pending)
566 stub_gravatar_request(user.email)
567 post user_new_path, :params => { :user => user.attributes }
568 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
569 confirm_string = User.find_by(:email => user.email).tokens.create(:referer => new_diary_entry_path).token
572 session_for(create(:user))
574 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
575 assert_redirected_to login_path(:referer => new_diary_entry_path)
576 assert_match(/Confirmed your account/, flash[:notice])
579 def test_confirm_expired_token
580 user = build(:user, :pending)
581 stub_gravatar_request(user.email)
582 post user_new_path, :params => { :user => user.attributes }
583 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
584 confirm_string = User.find_by(:email => user.email).tokens.create(:expiry => 1.day.ago).token
586 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
587 assert_redirected_to :action => "confirm"
588 assert_match(/confirmation code has expired/, flash[:error])
591 def test_confirm_already_confirmed
592 user = build(:user, :pending)
593 stub_gravatar_request(user.email)
594 post user_new_path, :params => { :user => user.attributes }
595 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
596 confirm_string = User.find_by(:email => user.email).tokens.create(:referer => new_diary_entry_path).token
598 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
599 assert_redirected_to new_diary_entry_path
603 confirm_string = User.find_by(:email => user.email).tokens.create(:referer => new_diary_entry_path).token
604 post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string }
605 assert_redirected_to login_path
606 assert_match(/already been confirmed/, flash[:error])
609 def test_confirm_resend_success
610 user = build(:user, :pending)
611 post user_new_path, :params => { :user => user.attributes }
612 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
614 assert_difference "ActionMailer::Base.deliveries.size", 1 do
615 perform_enqueued_jobs do
616 get user_confirm_resend_path(user)
620 assert_response :redirect
621 assert_redirected_to login_path
622 assert_match(/sent a new confirmation/, flash[:notice])
624 email = ActionMailer::Base.deliveries.last
626 assert_equal user.email, email.to.first
628 ActionMailer::Base.deliveries.clear
631 def test_confirm_resend_no_token
632 user = build(:user, :pending)
633 # only complete first half of registration
634 post user_new_path, :params => { :user => user.attributes }
636 assert_no_difference "ActionMailer::Base.deliveries.size" do
637 perform_enqueued_jobs do
638 get user_confirm_resend_path(user)
642 assert_response :redirect
643 assert_redirected_to login_path
644 assert_match "User #{user.display_name} not found.", flash[:error]
647 def test_confirm_resend_unknown_user
648 assert_no_difference "ActionMailer::Base.deliveries.size" do
649 perform_enqueued_jobs do
650 get user_confirm_resend_path(:display_name => "No Such User")
654 assert_response :redirect
655 assert_redirected_to login_path
656 assert_match "User No Such User not found.", flash[:error]
659 def test_confirm_email_get
661 confirm_string = user.tokens.create.token
663 get user_confirm_email_path, :params => { :confirm_string => confirm_string }
664 assert_response :success
665 assert_template :confirm_email
668 def test_confirm_email_success
669 user = create(:user, :new_email => "test-new@example.com")
670 stub_gravatar_request(user.new_email)
671 confirm_string = user.tokens.create.token
673 post user_confirm_email_path, :params => { :confirm_string => confirm_string }
674 assert_response :redirect
675 assert_redirected_to :action => :account, :display_name => user.display_name
676 assert_match(/Confirmed your change of email address/, flash[:notice])
679 def test_confirm_email_already_confirmed
681 confirm_string = user.tokens.create.token
683 post user_confirm_email_path, :params => { :confirm_string => confirm_string }
684 assert_response :redirect
685 assert_redirected_to :action => :account, :display_name => user.display_name
686 assert_match(/already been confirmed/, flash[:error])
689 def test_confirm_email_bad_token
690 post user_confirm_email_path, :params => { :confirm_string => "XXXXX" }
691 assert_response :success
692 assert_template :confirm_email
693 assert_match(/confirmation code has expired or does not exist/, flash[:error])
697 # test if testing for a gravatar works
698 # this happens when the email is actually changed
699 # which is triggered by the confirmation mail
700 def test_gravatar_auto_enable
701 # switch to email that has a gravatar
702 user = create(:user, :new_email => "test-new@example.com")
703 stub_gravatar_request(user.new_email, 200)
704 confirm_string = user.tokens.create.token
705 # precondition gravatar should be turned off
706 assert_not user.image_use_gravatar
707 post user_confirm_email_path, :params => { :confirm_string => confirm_string }
708 assert_response :redirect
709 assert_redirected_to :action => :account, :display_name => user.display_name
710 assert_match(/Confirmed your change of email address/, flash[:notice])
711 # gravatar use should now be enabled
712 assert User.find(user.id).image_use_gravatar
715 def test_gravatar_auto_disable
716 # switch to email without a gravatar
717 user = create(:user, :new_email => "test-new@example.com", :image_use_gravatar => true)
718 stub_gravatar_request(user.new_email, 404)
719 confirm_string = user.tokens.create.token
720 # precondition gravatar should be turned on
721 assert user.image_use_gravatar
722 post user_confirm_email_path, :params => { :confirm_string => confirm_string }
723 assert_response :redirect
724 assert_redirected_to :action => :account, :display_name => user.display_name
725 assert_match(/Confirmed your change of email address/, flash[:notice])
726 # gravatar use should now be disabled
727 assert_not User.find(user.id).image_use_gravatar
730 def test_terms_new_user
731 user = build(:user, :pending)
733 # Set up our user as being half-way through registration
734 assert_no_difference "User.count" do
735 assert_no_difference "ActionMailer::Base.deliveries.size" do
736 perform_enqueued_jobs do
737 post user_new_path, :params => { :user => user.attributes }
744 assert_response :success
745 assert_template :terms
748 def test_terms_agreed
749 user = create(:user, :terms_seen => true, :terms_agreed => Date.yesterday)
754 assert_response :redirect
755 assert_redirected_to :action => :account, :display_name => user.display_name
758 def test_terms_not_seen_without_referer
759 user = create(:user, :terms_seen => false, :terms_agreed => nil)
764 assert_response :success
765 assert_template :terms
767 post user_save_path, :params => { :user => { :consider_pd => true }, :read_ct => 1, :read_tou => 1 }
768 assert_response :redirect
769 assert_redirected_to :action => :account, :display_name => user.display_name
770 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
774 assert user.consider_pd
775 assert_not_nil user.terms_agreed
776 assert user.terms_seen
779 def test_terms_not_seen_with_referer
780 user = create(:user, :terms_seen => false, :terms_agreed => nil)
784 get user_terms_path, :params => { :referer => "/test" }
785 assert_response :success
786 assert_template :terms
788 post user_save_path, :params => { :user => { :consider_pd => true }, :referer => "/test", :read_ct => 1, :read_tou => 1 }
789 assert_response :redirect
790 assert_redirected_to "/test"
791 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
795 assert user.consider_pd
796 assert_not_nil user.terms_agreed
797 assert user.terms_seen
800 # Check that if you haven't seen the terms, and make a request that requires authentication,
801 # that your request is redirected to view the terms
802 def test_terms_not_seen_redirection
803 user = create(:user, :terms_seen => false, :terms_agreed => nil)
806 get user_account_path(user)
807 assert_response :redirect
808 assert_redirected_to :action => :terms, :referer => "/user/#{ERB::Util.u(user.display_name)}/account"
812 user = create(:user, :data_public => false)
815 post user_go_public_path
817 assert_response :redirect
818 assert_redirected_to :action => :account, :display_name => user.display_name
819 assert User.find(user.id).data_public
822 def test_lost_password
823 # Test fetching the lost password page
824 get user_forgot_password_path
825 assert_response :success
826 assert_template :lost_password
827 assert_select "div#notice", false
829 # Test resetting using the address as recorded for a user that has an
830 # address which is duplicated in a different case by another user
832 uppercase_user = build(:user, :email => user.email.upcase).tap { |u| u.save(:validate => false) }
834 # Resetting with GET should fail
835 assert_no_difference "ActionMailer::Base.deliveries.size" do
836 perform_enqueued_jobs do
837 get user_forgot_password_path, :params => { :email => user.email }
840 assert_response :success
841 assert_template :lost_password
843 # Resetting with POST should work
844 assert_difference "ActionMailer::Base.deliveries.size", 1 do
845 perform_enqueued_jobs do
846 post user_forgot_password_path, :params => { :email => user.email }
849 assert_response :redirect
850 assert_redirected_to login_path
851 assert_match(/^Sorry you lost it/, flash[:notice])
852 email = ActionMailer::Base.deliveries.first
853 assert_equal 1, email.to.count
854 assert_equal user.email, email.to.first
855 ActionMailer::Base.deliveries.clear
857 # Test resetting using an address that matches a different user
858 # that has the same address in a different case
859 assert_difference "ActionMailer::Base.deliveries.size", 1 do
860 perform_enqueued_jobs do
861 post user_forgot_password_path, :params => { :email => user.email.upcase }
864 assert_response :redirect
865 assert_redirected_to login_path
866 assert_match(/^Sorry you lost it/, flash[:notice])
867 email = ActionMailer::Base.deliveries.first
868 assert_equal 1, email.to.count
869 assert_equal uppercase_user.email, email.to.first
870 ActionMailer::Base.deliveries.clear
872 # Test resetting using an address that is a case insensitive match
873 # for more than one user but not an exact match for either
874 assert_no_difference "ActionMailer::Base.deliveries.size" do
875 perform_enqueued_jobs do
876 post user_forgot_password_path, :params => { :email => user.email.titlecase }
879 assert_response :success
880 assert_template :lost_password
881 assert_select ".error", /^Could not find that email address/
883 # Test resetting using the address as recorded for a user that has an
884 # address which is case insensitively unique
885 third_user = create(:user)
886 assert_difference "ActionMailer::Base.deliveries.size", 1 do
887 perform_enqueued_jobs do
888 post user_forgot_password_path, :params => { :email => third_user.email }
891 assert_response :redirect
892 assert_redirected_to login_path
893 assert_match(/^Sorry you lost it/, flash[:notice])
894 email = ActionMailer::Base.deliveries.first
895 assert_equal 1, email.to.count
896 assert_equal third_user.email, email.to.first
897 ActionMailer::Base.deliveries.clear
899 # Test resetting using an address that matches a user that has the
900 # same (case insensitively unique) address in a different case
901 assert_difference "ActionMailer::Base.deliveries.size", 1 do
902 perform_enqueued_jobs do
903 post user_forgot_password_path, :params => { :email => third_user.email.upcase }
906 assert_response :redirect
907 assert_redirected_to login_path
908 assert_match(/^Sorry you lost it/, flash[:notice])
909 email = ActionMailer::Base.deliveries.first
910 assert_equal 1, email.to.count
911 assert_equal third_user.email, email.to.first
912 ActionMailer::Base.deliveries.clear
915 def test_reset_password
916 user = create(:user, :pending)
917 # Test a request with no token
918 get user_reset_password_path
919 assert_response :bad_request
921 # Test a request with a bogus token
922 get user_reset_password_path, :params => { :token => "made_up_token" }
923 assert_response :redirect
924 assert_redirected_to :action => :lost_password
926 # Create a valid token for a user
927 token = user.tokens.create
929 # Test a request with a valid token
930 get user_reset_password_path, :params => { :token => token.token }
931 assert_response :success
932 assert_template :reset_password
934 # Test that errors are reported for erroneous submissions
935 post user_reset_password_path, :params => { :token => token.token, :user => { :pass_crypt => "new_password", :pass_crypt_confirmation => "different_password" } }
936 assert_response :success
937 assert_template :reset_password
938 assert_select "div.invalid-feedback"
940 # Test setting a new password
941 post user_reset_password_path, :params => { :token => token.token, :user => { :pass_crypt => "new_password", :pass_crypt_confirmation => "new_password" } }
942 assert_response :redirect
943 assert_redirected_to root_path
944 assert_equal user.id, session[:user]
946 assert_equal "active", user.status
947 assert user.email_valid
948 assert_equal user, User.authenticate(:username => user.email, :password => "new_password")
952 # Get a user to work with - note that this user deliberately
953 # conflicts with uppercase_user in the email and display name
954 # fields to test that we can change other fields without any
955 # validation errors being reported
956 user = create(:user, :languages => [])
957 _uppercase_user = build(:user, :email => user.email.upcase, :display_name => user.display_name.upcase).tap { |u| u.save(:validate => false) }
959 # Make sure that you are redirected to the login page when
960 # you are not logged in
961 get user_account_path(user)
962 assert_response :redirect
963 assert_redirected_to login_path(:referer => "/user/#{ERB::Util.u(user.display_name)}/account")
965 # Make sure that you are blocked when not logged in as the right user
966 session_for(create(:user))
967 get user_account_path(user)
968 assert_response :forbidden
970 # Make sure we get the page when we are logged in as the right user
972 get user_account_path(user)
973 assert_response :success
974 assert_template :account
975 assert_select "form#accountForm" do |form|
976 assert_equal "post", form.attr("method").to_s
977 assert_select "input[name='_method']", false
978 assert_equal "/user/#{ERB::Util.u(user.display_name)}/account", form.attr("action").to_s
981 # Updating the description using GET should fail
982 user.description = "new description"
983 user.preferred_editor = "default"
984 get user_account_path(user), :params => { :user => user.attributes }
985 assert_response :success
986 assert_template :account
987 assert_not_equal user.description, User.find(user.id).description
989 # Updating the description should work
990 user.description = "new description"
991 user.preferred_editor = "default"
992 post user_account_path(user), :params => { :user => user.attributes }
993 assert_response :redirect
994 assert_redirected_to user_account_url(user)
995 get user_account_path(user)
996 assert_response :success
997 assert_template :account
998 assert_select ".notice", /^User information updated successfully/
999 assert_select "form#accountForm > div.form-group > div#user_description_container > div#user_description_content > textarea#user_description", user.description
1001 # Changing to a invalid editor should fail
1002 user.preferred_editor = "unknown"
1003 post user_account_path(user), :params => { :user => user.attributes }
1004 assert_response :success
1005 assert_template :account
1006 assert_select ".notice", false
1007 assert_select "form#accountForm > div.form-group > select#user_preferred_editor > option[selected]", false
1009 # Changing to a valid editor should work
1010 user.preferred_editor = "id"
1011 post user_account_path(user), :params => { :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 ".notice", /^User information updated successfully/
1018 assert_select "form#accountForm > div.form-group > select#user_preferred_editor > option[selected][value=?]", "id"
1020 # Changing to the default editor should work
1021 user.preferred_editor = "default"
1022 post user_account_path(user), :params => { :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 ".notice", /^User information updated successfully/
1029 assert_select "form#accountForm > div.form-group > select#user_preferred_editor > option[selected]", false
1031 # Changing to an uploaded image should work
1032 image = Rack::Test::UploadedFile.new("test/gpx/fixtures/a.gif", "image/gif")
1033 post user_account_path(user), :params => { :avatar_action => "new", :user => user.attributes.merge(:avatar => image) }
1034 assert_response :redirect
1035 assert_redirected_to user_account_url(user)
1036 get user_account_path(user)
1037 assert_response :success
1038 assert_template :account
1039 assert_select ".notice", /^User information updated successfully/
1040 assert_select "form#accountForm > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-check > input[name=avatar_action][checked][value=?]", "keep"
1042 # Changing to a gravatar image should work
1043 post user_account_path(user), :params => { :avatar_action => "gravatar", :user => user.attributes }
1044 assert_response :redirect
1045 assert_redirected_to user_account_url(user)
1046 get user_account_path(user)
1047 assert_response :success
1048 assert_template :account
1049 assert_select ".notice", /^User information updated successfully/
1050 assert_select "form#accountForm > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-group > div.form-check > input[name=avatar_action][checked][value=?]", "gravatar"
1052 # Removing the image should work
1053 post user_account_path(user), :params => { :avatar_action => "delete", :user => user.attributes }
1054 assert_response :redirect
1055 assert_redirected_to user_account_url(user)
1056 get user_account_path(user)
1057 assert_response :success
1058 assert_template :account
1059 assert_select ".notice", /^User information updated successfully/
1060 assert_select "form#accountForm > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-check > input[name=avatar_action][checked]", false
1061 assert_select "form#accountForm > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-group > div.form-check > input[name=avatar_action][checked]", false
1063 # Adding external authentication should redirect to the auth provider
1064 post user_account_path(user), :params => { :user => user.attributes.merge(:auth_provider => "openid", :auth_uid => "gmail.com") }
1065 assert_response :redirect
1066 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")
1068 # Changing name to one that exists should fail
1069 new_attributes = user.attributes.dup.merge(:display_name => create(:user).display_name)
1070 post user_account_path(user), :params => { :user => new_attributes }
1071 assert_response :success
1072 assert_template :account
1073 assert_select ".notice", false
1074 assert_select "form#accountForm > div.form-group > input.is-invalid#user_display_name"
1076 # Changing name to one that exists should fail, regardless of case
1077 new_attributes = user.attributes.dup.merge(:display_name => create(:user).display_name.upcase)
1078 post user_account_path(user), :params => { :user => new_attributes }
1079 assert_response :success
1080 assert_template :account
1081 assert_select ".notice", false
1082 assert_select "form#accountForm > div.form-group > input.is-invalid#user_display_name"
1084 # Changing name to one that doesn't exist should work
1085 new_attributes = user.attributes.dup.merge(:display_name => "new tester")
1086 post user_account_path(user), :params => { :user => new_attributes }
1087 assert_response :redirect
1088 assert_redirected_to user_account_url(:display_name => "new tester")
1089 get user_account_path(:display_name => "new tester")
1090 assert_response :success
1091 assert_template :account
1092 assert_select ".notice", /^User information updated successfully/
1093 assert_select "form#accountForm > div.form-group > input#user_display_name[value=?]", "new tester"
1095 # Record the change of name
1096 user.display_name = "new tester"
1098 # Changing email to one that exists should fail
1099 user.new_email = create(:user).email
1100 assert_no_difference "ActionMailer::Base.deliveries.size" do
1101 perform_enqueued_jobs do
1102 post user_account_path(user), :params => { :user => user.attributes }
1105 assert_response :success
1106 assert_template :account
1107 assert_select ".notice", false
1108 assert_select "form#accountForm > div.form-group > input.is-invalid#user_new_email"
1110 # Changing email to one that exists should fail, regardless of case
1111 user.new_email = create(:user).email.upcase
1112 assert_no_difference "ActionMailer::Base.deliveries.size" do
1113 perform_enqueued_jobs do
1114 post user_account_path(user), :params => { :user => user.attributes }
1117 assert_response :success
1118 assert_template :account
1119 assert_select ".notice", false
1120 assert_select "form#accountForm > div.form-group > input.is-invalid#user_new_email"
1122 # Changing email to one that doesn't exist should work
1123 user.new_email = "new_tester@example.com"
1124 assert_difference "ActionMailer::Base.deliveries.size", 1 do
1125 perform_enqueued_jobs do
1126 post user_account_path(user), :params => { :user => user.attributes }
1129 assert_response :redirect
1130 assert_redirected_to user_account_url(user)
1131 get user_account_path(user)
1132 assert_response :success
1133 assert_template :account
1134 assert_select ".notice", /^User information updated successfully/
1135 assert_select "form#accountForm > div.form-group > input#user_new_email[value=?]", user.new_email
1136 email = ActionMailer::Base.deliveries.first
1137 assert_equal 1, email.to.count
1138 assert_equal user.new_email, email.to.first
1139 ActionMailer::Base.deliveries.clear
1142 # Check that the user account page will display and contains some relevant
1143 # information for the user
1145 # Test a non-existent user
1146 get user_path(:display_name => "unknown")
1147 assert_response :not_found
1149 # Test a normal user
1150 user = create(:user, :home_lon => 1.1, :home_lat => 1.1)
1151 friend_user = create(:user, :home_lon => 1.2, :home_lat => 1.2)
1152 create(:friendship, :befriender => user, :befriendee => friend_user)
1153 create(:changeset, :user => friend_user)
1156 assert_response :success
1157 assert_select "div#userinformation" do
1158 assert_select "a[href^='/user/#{ERB::Util.u(user.display_name)}/history']", 1
1159 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/traces']", 1
1160 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary']", 1
1161 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary/comments']", 1
1162 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/account']", 0
1163 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks']", 0
1164 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks_by']", 0
1165 assert_select "a[href='/blocks/new/#{ERB::Util.u(user.display_name)}']", 0
1168 # Friends shouldn't be visible as we're not logged in
1169 assert_select "div#friends-container", :count => 0
1171 # Test a user who has been blocked
1172 blocked_user = create(:user)
1173 create(:user_block, :user => blocked_user)
1174 get user_path(blocked_user)
1175 assert_response :success
1176 assert_select "div#userinformation" do
1177 assert_select "a[href^='/user/#{ERB::Util.u(blocked_user.display_name)}/history']", 1
1178 assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/traces']", 1
1179 assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/diary']", 1
1180 assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/diary/comments']", 1
1181 assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/account']", 0
1182 assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/blocks']", 1
1183 assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/blocks_by']", 0
1184 assert_select "a[href='/blocks/new/#{ERB::Util.u(blocked_user.display_name)}']", 0
1187 # Test a moderator who has applied blocks
1188 moderator_user = create(:moderator_user)
1189 create(:user_block, :creator => moderator_user)
1190 get user_path(moderator_user)
1191 assert_response :success
1192 assert_select "div#userinformation" do
1193 assert_select "a[href^='/user/#{ERB::Util.u(moderator_user.display_name)}/history']", 1
1194 assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/traces']", 1
1195 assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/diary']", 1
1196 assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/diary/comments']", 1
1197 assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/account']", 0
1198 assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/blocks']", 0
1199 assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/blocks_by']", 1
1200 assert_select "a[href='/blocks/new/#{ERB::Util.u(moderator_user.display_name)}']", 0
1203 # Login as a normal user
1206 # Test the normal user
1208 assert_response :success
1209 assert_select "div#userinformation" do
1210 assert_select "a[href^='/user/#{ERB::Util.u(user.display_name)}/history']", 1
1211 assert_select "a[href='/traces/mine']", 1
1212 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary']", 1
1213 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary/comments']", 1
1214 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/account']", 1
1215 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks']", 0
1216 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks_by']", 0
1217 assert_select "a[href='/blocks/new/#{ERB::Util.u(user.display_name)}']", 0
1220 # Friends should be visible as we're now logged in
1221 assert_select "div#friends-container" do
1222 assert_select "div.contact-activity", :count => 1
1225 # Login as a moderator
1226 session_for(create(:moderator_user))
1228 # Test the normal user
1230 assert_response :success
1231 assert_select "div#userinformation" do
1232 assert_select "a[href^='/user/#{ERB::Util.u(user.display_name)}/history']", 1
1233 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/traces']", 1
1234 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary']", 1
1235 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary/comments']", 1
1236 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/account']", 0
1237 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks']", 0
1238 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks_by']", 0
1239 assert_select "a[href='/blocks/new/#{ERB::Util.u(user.display_name)}']", 1
1243 # Test whether information about contributor terms is shown for users who haven't agreed
1244 def test_terms_not_agreed
1245 agreed_user = create(:user, :terms_agreed => 3.days.ago)
1246 seen_user = create(:user, :terms_seen => true, :terms_agreed => nil)
1247 not_seen_user = create(:user, :terms_seen => false, :terms_agreed => nil)
1249 get user_path(agreed_user)
1250 assert_response :success
1251 assert_select "div#userinformation" do
1252 assert_select "p", :count => 0, :text => /Contributor terms/
1255 get user_path(seen_user)
1256 assert_response :success
1257 # put @response.body
1258 assert_select "div#userinformation" do
1259 assert_select "p", :count => 1, :text => /Contributor terms/
1260 assert_select "p", /Declined/
1263 get user_path(not_seen_user)
1264 assert_response :success
1265 assert_select "div#userinformation" do
1266 assert_select "p", :count => 1, :text => /Contributor terms/
1267 assert_select "p", /Undecided/
1272 user = create(:user)
1274 # Try without logging in
1275 post set_status_user_path(user), :params => { :status => "suspended" }
1276 assert_response :forbidden
1278 # Now try as a normal user
1280 post set_status_user_path(user), :params => { :status => "suspended" }
1281 assert_response :redirect
1282 assert_redirected_to :controller => :errors, :action => :forbidden
1284 # Finally try as an administrator
1285 session_for(create(:administrator_user))
1286 post set_status_user_path(user), :params => { :status => "suspended" }
1287 assert_response :redirect
1288 assert_redirected_to :action => :show, :display_name => user.display_name
1289 assert_equal "suspended", User.find(user.id).status
1293 user = create(:user, :home_lat => 12.1, :home_lon => 12.1, :description => "test")
1295 # Try without logging in
1296 delete user_path(user), :params => { :status => "suspended" }
1297 assert_response :forbidden
1299 # Now try as a normal user
1301 delete user_path(user), :params => { :status => "suspended" }
1302 assert_response :redirect
1303 assert_redirected_to :controller => :errors, :action => :forbidden
1305 # Finally try as an administrator
1306 session_for(create(:administrator_user))
1307 delete user_path(user), :params => { :status => "suspended" }
1308 assert_response :redirect
1309 assert_redirected_to :action => :show, :display_name => user.display_name
1311 # Check that the user was deleted properly
1313 assert_equal "user_#{user.id}", user.display_name
1314 assert_equal "", user.description
1315 assert_nil user.home_lat
1316 assert_nil user.home_lon
1317 assert_not user.avatar.attached?
1318 assert_not user.email_valid
1319 assert_nil user.new_email
1320 assert_nil user.auth_provider
1321 assert_nil user.auth_uid
1322 assert_equal "deleted", user.status
1326 user = create(:user)
1327 moderator_user = create(:moderator_user)
1328 administrator_user = create(:administrator_user)
1329 _suspended_user = create(:user, :suspended)
1330 _ip_user = create(:user, :creation_ip => "1.2.3.4")
1332 # There are now 7 users - the five above, plus two extra "granters" for the
1333 # moderator_user and administrator_user
1334 assert_equal 7, User.count
1336 # Shouldn't work when not logged in
1338 assert_response :redirect
1339 assert_redirected_to login_path(:referer => users_path)
1343 # Shouldn't work when logged in as a normal user
1345 assert_response :redirect
1346 assert_redirected_to :controller => :errors, :action => :forbidden
1348 session_for(moderator_user)
1350 # Shouldn't work when logged in as a moderator
1352 assert_response :redirect
1353 assert_redirected_to :controller => :errors, :action => :forbidden
1355 session_for(administrator_user)
1357 # Note there is a header row, so all row counts are users + 1
1358 # Should work when logged in as an administrator
1360 assert_response :success
1361 assert_template :index
1362 assert_select "table#user_list tr", :count => 7 + 1
1364 # Should be able to limit by status
1365 get users_path, :params => { :status => "suspended" }
1366 assert_response :success
1367 assert_template :index
1368 assert_select "table#user_list tr", :count => 1 + 1
1370 # Should be able to limit by IP address
1371 get users_path, :params => { :ip => "1.2.3.4" }
1372 assert_response :success
1373 assert_template :index
1374 assert_select "table#user_list tr", :count => 1 + 1
1377 def test_index_get_paginated
1378 1.upto(100).each do |n|
1379 User.create(:display_name => "extra_#{n}",
1380 :email => "extra#{n}@example.com",
1381 :pass_crypt => "extraextra")
1384 session_for(create(:administrator_user))
1386 # 100 examples, an administrator, and a granter for the admin.
1387 assert_equal 102, User.count
1390 assert_response :success
1391 assert_template :index
1392 assert_select "table#user_list tr", :count => 51
1394 get users_path, :params => { :page => 2 }
1395 assert_response :success
1396 assert_template :index
1397 assert_select "table#user_list tr", :count => 51
1399 get users_path, :params => { :page => 3 }
1400 assert_response :success
1401 assert_template :index
1402 assert_select "table#user_list tr", :count => 3
1405 def test_index_post_confirm
1406 inactive_user = create(:user, :pending)
1407 suspended_user = create(:user, :suspended)
1409 # Shouldn't work when not logged in
1410 assert_no_difference "User.active.count" do
1411 post users_path, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } }
1413 assert_response :forbidden
1415 assert_equal "pending", inactive_user.reload.status
1416 assert_equal "suspended", suspended_user.reload.status
1418 session_for(create(:user))
1420 # Shouldn't work when logged in as a normal user
1421 assert_no_difference "User.active.count" do
1422 post users_path, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } }
1424 assert_response :redirect
1425 assert_redirected_to :controller => :errors, :action => :forbidden
1426 assert_equal "pending", inactive_user.reload.status
1427 assert_equal "suspended", suspended_user.reload.status
1429 session_for(create(:moderator_user))
1431 # Shouldn't work when logged in as a moderator
1432 assert_no_difference "User.active.count" do
1433 post users_path, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } }
1435 assert_response :redirect
1436 assert_redirected_to :controller => :errors, :action => :forbidden
1437 assert_equal "pending", inactive_user.reload.status
1438 assert_equal "suspended", suspended_user.reload.status
1440 session_for(create(:administrator_user))
1442 # Should work when logged in as an administrator
1443 assert_difference "User.active.count", 2 do
1444 post users_path, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } }
1446 assert_response :redirect
1447 assert_redirected_to :action => :index
1448 assert_equal "confirmed", inactive_user.reload.status
1449 assert_equal "confirmed", suspended_user.reload.status
1452 def test_index_post_hide
1453 normal_user = create(:user)
1454 confirmed_user = create(:user, :confirmed)
1456 # Shouldn't work when not logged in
1457 assert_no_difference "User.active.count" do
1458 post users_path, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } }
1460 assert_response :forbidden
1462 assert_equal "active", normal_user.reload.status
1463 assert_equal "confirmed", confirmed_user.reload.status
1465 session_for(create(:user))
1467 # Shouldn't work when logged in as a normal user
1468 assert_no_difference "User.active.count" do
1469 post users_path, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } }
1471 assert_response :redirect
1472 assert_redirected_to :controller => :errors, :action => :forbidden
1473 assert_equal "active", normal_user.reload.status
1474 assert_equal "confirmed", confirmed_user.reload.status
1476 session_for(create(:moderator_user))
1478 # Shouldn't work when logged in as a moderator
1479 assert_no_difference "User.active.count" do
1480 post users_path, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } }
1482 assert_response :redirect
1483 assert_redirected_to :controller => :errors, :action => :forbidden
1484 assert_equal "active", normal_user.reload.status
1485 assert_equal "confirmed", confirmed_user.reload.status
1487 session_for(create(:administrator_user))
1489 # Should work when logged in as an administrator
1490 assert_difference "User.active.count", -2 do
1491 post users_path, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } }
1493 assert_response :redirect
1494 assert_redirected_to :action => :index
1495 assert_equal "deleted", normal_user.reload.status
1496 assert_equal "deleted", confirmed_user.reload.status