3 class UserControllerTest < ActionController::TestCase
5 fixtures :messages, :friends
8 # test all routes which lead to this controller
11 { :path => "/api/0.6/user/1", :method => :get },
12 { :controller => "user", :action => "api_read", :id => "1" }
15 { :path => "/api/0.6/user/details", :method => :get },
16 { :controller => "user", :action => "api_details" }
19 { :path => "/api/0.6/user/gpx_files", :method => :get },
20 { :controller => "user", :action => "api_gpx_files" }
24 { :path => "/login", :method => :get },
25 { :controller => "user", :action => "login" }
28 { :path => "/login", :method => :post },
29 { :controller => "user", :action => "login" }
32 { :controller => "user", :action => "login", :format => "html" },
33 { :path => "/login.html", :method => :get }
37 { :path => "/logout", :method => :get },
38 { :controller => "user", :action => "logout" }
41 { :path => "/logout", :method => :post },
42 { :controller => "user", :action => "logout" }
45 { :controller => "user", :action => "logout", :format => "html" },
46 { :path => "/logout.html", :method => :get }
50 { :path => "/user/new", :method => :get },
51 { :controller => "user", :action => "new" }
55 { :path => "/user/new", :method => :post },
56 { :controller => "user", :action => "create" }
60 { :path => "/user/terms", :method => :get },
61 { :controller => "user", :action => "terms" }
65 { :path => "/user/save", :method => :post },
66 { :controller => "user", :action => "save" }
70 { :path => "/user/username/confirm", :method => :get },
71 { :controller => "user", :action => "confirm", :display_name => "username" }
74 { :path => "/user/username/confirm", :method => :post },
75 { :controller => "user", :action => "confirm", :display_name => "username" }
78 { :path => "/user/username/confirm/resend", :method => :get },
79 { :controller => "user", :action => "confirm_resend", :display_name => "username" }
83 { :path => "/user/confirm", :method => :get },
84 { :controller => "user", :action => "confirm" }
87 { :path => "/user/confirm", :method => :post },
88 { :controller => "user", :action => "confirm" }
91 { :path => "/user/confirm-email", :method => :get },
92 { :controller => "user", :action => "confirm_email" }
95 { :path => "/user/confirm-email", :method => :post },
96 { :controller => "user", :action => "confirm_email" }
100 { :path => "/user/go_public", :method => :post },
101 { :controller => "user", :action => "go_public" }
105 { :path => "/user/forgot-password", :method => :get },
106 { :controller => "user", :action => "lost_password" }
109 { :path => "/user/forgot-password", :method => :post },
110 { :controller => "user", :action => "lost_password" }
113 { :path => "/user/reset-password", :method => :get },
114 { :controller => "user", :action => "reset_password" }
117 { :path => "/user/reset-password", :method => :post },
118 { :controller => "user", :action => "reset_password" }
122 { :path => "/user/suspended", :method => :get },
123 { :controller => "user", :action => "suspended" }
127 { :path => "/user/username", :method => :get },
128 { :controller => "user", :action => "view", :display_name => "username" }
132 { :path => "/user/username/account", :method => :get },
133 { :controller => "user", :action => "account", :display_name => "username" }
136 { :path => "/user/username/account", :method => :post },
137 { :controller => "user", :action => "account", :display_name => "username" }
141 { :path => "/user/username/make_friend", :method => :get },
142 { :controller => "user", :action => "make_friend", :display_name => "username" }
145 { :path => "/user/username/make_friend", :method => :post },
146 { :controller => "user", :action => "make_friend", :display_name => "username" }
149 { :path => "/user/username/remove_friend", :method => :get },
150 { :controller => "user", :action => "remove_friend", :display_name => "username" }
153 { :path => "/user/username/remove_friend", :method => :post },
154 { :controller => "user", :action => "remove_friend", :display_name => "username" }
158 { :path => "/user/username/set_status", :method => :get },
159 { :controller => "user", :action => "set_status", :display_name => "username" }
162 { :path => "/user/username/delete", :method => :get },
163 { :controller => "user", :action => "delete", :display_name => "username" }
167 { :path => "/users", :method => :get },
168 { :controller => "user", :action => "list" }
171 { :path => "/users", :method => :post },
172 { :controller => "user", :action => "list" }
175 { :path => "/users/status", :method => :get },
176 { :controller => "user", :action => "list", :status => "status" }
179 { :path => "/users/status", :method => :post },
180 { :controller => "user", :action => "list", :status => "status" }
184 # The user creation page loads
187 assert_response :redirect
188 assert_redirected_to user_new_path(:cookie_test => "true")
190 get :new, { :cookie_test => "true" }, { :cookie_test => true }
191 assert_response :success
193 assert_select "html", :count => 1 do
194 assert_select "head", :count => 1 do
195 assert_select "title", :text => /Sign Up/, :count => 1
197 assert_select "body", :count => 1 do
198 assert_select "div#content", :count => 1 do
199 assert_select "form[action='/user/new'][method='post']", :count => 1 do
200 assert_select "input[id='user_email']", :count => 1
201 assert_select "input[id='user_email_confirmation']", :count => 1
202 assert_select "input[id='user_display_name']", :count => 1
203 assert_select "input[id='user_pass_crypt'][type='password']", :count => 1
204 assert_select "input[id='user_pass_crypt_confirmation'][type='password']", :count => 1
205 assert_select "input[type='submit'][value='Sign Up']", :count => 1
212 def test_new_view_logged_in
213 session[:user] = users(:normal_user).id
216 assert_response :redirect
217 assert_redirected_to user_new_path(:cookie_test => "true")
218 get :new, :cookie_test => "true"
219 assert_response :redirect
220 assert_redirected_to root_path
222 get :new, :referer => "/test"
223 assert_response :redirect
224 assert_redirected_to user_new_path(:referer => "/test", :cookie_test => "true")
225 get :new, :referer => "/test", :cookie_test => "true"
226 assert_response :redirect
227 assert_redirected_to "/test"
233 assert_difference "User.count", 1 do
234 assert_difference "ActionMailer::Base.deliveries.size", 1 do
235 post :save, {}, { :new_user => user }
240 register_email = ActionMailer::Base.deliveries.first
242 assert_equal register_email.to[0], user.email
243 assert_match /#{@url}/, register_email.body.to_s
246 assert_redirected_to :action => "confirm", :display_name => user.display_name
248 ActionMailer::Base.deliveries.clear
251 def test_new_duplicate_email
253 user.email = users(:public_user).email
255 assert_no_difference "User.count" do
256 assert_no_difference "ActionMailer::Base.deliveries.size" do
257 post :save, {}, { :new_user => user }
261 assert_response :success
262 assert_template "new"
263 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
266 def test_new_duplicate_email_uppercase
268 user.email = users(:public_user).email.upcase
270 assert_no_difference "User.count" do
271 assert_no_difference "ActionMailer::Base.deliveries.size" do
272 post :save, {}, { :new_user => user }
276 assert_response :success
277 assert_template "new"
278 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
281 def test_new_duplicate_name
283 user.display_name = users(:public_user).display_name
285 assert_no_difference "User.count" do
286 assert_no_difference "ActionMailer::Base.deliveries.size" do
287 post :save, {}, { :new_user => user }
291 assert_response :success
292 assert_template "new"
293 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
296 def test_new_duplicate_name_uppercase
298 user.display_name = users(:public_user).display_name.upcase
300 assert_no_difference "User.count" do
301 assert_no_difference "ActionMailer::Base.deliveries.size" do
302 post :save, {}, { :new_user => user }
306 assert_response :success
307 assert_template "new"
308 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
311 def test_save_referer_params
314 assert_difference "User.count", 1 do
315 assert_difference "ActionMailer::Base.deliveries.size", 1 do
316 post :save, {}, { :new_user => user,
317 :referer => "/edit?editor=id#map=1/2/3" }
321 assert_equal welcome_path(:editor => "id", :zoom => 1, :lat => 2, :lon => 3),
322 user.tokens.order("id DESC").first.referer
324 ActionMailer::Base.deliveries.clear
327 def test_logout_without_referer
329 assert_response :success
330 assert_template :logout
331 assert_select "input[name=referer][value=?]", ""
333 session_id = assert_select("input[name=session]").first["value"]
335 get :logout, :session => session_id
336 assert_response :redirect
337 assert_redirected_to root_path
340 def test_logout_with_referer
341 get :logout, :referer => "/test"
342 assert_response :success
343 assert_template :logout
344 assert_select "input[name=referer][value=?]", "/test"
346 session_id = assert_select("input[name=session]").first["value"]
348 get :logout, :session => session_id, :referer => "/test"
349 assert_response :redirect
350 assert_redirected_to "/test"
353 def test_logout_with_token
354 token = users(:normal_user).tokens.create
356 session[:token] = token.token
359 assert_response :success
360 assert_template :logout
361 assert_select "input[name=referer][value=?]", ""
362 assert_equal token.token, session[:token]
363 assert_not_nil UserToken.where(:id => token.id).first
365 session_id = assert_select("input[name=session]").first["value"]
367 get :logout, :session => session_id
368 assert_response :redirect
369 assert_redirected_to root_path
370 assert_nil session[:token]
371 assert_nil UserToken.where(:id => token.id).first
375 user = users(:inactive_user)
376 confirm_string = user.tokens.create.token
378 @request.cookies["_osm_session"] = user.display_name
379 get :confirm, :display_name => user.display_name, :confirm_string => confirm_string
380 assert_response :success
381 assert_template :confirm
384 def test_confirm_get_already_confirmed
385 user = users(:normal_user)
386 confirm_string = user.tokens.create.token
388 @request.cookies["_osm_session"] = user.display_name
389 get :confirm, :display_name => user.display_name, :confirm_string => confirm_string
390 assert_response :redirect
391 assert_redirected_to root_path
394 def test_confirm_success_no_token_no_referer
395 user = users(:inactive_user)
396 confirm_string = user.tokens.create.token
398 @request.cookies["_osm_session"] = user.display_name
399 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
400 assert_redirected_to login_path
401 assert_match /Confirmed your account/, flash[:notice]
404 def test_confirm_success_good_token_no_referer
405 user = users(:inactive_user)
406 confirm_string = user.tokens.create.token
407 token = user.tokens.create.token
409 @request.cookies["_osm_session"] = user.display_name
410 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
411 assert_redirected_to welcome_path
414 def test_confirm_success_bad_token_no_referer
415 user = users(:inactive_user)
416 confirm_string = user.tokens.create.token
417 token = users(:normal_user).tokens.create.token
419 @request.cookies["_osm_session"] = user.display_name
420 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
421 assert_redirected_to login_path
422 assert_match /Confirmed your account/, flash[:notice]
425 def test_confirm_success_no_token_with_referer
426 user = users(:inactive_user)
427 confirm_string = user.tokens.create(:referer => diary_new_path).token
429 @request.cookies["_osm_session"] = user.display_name
430 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
431 assert_redirected_to login_path(:referer => diary_new_path)
432 assert_match /Confirmed your account/, flash[:notice]
435 def test_confirm_success_good_token_with_referer
436 user = users(:inactive_user)
437 confirm_string = user.tokens.create(:referer => diary_new_path).token
438 token = user.tokens.create.token
440 @request.cookies["_osm_session"] = user.display_name
441 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
442 assert_redirected_to diary_new_path
445 def test_confirm_success_bad_token_with_referer
446 user = users(:inactive_user)
447 confirm_string = user.tokens.create(:referer => diary_new_path).token
448 token = users(:normal_user).tokens.create.token
450 @request.cookies["_osm_session"] = user.display_name
451 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
452 assert_redirected_to login_path(:referer => diary_new_path)
453 assert_match /Confirmed your account/, flash[:notice]
456 def test_confirm_expired_token
457 user = users(:inactive_user)
458 confirm_string = user.tokens.create(:expiry => 1.day.ago).token
460 @request.cookies["_osm_session"] = user.display_name
461 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
462 assert_redirected_to :action => "confirm"
463 assert_match /confirmation code has expired/, flash[:error]
466 def test_confirm_already_confirmed
467 user = users(:normal_user)
468 confirm_string = user.tokens.create(:referer => diary_new_path).token
470 @request.cookies["_osm_session"] = user.display_name
471 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
472 assert_redirected_to :action => "login"
473 assert_match /already been confirmed/, flash[:error]
476 def test_confirm_resend_success
477 session[:token] = users(:inactive_user).tokens.create.token
479 assert_difference "ActionMailer::Base.deliveries.size", 1 do
480 get :confirm_resend, :display_name => users(:inactive_user).display_name
483 assert_response :redirect
484 assert_redirected_to login_path
485 assert_match /sent a new confirmation/, flash[:notice]
487 email = ActionMailer::Base.deliveries.last
489 assert_equal users(:inactive_user).email, email.to.first
491 ActionMailer::Base.deliveries.clear
494 def test_confirm_resend_no_token
495 assert_no_difference "ActionMailer::Base.deliveries.size" do
496 get :confirm_resend, :display_name => users(:inactive_user).display_name
499 assert_response :redirect
500 assert_redirected_to login_path
501 assert_match "User Inactive User not found.", flash[:error]
504 def test_confirm_resend_unknown_user
505 assert_no_difference "ActionMailer::Base.deliveries.size" do
506 get :confirm_resend, :display_name => "No Such User"
509 assert_response :redirect
510 assert_redirected_to login_path
511 assert_match "User No Such User not found.", flash[:error]
514 def test_confirm_email_get
515 user = users(:normal_user)
516 confirm_string = user.tokens.create.token
518 get :confirm_email, :confirm_string => confirm_string
519 assert_response :success
520 assert_template :confirm_email
523 def test_confirm_email_success
524 user = users(:second_public_user)
525 confirm_string = user.tokens.create.token
527 post :confirm_email, :confirm_string => confirm_string
528 assert_response :redirect
529 assert_redirected_to :action => :account, :display_name => user.display_name
530 assert_match /Confirmed your change of email address/, flash[:notice]
533 def test_confirm_email_already_confirmed
534 user = users(:normal_user)
535 confirm_string = user.tokens.create.token
537 post :confirm_email, :confirm_string => confirm_string
538 assert_response :redirect
539 assert_redirected_to :action => :account, :display_name => user.display_name
540 assert_match /already been confirmed/, flash[:error]
543 def test_confirm_email_bad_token
544 post :confirm_email, :confirm_string => "XXXXX"
545 assert_response :success
546 assert_template :confirm_email
547 assert_match /confirmation code has expired or does not exist/, flash[:error]
551 # test if testing for a gravatar works
552 # this happens when the email is actually changed
553 # which is triggered by the confirmation mail
554 def test_gravatar_auto_enable
555 with_http_stubs "gravatar" do
556 # switch to email that has a gravatar
557 user = users(:first_gravatar_user)
558 confirm_string = user.tokens.create.token
559 # precondition gravatar should be turned off
560 assert !user.image_use_gravatar
561 post :confirm_email, :confirm_string => confirm_string
562 assert_response :redirect
563 assert_redirected_to :action => :account, :display_name => user.display_name
564 assert_match /Confirmed your change of email address/, flash[:notice]
565 # gravatar use should now be enabled
566 assert User.find(users(:first_gravatar_user).id).image_use_gravatar
570 def test_gravatar_auto_disable
571 with_http_stubs "gravatar" do
572 # switch to email without a gravatar
573 user = users(:second_gravatar_user)
574 confirm_string = user.tokens.create.token
575 # precondition gravatar should be turned on
576 assert user.image_use_gravatar
577 post :confirm_email, :confirm_string => confirm_string
578 assert_response :redirect
579 assert_redirected_to :action => :account, :display_name => user.display_name
580 assert_match /Confirmed your change of email address/, flash[:notice]
581 # gravatar use should now be disabled
582 assert !User.find(users(:second_gravatar_user).id).image_use_gravatar
586 def test_terms_new_user
587 get :terms, {}, { :new_user => User.new }
588 assert_response :success
589 assert_template :terms
593 user = users(:normal_user)
595 session[:user] = user.id
598 assert_response :redirect
599 assert_redirected_to :action => :account, :display_name => user.display_name
602 def test_terms_not_seen_without_referer
603 user = users(:terms_not_seen_user)
605 session[:user] = user.id
608 assert_response :success
609 assert_template :terms
611 post :save, :user => { :consider_pd => true }
612 assert_response :redirect
613 assert_redirected_to :action => :account, :display_name => user.display_name
614 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
618 assert_equal true, user.consider_pd
619 assert_not_nil user.terms_agreed
620 assert_equal true, user.terms_seen
623 def test_terms_not_seen_with_referer
624 user = users(:terms_not_seen_user)
626 session[:user] = user.id
628 get :terms, :referer => "/test"
629 assert_response :success
630 assert_template :terms
632 post :save, :user => { :consider_pd => true }, :referer => "/test"
633 assert_response :redirect
634 assert_redirected_to "/test"
635 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
639 assert_equal true, user.consider_pd
640 assert_not_nil user.terms_agreed
641 assert_equal true, user.terms_seen
645 post :go_public, {}, { :user => users(:normal_user) }
646 assert_response :redirect
647 assert_redirected_to :action => :account, :display_name => users(:normal_user).display_name
648 assert_equal true, User.find(users(:normal_user).id).data_public
651 def test_lost_password
652 # Test fetching the lost password page
654 assert_response :success
655 assert_template :lost_password
656 assert_select "div#notice", false
658 # Test resetting using the address as recorded for a user that has an
659 # address which is duplicated in a different case by another user
660 assert_difference "ActionMailer::Base.deliveries.size", 1 do
661 post :lost_password, :user => { :email => users(:normal_user).email }
663 assert_response :redirect
664 assert_redirected_to :action => :login
665 assert_match /^Sorry you lost it/, flash[:notice]
666 email = ActionMailer::Base.deliveries.first
667 assert_equal 1, email.to.count
668 assert_equal users(:normal_user).email, email.to.first
669 ActionMailer::Base.deliveries.clear
671 # Test resetting using an address that matches a different user
672 # that has the same address in a different case
673 assert_difference "ActionMailer::Base.deliveries.size", 1 do
674 post :lost_password, :user => { :email => users(:normal_user).email.upcase }
676 assert_response :redirect
677 assert_redirected_to :action => :login
678 assert_match /^Sorry you lost it/, flash[:notice]
679 email = ActionMailer::Base.deliveries.first
680 assert_equal 1, email.to.count
681 assert_equal users(:uppercase_user).email, email.to.first
682 ActionMailer::Base.deliveries.clear
684 # Test resetting using an address that is a case insensitive match
685 # for more than one user but not an exact match for either
686 assert_no_difference "ActionMailer::Base.deliveries.size" do
687 post :lost_password, :user => { :email => users(:normal_user).email.titlecase }
689 assert_response :success
690 assert_template :lost_password
691 assert_select ".error", /^Could not find that email address/
693 # Test resetting using the address as recorded for a user that has an
694 # address which is case insensitively unique
695 assert_difference "ActionMailer::Base.deliveries.size", 1 do
696 post :lost_password, :user => { :email => users(:public_user).email }
698 assert_response :redirect
699 assert_redirected_to :action => :login
700 assert_match /^Sorry you lost it/, flash[:notice]
701 email = ActionMailer::Base.deliveries.first
702 assert_equal 1, email.to.count
703 assert_equal users(:public_user).email, email.to.first
704 ActionMailer::Base.deliveries.clear
706 # Test resetting using an address that matches a user that has the
707 # same (case insensitively unique) address in a different case
708 assert_difference "ActionMailer::Base.deliveries.size", 1 do
709 post :lost_password, :user => { :email => users(:public_user).email.upcase }
711 assert_response :redirect
712 assert_redirected_to :action => :login
713 assert_match /^Sorry you lost it/, flash[:notice]
714 email = ActionMailer::Base.deliveries.first
715 assert_equal 1, email.to.count
716 assert_equal users(:public_user).email, email.to.first
717 ActionMailer::Base.deliveries.clear
720 def test_reset_password
721 # Test a request with no token
723 assert_response :bad_request
725 # Test a request with a bogus token
726 get :reset_password, :token => "made_up_token"
727 assert_response :redirect
728 assert_redirected_to :action => :lost_password
730 # Create a valid token for a user
731 token = User.find(users(:inactive_user).id).tokens.create
733 # Test a request with a valid token
734 get :reset_password, :token => token.token
735 assert_response :success
736 assert_template :reset_password
738 # Test setting a new password
739 post :reset_password, :token => token.token, :user => { :pass_crypt => "new_password", :pass_crypt_confirmation => "new_password" }
740 assert_response :redirect
741 assert_redirected_to root_path
742 assert_equal users(:inactive_user).id, session[:user]
743 user = User.find(users(:inactive_user).id)
744 assert_equal "active", user.status
745 assert_equal true, user.email_valid
746 assert_equal user, User.authenticate(:username => "inactive@openstreetmap.org", :password => "new_password")
750 # Get a user to work with - note that this user deliberately
751 # conflicts with uppercase_user in the email and display name
752 # fields to test that we can change other fields without any
753 # validation errors being reported
754 user = users(:normal_user)
756 # Make sure that you are redirected to the login page when
757 # you are not logged in
758 get :account, :display_name => user.display_name
759 assert_response :redirect
760 assert_redirected_to :controller => :user, :action => "login", :referer => "/user/test/account"
762 # Make sure that you are blocked when not logged in as the right user
763 get :account, { :display_name => user.display_name }, { :user => users(:public_user).id }
764 assert_response :forbidden
766 # Make sure we get the page when we are logged in as the right user
767 get :account, { :display_name => user.display_name }, { :user => user }
768 assert_response :success
769 assert_template :account
771 # Updating the description should work
772 user.description = "new description"
773 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
774 assert_response :success
775 assert_template :account
776 assert_select "div#errorExplanation", false
777 assert_select ".notice", /^User information updated successfully/
778 assert_select "form#accountForm > fieldset > div.form-row > div#user_description_container > div#user_description_content > textarea#user_description", user.description
780 # Changing to a invalid editor should fail
781 user.preferred_editor = "unknown"
782 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
783 assert_response :success
784 assert_template :account
785 assert_select ".notice", false
786 assert_select "div#errorExplanation"
787 assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected]", false
789 # Changing to a valid editor should work
790 user.preferred_editor = "potlatch2"
791 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
792 assert_response :success
793 assert_template :account
794 assert_select "div#errorExplanation", false
795 assert_select ".notice", /^User information updated successfully/
796 assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected][value=?]", "potlatch2"
798 # Changing to the default editor should work
799 user.preferred_editor = "default"
800 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
801 assert_response :success
802 assert_template :account
803 assert_select "div#errorExplanation", false
804 assert_select ".notice", /^User information updated successfully/
805 assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected]", false
807 # Changing to an uploaded image should work
808 image = Rack::Test::UploadedFile.new("test/traces/1.gif", "image/gif")
809 post :account, { :display_name => user.display_name, :image_action => "new", :user => user.attributes.merge(:image => image) }, { :user => user.id }
810 assert_response :success
811 assert_template :account
812 assert_select "div#errorExplanation", false
813 assert_select ".notice", /^User information updated successfully/
814 assert_select "form#accountForm > fieldset > div.form-row.accountImage input[name=image_action][checked][value=?]", "keep"
816 # Changing to a gravatar image should work
817 post :account, { :display_name => user.display_name, :image_action => "gravatar", :user => user.attributes }, { :user => user.id }
818 assert_response :success
819 assert_template :account
820 assert_select "div#errorExplanation", false
821 assert_select ".notice", /^User information updated successfully/
822 assert_select "form#accountForm > fieldset > div.form-row.accountImage input[name=image_action][checked][value=?]", "gravatar"
824 # Removing the image should work
825 post :account, { :display_name => user.display_name, :image_action => "delete", :user => user.attributes }, { :user => user.id }
826 assert_response :success
827 assert_template :account
828 assert_select "div#errorExplanation", false
829 assert_select ".notice", /^User information updated successfully/
830 assert_select "form#accountForm > fieldset > div.form-row.accountImage input[name=image_action][checked]", false
832 # Adding external authentication should redirect to the auth provider
833 post :account, { :display_name => user.display_name, :user => user.attributes.merge(:auth_provider => "openid", :auth_uid => "gmail.com") }, { :user => user.id }
834 assert_response :redirect
835 assert_redirected_to auth_path(:provider => "openid", :openid_url => "https://www.google.com/accounts/o8/id", :origin => "/user/#{user.display_name}/account")
837 # Changing name to one that exists should fail
838 new_attributes = user.attributes.dup.merge(:display_name => users(:public_user).display_name)
839 post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id }
840 assert_response :success
841 assert_template :account
842 assert_select ".notice", false
843 assert_select "div#errorExplanation"
844 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_display_name"
846 # Changing name to one that exists should fail, regardless of case
847 new_attributes = user.attributes.dup.merge(:display_name => users(:public_user).display_name.upcase)
848 post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id }
849 assert_response :success
850 assert_template :account
851 assert_select ".notice", false
852 assert_select "div#errorExplanation"
853 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_display_name"
855 # Changing name to one that doesn't exist should work
856 new_attributes = user.attributes.dup.merge(:display_name => "new tester")
857 post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id }
858 assert_response :success
859 assert_template :account
860 assert_select "div#errorExplanation", false
861 assert_select ".notice", /^User information updated successfully/
862 assert_select "form#accountForm > fieldset > div.form-row > input#user_display_name[value=?]", "new tester"
864 # Record the change of name
865 user.display_name = "new tester"
867 # Changing email to one that exists should fail
868 user.new_email = users(:public_user).email
869 assert_no_difference "ActionMailer::Base.deliveries.size" do
870 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
872 assert_response :success
873 assert_template :account
874 assert_select ".notice", false
875 assert_select "div#errorExplanation"
876 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_new_email"
878 # Changing email to one that exists should fail, regardless of case
879 user.new_email = users(:public_user).email.upcase
880 assert_no_difference "ActionMailer::Base.deliveries.size" do
881 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
883 assert_response :success
884 assert_template :account
885 assert_select ".notice", false
886 assert_select "div#errorExplanation"
887 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_new_email"
889 # Changing email to one that doesn't exist should work
890 user.new_email = "new_tester@example.com"
891 assert_difference "ActionMailer::Base.deliveries.size", 1 do
892 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
894 assert_response :success
895 assert_template :account
896 assert_select "div#errorExplanation", false
897 assert_select ".notice", /^User information updated successfully/
898 assert_select "form#accountForm > fieldset > div.form-row > input#user_new_email[value=?]", user.new_email
899 email = ActionMailer::Base.deliveries.first
900 assert_equal 1, email.to.count
901 assert_equal user.new_email, email.to.first
902 ActionMailer::Base.deliveries.clear
905 # Check that the user account page will display and contains some relevant
906 # information for the user
908 # Test a non-existent user
909 get :view, :display_name => "unknown"
910 assert_response :not_found
913 get :view, :display_name => "test"
914 assert_response :success
915 assert_select "div#userinformation" do
916 assert_select "a[href^='/user/test/history']", 1
917 assert_select "a[href='/user/test/traces']", 1
918 assert_select "a[href='/user/test/diary']", 1
919 assert_select "a[href='/user/test/diary/comments']", 1
920 assert_select "a[href='/user/test/account']", 0
921 assert_select "a[href='/user/test/blocks']", 0
922 assert_select "a[href='/user/test/blocks_by']", 0
923 assert_select "a[href='/blocks/new/test']", 0
926 # Test a user who has been blocked
927 get :view, :display_name => "blocked"
928 assert_response :success
929 assert_select "div#userinformation" do
930 assert_select "a[href^='/user/blocked/history']", 1
931 assert_select "a[href='/user/blocked/traces']", 1
932 assert_select "a[href='/user/blocked/diary']", 1
933 assert_select "a[href='/user/blocked/diary/comments']", 1
934 assert_select "a[href='/user/blocked/account']", 0
935 assert_select "a[href='/user/blocked/blocks']", 1
936 assert_select "a[href='/user/blocked/blocks_by']", 0
937 assert_select "a[href='/blocks/new/blocked']", 0
940 # Test a moderator who has applied blocks
941 get :view, :display_name => "moderator"
942 assert_response :success
943 assert_select "div#userinformation" do
944 assert_select "a[href^='/user/moderator/history']", 1
945 assert_select "a[href='/user/moderator/traces']", 1
946 assert_select "a[href='/user/moderator/diary']", 1
947 assert_select "a[href='/user/moderator/diary/comments']", 1
948 assert_select "a[href='/user/moderator/account']", 0
949 assert_select "a[href='/user/moderator/blocks']", 0
950 assert_select "a[href='/user/moderator/blocks_by']", 1
951 assert_select "a[href='/blocks/new/moderator']", 0
954 # Login as a normal user
955 session[:user] = users(:normal_user).id
957 # Test the normal user
958 get :view, :display_name => "test"
959 assert_response :success
960 assert_select "div#userinformation" do
961 assert_select "a[href^='/user/test/history']", 1
962 assert_select "a[href='/traces/mine']", 1
963 assert_select "a[href='/user/test/diary']", 1
964 assert_select "a[href='/user/test/diary/comments']", 1
965 assert_select "a[href='/user/test/account']", 1
966 assert_select "a[href='/user/test/blocks']", 0
967 assert_select "a[href='/user/test/blocks_by']", 0
968 assert_select "a[href='/blocks/new/test']", 0
971 # Login as a moderator
972 session[:user] = users(:moderator_user).id
974 # Test the normal user
975 get :view, :display_name => "test"
976 assert_response :success
977 assert_select "div#userinformation" do
978 assert_select "a[href^='/user/test/history']", 1
979 assert_select "a[href='/user/test/traces']", 1
980 assert_select "a[href='/user/test/diary']", 1
981 assert_select "a[href='/user/test/diary/comments']", 1
982 assert_select "a[href='/user/test/account']", 0
983 assert_select "a[href='/user/test/blocks']", 0
984 assert_select "a[href='/user/test/blocks_by']", 0
985 assert_select "a[href='/blocks/new/test']", 1
990 # check that a visible user is returned properly
991 get :api_read, :id => users(:normal_user).id
992 assert_response :success
993 assert_equal "text/xml", response.content_type
995 # check the data that is returned
996 assert_select "description", :count => 1, :text => "test"
997 assert_select "contributor-terms", :count => 1 do
998 assert_select "[agreed='true']"
1000 assert_select "img", :count => 0
1001 assert_select "roles", :count => 1 do
1002 assert_select "role", :count => 0
1004 assert_select "changesets", :count => 1 do
1005 assert_select "[count='0']"
1007 assert_select "traces", :count => 1 do
1008 assert_select "[count='0']"
1010 assert_select "blocks", :count => 1 do
1011 assert_select "received", :count => 1 do
1012 assert_select "[count='0'][active='0']"
1014 assert_select "issued", :count => 0
1017 # check that we aren't revealing private information
1018 assert_select "contributor-terms[pd]", false
1019 assert_select "home", false
1020 assert_select "languages", false
1021 assert_select "messages", false
1023 # check that a suspended user is not returned
1024 get :api_read, :id => users(:suspended_user).id
1025 assert_response :gone
1027 # check that a deleted user is not returned
1028 get :api_read, :id => users(:deleted_user).id
1029 assert_response :gone
1031 # check that a non-existent user is not returned
1032 get :api_read, :id => 0
1033 assert_response :not_found
1036 def test_api_details
1037 # check that nothing is returned when not logged in
1039 assert_response :unauthorized
1041 # check that we get a response when logged in
1042 basic_authorization(users(:normal_user).email, "test")
1044 assert_response :success
1045 assert_equal "text/xml", response.content_type
1047 # check the data that is returned
1048 assert_select "description", :count => 1, :text => "test"
1049 assert_select "contributor-terms", :count => 1 do
1050 assert_select "[agreed='true'][pd='false']"
1052 assert_select "img", :count => 0
1053 assert_select "roles", :count => 1 do
1054 assert_select "role", :count => 0
1056 assert_select "changesets", :count => 1 do
1057 assert_select "[count='0']", :count => 1
1059 assert_select "traces", :count => 1 do
1060 assert_select "[count='0']", :count => 1
1062 assert_select "blocks", :count => 1 do
1063 assert_select "received", :count => 1 do
1064 assert_select "[count='0'][active='0']"
1066 assert_select "issued", :count => 0
1068 assert_select "home", :count => 1 do
1069 assert_select "[lat='12.1'][lon='12.1'][zoom='3']"
1071 assert_select "languages", :count => 1 do
1072 assert_select "lang", :count => 1, :text => "en"
1074 assert_select "messages", :count => 1 do
1075 assert_select "received", :count => 1 do
1076 assert_select "[count='1'][unread='0']"
1078 assert_select "sent", :count => 1 do
1079 assert_select "[count='1']"
1084 def test_api_gpx_files
1085 # check that nothing is returned when not logged in
1087 assert_response :unauthorized
1089 # check that we get a response when logged in
1090 basic_authorization(users(:normal_user).email, "test")
1092 assert_response :success
1093 assert_equal "text/xml", response.content_type
1095 # check the data that is returned
1096 assert_select "gpx_file[id='1']", 1 do
1097 assert_select "tag", "London"
1099 assert_select "gpx_file[id='4']", 1 do
1100 assert_select "tag", "Birmingham"
1104 def test_make_friend
1105 # Get users to work with
1106 user = users(:normal_user)
1107 friend = users(:second_public_user)
1109 # Check that the users aren't already friends
1110 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1112 # When not logged in a GET should ask us to login
1113 get :make_friend, :display_name => friend.display_name
1114 assert_redirected_to :controller => :user, :action => "login", :referer => make_friend_path(:display_name => friend.display_name)
1116 # When not logged in a POST should error
1117 post :make_friend, :display_name => friend.display_name
1118 assert_response :forbidden
1119 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1121 # When logged in a GET should get a confirmation page
1122 get :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1123 assert_response :success
1124 assert_template :make_friend
1125 assert_select "form" do
1126 assert_select "input[type='hidden'][name='referer']", 0
1127 assert_select "input[type='submit']", 1
1129 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1131 # When logged in a POST should add the friendship
1132 assert_difference "ActionMailer::Base.deliveries.size", 1 do
1133 post :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1135 assert_redirected_to user_path(:display_name => friend.display_name)
1136 assert_match /is now your friend/, flash[:notice]
1137 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1138 email = ActionMailer::Base.deliveries.first
1139 assert_equal 1, email.to.count
1140 assert_equal friend.email, email.to.first
1141 ActionMailer::Base.deliveries.clear
1143 # A second POST should report that the friendship already exists
1144 assert_no_difference "ActionMailer::Base.deliveries.size" do
1145 post :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1147 assert_redirected_to user_path(:display_name => friend.display_name)
1148 assert_match /You are already friends with/, flash[:warning]
1149 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1152 def test_make_friend_with_referer
1153 # Get users to work with
1154 user = users(:normal_user)
1155 friend = users(:second_public_user)
1157 # Check that the users aren't already friends
1158 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1160 # The GET should preserve any referer
1161 get :make_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1162 assert_response :success
1163 assert_template :make_friend
1164 assert_select "form" do
1165 assert_select "input[type='hidden'][name='referer'][value='/test']", 1
1166 assert_select "input[type='submit']", 1
1168 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1170 # When logged in a POST should add the friendship and refer us
1171 assert_difference "ActionMailer::Base.deliveries.size", 1 do
1172 post :make_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1174 assert_redirected_to "/test"
1175 assert_match /is now your friend/, flash[:notice]
1176 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1177 email = ActionMailer::Base.deliveries.first
1178 assert_equal 1, email.to.count
1179 assert_equal friend.email, email.to.first
1180 ActionMailer::Base.deliveries.clear
1183 def test_make_friend_unkown_user
1184 # Should error when a bogus user is specified
1185 get :make_friend, { :display_name => "No Such User" }, { :user => users(:normal_user).id }
1186 assert_response :not_found
1187 assert_template :no_such_user
1190 def test_remove_friend
1191 # Get users to work with
1192 user = users(:normal_user)
1193 friend = users(:public_user)
1195 # Check that the users are friends
1196 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1198 # When not logged in a GET should ask us to login
1199 get :remove_friend, :display_name => friend.display_name
1200 assert_redirected_to :controller => :user, :action => "login", :referer => remove_friend_path(:display_name => friend.display_name)
1202 # When not logged in a POST should error
1203 post :remove_friend, :display_name => friend.display_name
1204 assert_response :forbidden
1205 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1207 # When logged in a GET should get a confirmation page
1208 get :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1209 assert_response :success
1210 assert_template :remove_friend
1211 assert_select "form" do
1212 assert_select "input[type='hidden'][name='referer']", 0
1213 assert_select "input[type='submit']", 1
1215 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1217 # When logged in a POST should remove the friendship
1218 post :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1219 assert_redirected_to user_path(:display_name => friend.display_name)
1220 assert_match /was removed from your friends/, flash[:notice]
1221 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1223 # A second POST should report that the friendship does not exist
1224 post :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1225 assert_redirected_to user_path(:display_name => friend.display_name)
1226 assert_match /is not one of your friends/, flash[:error]
1227 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1230 def test_remove_friend_with_referer
1231 # Get users to work with
1232 user = users(:normal_user)
1233 friend = users(:public_user)
1235 # Check that the users are friends
1236 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1238 # The GET should preserve any referer
1239 get :remove_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1240 assert_response :success
1241 assert_template :remove_friend
1242 assert_select "form" do
1243 assert_select "input[type='hidden'][name='referer'][value='/test']", 1
1244 assert_select "input[type='submit']", 1
1246 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1248 # When logged in a POST should remove the friendship and refer
1249 post :remove_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1250 assert_redirected_to "/test"
1251 assert_match /was removed from your friends/, flash[:notice]
1252 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1255 def test_remove_friend_unkown_user
1256 # Should error when a bogus user is specified
1257 get :remove_friend, { :display_name => "No Such User" }, { :user => users(:normal_user).id }
1258 assert_response :not_found
1259 assert_template :no_such_user
1263 # Try without logging in
1264 get :set_status, :display_name => users(:normal_user).display_name, :status => "suspended"
1265 assert_response :redirect
1266 assert_redirected_to :action => :login, :referer => set_status_user_path(:status => "suspended")
1268 # Now try as a normal user
1269 get :set_status, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:normal_user).id }
1270 assert_response :redirect
1271 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1273 # Finally try as an administrator
1274 get :set_status, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:administrator_user).id }
1275 assert_response :redirect
1276 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1277 assert_equal "suspended", User.find(users(:normal_user).id).status
1281 # Try without logging in
1282 get :delete, :display_name => users(:normal_user).display_name, :status => "suspended"
1283 assert_response :redirect
1284 assert_redirected_to :action => :login, :referer => delete_user_path(:status => "suspended")
1286 # Now try as a normal user
1287 get :delete, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:normal_user).id }
1288 assert_response :redirect
1289 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1291 # Finally try as an administrator
1292 get :delete, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:administrator_user).id }
1293 assert_response :redirect
1294 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1296 # Check that the user was deleted properly
1297 user = User.find(users(:normal_user).id)
1298 assert_equal "user_1", user.display_name
1299 assert_equal "", user.description
1300 assert_nil user.home_lat
1301 assert_nil user.home_lon
1302 assert_equal false, user.image.file?
1303 assert_equal false, user.email_valid
1304 assert_nil user.new_email
1305 assert_nil user.auth_provider
1306 assert_nil user.auth_uid
1307 assert_equal "deleted", user.status
1311 # Shouldn't work when not logged in
1313 assert_response :redirect
1314 assert_redirected_to :action => :login, :referer => users_path
1316 session[:user] = users(:normal_user).id
1318 # Shouldn't work when logged in as a normal user
1320 assert_response :redirect
1321 assert_redirected_to :action => :login, :referer => users_path
1323 session[:user] = users(:moderator_user).id
1325 # Shouldn't work when logged in as a moderator
1327 assert_response :redirect
1328 assert_redirected_to :action => :login, :referer => users_path
1330 session[:user] = users(:administrator_user).id
1332 # Should work when logged in as an administrator
1334 assert_response :success
1335 assert_template :list
1336 assert_select "table#user_list tr", :count => User.count + 1
1338 # Should be able to limit by status
1339 get :list, :status => "suspended"
1340 assert_response :success
1341 assert_template :list
1342 assert_select "table#user_list tr", :count => User.where(:status => "suspended").count + 1
1344 # Should be able to limit by IP address
1345 get :list, :ip => "1.2.3.4"
1346 assert_response :success
1347 assert_template :list
1348 assert_select "table#user_list tr", :count => User.where(:creation_ip => "1.2.3.4").count + 1
1351 def test_list_get_paginated
1352 1.upto(100).each do |n|
1353 User.create(:display_name => "extra_#{n}",
1354 :email => "extra#{n}@example.com",
1355 :pass_crypt => "extraextra")
1358 session[:user] = users(:administrator_user).id
1361 assert_response :success
1362 assert_template :list
1363 assert_select "table#user_list tr", :count => 51
1365 get :list, :page => 2
1366 assert_response :success
1367 assert_template :list
1368 assert_select "table#user_list tr", :count => 51
1370 get :list, :page => 3
1371 assert_response :success
1372 assert_template :list
1373 assert_select "table#user_list tr", :count => 25
1376 def test_list_post_confirm
1377 inactive_user = users(:inactive_user)
1378 suspended_user = users(:suspended_user)
1380 # Shouldn't work when not logged in
1381 assert_no_difference "User.active.count" do
1382 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1384 assert_response :redirect
1385 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1386 assert_equal "pending", inactive_user.reload.status
1387 assert_equal "suspended", suspended_user.reload.status
1389 session[:user] = users(:normal_user).id
1391 # Shouldn't work when logged in as a normal user
1392 assert_no_difference "User.active.count" do
1393 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1395 assert_response :redirect
1396 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1397 assert_equal "pending", inactive_user.reload.status
1398 assert_equal "suspended", suspended_user.reload.status
1400 session[:user] = users(:moderator_user).id
1402 # Shouldn't work when logged in as a moderator
1403 assert_no_difference "User.active.count" do
1404 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1406 assert_response :redirect
1407 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1408 assert_equal "pending", inactive_user.reload.status
1409 assert_equal "suspended", suspended_user.reload.status
1411 session[:user] = users(:administrator_user).id
1413 # Should work when logged in as an administrator
1414 assert_difference "User.active.count", 2 do
1415 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1417 assert_response :redirect
1418 assert_redirected_to :action => :list
1419 assert_equal "confirmed", inactive_user.reload.status
1420 assert_equal "confirmed", suspended_user.reload.status
1423 def test_list_post_hide
1424 normal_user = users(:normal_user)
1425 confirmed_user = users(:confirmed_user)
1427 # Shouldn't work when not logged in
1428 assert_no_difference "User.active.count" do
1429 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1431 assert_response :redirect
1432 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1433 assert_equal "active", normal_user.reload.status
1434 assert_equal "confirmed", confirmed_user.reload.status
1436 session[:user] = users(:normal_user).id
1438 # Shouldn't work when logged in as a normal user
1439 assert_no_difference "User.active.count" do
1440 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1442 assert_response :redirect
1443 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1444 assert_equal "active", normal_user.reload.status
1445 assert_equal "confirmed", confirmed_user.reload.status
1447 session[:user] = users(:moderator_user).id
1449 # Shouldn't work when logged in as a moderator
1450 assert_no_difference "User.active.count" do
1451 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1453 assert_response :redirect
1454 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1455 assert_equal "active", normal_user.reload.status
1456 assert_equal "confirmed", confirmed_user.reload.status
1458 session[:user] = users(:administrator_user).id
1460 # Should work when logged in as an administrator
1461 assert_difference "User.active.count", -2 do
1462 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1464 assert_response :redirect
1465 assert_redirected_to :action => :list
1466 assert_equal "deleted", normal_user.reload.status
1467 assert_equal "deleted", confirmed_user.reload.status
1474 user.status = "pending"
1475 user.display_name = "new_tester"
1476 user.email = "newtester@osm.org"
1477 user.email_confirmation = "newtester@osm.org"
1478 user.pass_crypt = "testtest"
1479 user.pass_crypt_confirmation = "testtest"