3 class UserControllerTest < ActionController::TestCase
7 stub_request(:get, "http://api.hostip.info/country.php?ip=0.0.0.0")
8 stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404)
12 # test all routes which lead to this controller
15 { :path => "/api/0.6/user/1", :method => :get },
16 { :controller => "user", :action => "api_read", :id => "1" }
19 { :path => "/api/0.6/user/details", :method => :get },
20 { :controller => "user", :action => "api_details" }
23 { :path => "/api/0.6/user/gpx_files", :method => :get },
24 { :controller => "user", :action => "api_gpx_files" }
28 { :path => "/login", :method => :get },
29 { :controller => "user", :action => "login" }
32 { :path => "/login", :method => :post },
33 { :controller => "user", :action => "login" }
36 { :controller => "user", :action => "login", :format => "html" },
37 { :path => "/login.html", :method => :get }
41 { :path => "/logout", :method => :get },
42 { :controller => "user", :action => "logout" }
45 { :path => "/logout", :method => :post },
46 { :controller => "user", :action => "logout" }
49 { :controller => "user", :action => "logout", :format => "html" },
50 { :path => "/logout.html", :method => :get }
54 { :path => "/user/new", :method => :get },
55 { :controller => "user", :action => "new" }
59 { :path => "/user/new", :method => :post },
60 { :controller => "user", :action => "create" }
64 { :path => "/user/terms", :method => :get },
65 { :controller => "user", :action => "terms" }
69 { :path => "/user/save", :method => :post },
70 { :controller => "user", :action => "save" }
74 { :path => "/user/username/confirm", :method => :get },
75 { :controller => "user", :action => "confirm", :display_name => "username" }
78 { :path => "/user/username/confirm", :method => :post },
79 { :controller => "user", :action => "confirm", :display_name => "username" }
82 { :path => "/user/username/confirm/resend", :method => :get },
83 { :controller => "user", :action => "confirm_resend", :display_name => "username" }
87 { :path => "/user/confirm", :method => :get },
88 { :controller => "user", :action => "confirm" }
91 { :path => "/user/confirm", :method => :post },
92 { :controller => "user", :action => "confirm" }
95 { :path => "/user/confirm-email", :method => :get },
96 { :controller => "user", :action => "confirm_email" }
99 { :path => "/user/confirm-email", :method => :post },
100 { :controller => "user", :action => "confirm_email" }
104 { :path => "/user/go_public", :method => :post },
105 { :controller => "user", :action => "go_public" }
109 { :path => "/user/forgot-password", :method => :get },
110 { :controller => "user", :action => "lost_password" }
113 { :path => "/user/forgot-password", :method => :post },
114 { :controller => "user", :action => "lost_password" }
117 { :path => "/user/reset-password", :method => :get },
118 { :controller => "user", :action => "reset_password" }
121 { :path => "/user/reset-password", :method => :post },
122 { :controller => "user", :action => "reset_password" }
126 { :path => "/user/suspended", :method => :get },
127 { :controller => "user", :action => "suspended" }
131 { :path => "/user/username", :method => :get },
132 { :controller => "user", :action => "view", :display_name => "username" }
136 { :path => "/user/username/account", :method => :get },
137 { :controller => "user", :action => "account", :display_name => "username" }
140 { :path => "/user/username/account", :method => :post },
141 { :controller => "user", :action => "account", :display_name => "username" }
145 { :path => "/user/username/make_friend", :method => :get },
146 { :controller => "user", :action => "make_friend", :display_name => "username" }
149 { :path => "/user/username/make_friend", :method => :post },
150 { :controller => "user", :action => "make_friend", :display_name => "username" }
153 { :path => "/user/username/remove_friend", :method => :get },
154 { :controller => "user", :action => "remove_friend", :display_name => "username" }
157 { :path => "/user/username/remove_friend", :method => :post },
158 { :controller => "user", :action => "remove_friend", :display_name => "username" }
162 { :path => "/user/username/set_status", :method => :get },
163 { :controller => "user", :action => "set_status", :display_name => "username" }
166 { :path => "/user/username/delete", :method => :get },
167 { :controller => "user", :action => "delete", :display_name => "username" }
171 { :path => "/users", :method => :get },
172 { :controller => "user", :action => "list" }
175 { :path => "/users", :method => :post },
176 { :controller => "user", :action => "list" }
179 { :path => "/users/status", :method => :get },
180 { :controller => "user", :action => "list", :status => "status" }
183 { :path => "/users/status", :method => :post },
184 { :controller => "user", :action => "list", :status => "status" }
188 # The user creation page loads
191 assert_response :redirect
192 assert_redirected_to user_new_path(:cookie_test => "true")
194 get :new, { :cookie_test => "true" }, { :cookie_test => true }
195 assert_response :success
197 assert_select "html", :count => 1 do
198 assert_select "head", :count => 1 do
199 assert_select "title", :text => /Sign Up/, :count => 1
201 assert_select "body", :count => 1 do
202 assert_select "div#content", :count => 1 do
203 assert_select "form[action='/user/new'][method='post']", :count => 1 do
204 assert_select "input[id='user_email']", :count => 1
205 assert_select "input[id='user_email_confirmation']", :count => 1
206 assert_select "input[id='user_display_name']", :count => 1
207 assert_select "input[id='user_pass_crypt'][type='password']", :count => 1
208 assert_select "input[id='user_pass_crypt_confirmation'][type='password']", :count => 1
209 assert_select "input[type='submit'][value='Sign Up']", :count => 1
216 def test_new_view_logged_in
217 session[:user] = users(:normal_user).id
220 assert_response :redirect
221 assert_redirected_to user_new_path(:cookie_test => "true")
222 get :new, :cookie_test => "true"
223 assert_response :redirect
224 assert_redirected_to root_path
226 get :new, :referer => "/test"
227 assert_response :redirect
228 assert_redirected_to user_new_path(:referer => "/test", :cookie_test => "true")
229 get :new, :referer => "/test", :cookie_test => "true"
230 assert_response :redirect
231 assert_redirected_to "/test"
237 assert_difference "User.count", 1 do
238 assert_difference "ActionMailer::Base.deliveries.size", 1 do
239 post :save, {}, { :new_user => user }
244 register_email = ActionMailer::Base.deliveries.first
246 assert_equal register_email.to[0], user.email
247 assert_match /#{@url}/, register_email.body.to_s
250 assert_redirected_to :action => "confirm", :display_name => user.display_name
252 ActionMailer::Base.deliveries.clear
255 def test_new_duplicate_email
257 user.email = users(:public_user).email
259 assert_no_difference "User.count" do
260 assert_no_difference "ActionMailer::Base.deliveries.size" do
261 post :save, {}, { :new_user => user }
265 assert_response :success
266 assert_template "new"
267 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
270 def test_new_duplicate_email_uppercase
272 user.email = users(:public_user).email.upcase
274 assert_no_difference "User.count" do
275 assert_no_difference "ActionMailer::Base.deliveries.size" do
276 post :save, {}, { :new_user => user }
280 assert_response :success
281 assert_template "new"
282 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
285 def test_new_duplicate_name
287 user.display_name = users(:public_user).display_name
289 assert_no_difference "User.count" do
290 assert_no_difference "ActionMailer::Base.deliveries.size" do
291 post :save, {}, { :new_user => user }
295 assert_response :success
296 assert_template "new"
297 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
300 def test_new_duplicate_name_uppercase
302 user.display_name = users(:public_user).display_name.upcase
304 assert_no_difference "User.count" do
305 assert_no_difference "ActionMailer::Base.deliveries.size" do
306 post :save, {}, { :new_user => user }
310 assert_response :success
311 assert_template "new"
312 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
315 def test_save_referer_params
318 assert_difference "User.count", 1 do
319 assert_difference "ActionMailer::Base.deliveries.size", 1 do
320 post :save, {}, { :new_user => user,
321 :referer => "/edit?editor=id#map=1/2/3" }
325 assert_equal welcome_path(:editor => "id", :zoom => 1, :lat => 2, :lon => 3),
326 user.tokens.order("id DESC").first.referer
328 ActionMailer::Base.deliveries.clear
331 def test_logout_without_referer
333 assert_response :success
334 assert_template :logout
335 assert_select "input[name=referer][value=?]", ""
337 session_id = assert_select("input[name=session]").first["value"]
339 get :logout, :session => session_id
340 assert_response :redirect
341 assert_redirected_to root_path
344 def test_logout_with_referer
345 get :logout, :referer => "/test"
346 assert_response :success
347 assert_template :logout
348 assert_select "input[name=referer][value=?]", "/test"
350 session_id = assert_select("input[name=session]").first["value"]
352 get :logout, :session => session_id, :referer => "/test"
353 assert_response :redirect
354 assert_redirected_to "/test"
357 def test_logout_with_token
358 token = users(:normal_user).tokens.create
360 session[:token] = token.token
363 assert_response :success
364 assert_template :logout
365 assert_select "input[name=referer][value=?]", ""
366 assert_equal token.token, session[:token]
367 assert_not_nil UserToken.where(:id => token.id).first
369 session_id = assert_select("input[name=session]").first["value"]
371 get :logout, :session => session_id
372 assert_response :redirect
373 assert_redirected_to root_path
374 assert_nil session[:token]
375 assert_nil UserToken.where(:id => token.id).first
379 user = users(:inactive_user)
380 confirm_string = user.tokens.create.token
382 @request.cookies["_osm_session"] = user.display_name
383 get :confirm, :display_name => user.display_name, :confirm_string => confirm_string
384 assert_response :success
385 assert_template :confirm
388 def test_confirm_get_already_confirmed
389 user = users(:normal_user)
390 confirm_string = user.tokens.create.token
392 @request.cookies["_osm_session"] = user.display_name
393 get :confirm, :display_name => user.display_name, :confirm_string => confirm_string
394 assert_response :redirect
395 assert_redirected_to root_path
398 def test_confirm_success_no_token_no_referer
399 user = users(:inactive_user)
400 confirm_string = user.tokens.create.token
402 @request.cookies["_osm_session"] = user.display_name
403 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
404 assert_redirected_to login_path
405 assert_match /Confirmed your account/, flash[:notice]
408 def test_confirm_success_good_token_no_referer
409 user = users(:inactive_user)
410 confirm_string = user.tokens.create.token
411 token = user.tokens.create.token
413 @request.cookies["_osm_session"] = user.display_name
414 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
415 assert_redirected_to welcome_path
418 def test_confirm_success_bad_token_no_referer
419 user = users(:inactive_user)
420 confirm_string = user.tokens.create.token
421 token = users(:normal_user).tokens.create.token
423 @request.cookies["_osm_session"] = user.display_name
424 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
425 assert_redirected_to login_path
426 assert_match /Confirmed your account/, flash[:notice]
429 def test_confirm_success_no_token_with_referer
430 user = users(:inactive_user)
431 confirm_string = user.tokens.create(:referer => diary_new_path).token
433 @request.cookies["_osm_session"] = user.display_name
434 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
435 assert_redirected_to login_path(:referer => diary_new_path)
436 assert_match /Confirmed your account/, flash[:notice]
439 def test_confirm_success_good_token_with_referer
440 user = users(:inactive_user)
441 confirm_string = user.tokens.create(:referer => diary_new_path).token
442 token = user.tokens.create.token
444 @request.cookies["_osm_session"] = user.display_name
445 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
446 assert_redirected_to diary_new_path
449 def test_confirm_success_bad_token_with_referer
450 user = users(:inactive_user)
451 confirm_string = user.tokens.create(:referer => diary_new_path).token
452 token = users(:normal_user).tokens.create.token
454 @request.cookies["_osm_session"] = user.display_name
455 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
456 assert_redirected_to login_path(:referer => diary_new_path)
457 assert_match /Confirmed your account/, flash[:notice]
460 def test_confirm_expired_token
461 user = users(:inactive_user)
462 confirm_string = user.tokens.create(:expiry => 1.day.ago).token
464 @request.cookies["_osm_session"] = user.display_name
465 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
466 assert_redirected_to :action => "confirm"
467 assert_match /confirmation code has expired/, flash[:error]
470 def test_confirm_already_confirmed
471 user = users(:normal_user)
472 confirm_string = user.tokens.create(:referer => diary_new_path).token
474 @request.cookies["_osm_session"] = user.display_name
475 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
476 assert_redirected_to :action => "login"
477 assert_match /already been confirmed/, flash[:error]
480 def test_confirm_resend_success
481 session[:token] = users(:inactive_user).tokens.create.token
483 assert_difference "ActionMailer::Base.deliveries.size", 1 do
484 get :confirm_resend, :display_name => users(:inactive_user).display_name
487 assert_response :redirect
488 assert_redirected_to login_path
489 assert_match /sent a new confirmation/, flash[:notice]
491 email = ActionMailer::Base.deliveries.last
493 assert_equal users(:inactive_user).email, email.to.first
495 ActionMailer::Base.deliveries.clear
498 def test_confirm_resend_no_token
499 assert_no_difference "ActionMailer::Base.deliveries.size" do
500 get :confirm_resend, :display_name => users(:inactive_user).display_name
503 assert_response :redirect
504 assert_redirected_to login_path
505 assert_match "User Inactive User not found.", flash[:error]
508 def test_confirm_resend_unknown_user
509 assert_no_difference "ActionMailer::Base.deliveries.size" do
510 get :confirm_resend, :display_name => "No Such User"
513 assert_response :redirect
514 assert_redirected_to login_path
515 assert_match "User No Such User not found.", flash[:error]
518 def test_confirm_email_get
519 user = users(:normal_user)
520 confirm_string = user.tokens.create.token
522 get :confirm_email, :confirm_string => confirm_string
523 assert_response :success
524 assert_template :confirm_email
527 def test_confirm_email_success
528 user = users(:second_public_user)
529 confirm_string = user.tokens.create.token
531 post :confirm_email, :confirm_string => confirm_string
532 assert_response :redirect
533 assert_redirected_to :action => :account, :display_name => user.display_name
534 assert_match /Confirmed your change of email address/, flash[:notice]
537 def test_confirm_email_already_confirmed
538 user = users(:normal_user)
539 confirm_string = user.tokens.create.token
541 post :confirm_email, :confirm_string => confirm_string
542 assert_response :redirect
543 assert_redirected_to :action => :account, :display_name => user.display_name
544 assert_match /already been confirmed/, flash[:error]
547 def test_confirm_email_bad_token
548 post :confirm_email, :confirm_string => "XXXXX"
549 assert_response :success
550 assert_template :confirm_email
551 assert_match /confirmation code has expired or does not exist/, flash[:error]
555 # test if testing for a gravatar works
556 # this happens when the email is actually changed
557 # which is triggered by the confirmation mail
558 def test_gravatar_auto_enable
559 with_http_stubs "gravatar" do
560 # switch to email that has a gravatar
561 user = users(:first_gravatar_user)
562 confirm_string = user.tokens.create.token
563 # precondition gravatar should be turned off
564 assert !user.image_use_gravatar
565 post :confirm_email, :confirm_string => confirm_string
566 assert_response :redirect
567 assert_redirected_to :action => :account, :display_name => user.display_name
568 assert_match /Confirmed your change of email address/, flash[:notice]
569 # gravatar use should now be enabled
570 assert User.find(users(:first_gravatar_user).id).image_use_gravatar
574 def test_gravatar_auto_disable
575 with_http_stubs "gravatar" do
576 # switch to email without a gravatar
577 user = users(:second_gravatar_user)
578 confirm_string = user.tokens.create.token
579 # precondition gravatar should be turned on
580 assert user.image_use_gravatar
581 post :confirm_email, :confirm_string => confirm_string
582 assert_response :redirect
583 assert_redirected_to :action => :account, :display_name => user.display_name
584 assert_match /Confirmed your change of email address/, flash[:notice]
585 # gravatar use should now be disabled
586 assert !User.find(users(:second_gravatar_user).id).image_use_gravatar
590 def test_terms_new_user
591 get :terms, {}, { :new_user => User.new }
592 assert_response :success
593 assert_template :terms
597 user = users(:normal_user)
599 session[:user] = user.id
602 assert_response :redirect
603 assert_redirected_to :action => :account, :display_name => user.display_name
606 def test_terms_not_seen_without_referer
607 user = users(:terms_not_seen_user)
609 session[:user] = user.id
612 assert_response :success
613 assert_template :terms
615 post :save, :user => { :consider_pd => true }
616 assert_response :redirect
617 assert_redirected_to :action => :account, :display_name => user.display_name
618 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
622 assert_equal true, user.consider_pd
623 assert_not_nil user.terms_agreed
624 assert_equal true, user.terms_seen
627 def test_terms_not_seen_with_referer
628 user = users(:terms_not_seen_user)
630 session[:user] = user.id
632 get :terms, :referer => "/test"
633 assert_response :success
634 assert_template :terms
636 post :save, :user => { :consider_pd => true }, :referer => "/test"
637 assert_response :redirect
638 assert_redirected_to "/test"
639 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
643 assert_equal true, user.consider_pd
644 assert_not_nil user.terms_agreed
645 assert_equal true, user.terms_seen
649 post :go_public, {}, { :user => users(:normal_user) }
650 assert_response :redirect
651 assert_redirected_to :action => :account, :display_name => users(:normal_user).display_name
652 assert_equal true, User.find(users(:normal_user).id).data_public
655 def test_lost_password
656 # Test fetching the lost password page
658 assert_response :success
659 assert_template :lost_password
660 assert_select "div#notice", false
662 # Test resetting using the address as recorded for a user that has an
663 # address which is duplicated in a different case by another user
664 assert_difference "ActionMailer::Base.deliveries.size", 1 do
665 post :lost_password, :user => { :email => users(:normal_user).email }
667 assert_response :redirect
668 assert_redirected_to :action => :login
669 assert_match /^Sorry you lost it/, flash[:notice]
670 email = ActionMailer::Base.deliveries.first
671 assert_equal 1, email.to.count
672 assert_equal users(:normal_user).email, email.to.first
673 ActionMailer::Base.deliveries.clear
675 # Test resetting using an address that matches a different user
676 # that has the same address in a different case
677 assert_difference "ActionMailer::Base.deliveries.size", 1 do
678 post :lost_password, :user => { :email => users(:normal_user).email.upcase }
680 assert_response :redirect
681 assert_redirected_to :action => :login
682 assert_match /^Sorry you lost it/, flash[:notice]
683 email = ActionMailer::Base.deliveries.first
684 assert_equal 1, email.to.count
685 assert_equal users(:uppercase_user).email, email.to.first
686 ActionMailer::Base.deliveries.clear
688 # Test resetting using an address that is a case insensitive match
689 # for more than one user but not an exact match for either
690 assert_no_difference "ActionMailer::Base.deliveries.size" do
691 post :lost_password, :user => { :email => users(:normal_user).email.titlecase }
693 assert_response :success
694 assert_template :lost_password
695 assert_select ".error", /^Could not find that email address/
697 # Test resetting using the address as recorded for a user that has an
698 # address which is case insensitively unique
699 assert_difference "ActionMailer::Base.deliveries.size", 1 do
700 post :lost_password, :user => { :email => users(:public_user).email }
702 assert_response :redirect
703 assert_redirected_to :action => :login
704 assert_match /^Sorry you lost it/, flash[:notice]
705 email = ActionMailer::Base.deliveries.first
706 assert_equal 1, email.to.count
707 assert_equal users(:public_user).email, email.to.first
708 ActionMailer::Base.deliveries.clear
710 # Test resetting using an address that matches a user that has the
711 # same (case insensitively unique) address in a different case
712 assert_difference "ActionMailer::Base.deliveries.size", 1 do
713 post :lost_password, :user => { :email => users(:public_user).email.upcase }
715 assert_response :redirect
716 assert_redirected_to :action => :login
717 assert_match /^Sorry you lost it/, flash[:notice]
718 email = ActionMailer::Base.deliveries.first
719 assert_equal 1, email.to.count
720 assert_equal users(:public_user).email, email.to.first
721 ActionMailer::Base.deliveries.clear
724 def test_reset_password
725 # Test a request with no token
727 assert_response :bad_request
729 # Test a request with a bogus token
730 get :reset_password, :token => "made_up_token"
731 assert_response :redirect
732 assert_redirected_to :action => :lost_password
734 # Create a valid token for a user
735 token = User.find(users(:inactive_user).id).tokens.create
737 # Test a request with a valid token
738 get :reset_password, :token => token.token
739 assert_response :success
740 assert_template :reset_password
742 # Test setting a new password
743 post :reset_password, :token => token.token, :user => { :pass_crypt => "new_password", :pass_crypt_confirmation => "new_password" }
744 assert_response :redirect
745 assert_redirected_to root_path
746 assert_equal users(:inactive_user).id, session[:user]
747 user = User.find(users(:inactive_user).id)
748 assert_equal "active", user.status
749 assert_equal true, user.email_valid
750 assert_equal user, User.authenticate(:username => "inactive@openstreetmap.org", :password => "new_password")
754 # Get a user to work with - note that this user deliberately
755 # conflicts with uppercase_user in the email and display name
756 # fields to test that we can change other fields without any
757 # validation errors being reported
758 user = users(:normal_user)
760 # Make sure that you are redirected to the login page when
761 # you are not logged in
762 get :account, :display_name => user.display_name
763 assert_response :redirect
764 assert_redirected_to :controller => :user, :action => "login", :referer => "/user/test/account"
766 # Make sure that you are blocked when not logged in as the right user
767 get :account, { :display_name => user.display_name }, { :user => users(:public_user).id }
768 assert_response :forbidden
770 # Make sure we get the page when we are logged in as the right user
771 get :account, { :display_name => user.display_name }, { :user => user }
772 assert_response :success
773 assert_template :account
775 # Updating the description should work
776 user.description = "new description"
777 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
778 assert_response :success
779 assert_template :account
780 assert_select "div#errorExplanation", false
781 assert_select ".notice", /^User information updated successfully/
782 assert_select "form#accountForm > fieldset > div.form-row > div#user_description_container > div#user_description_content > textarea#user_description", user.description
784 # Changing to a invalid editor should fail
785 user.preferred_editor = "unknown"
786 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
787 assert_response :success
788 assert_template :account
789 assert_select ".notice", false
790 assert_select "div#errorExplanation"
791 assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected]", false
793 # Changing to a valid editor should work
794 user.preferred_editor = "potlatch2"
795 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
796 assert_response :success
797 assert_template :account
798 assert_select "div#errorExplanation", false
799 assert_select ".notice", /^User information updated successfully/
800 assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected][value=?]", "potlatch2"
802 # Changing to the default editor should work
803 user.preferred_editor = "default"
804 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
805 assert_response :success
806 assert_template :account
807 assert_select "div#errorExplanation", false
808 assert_select ".notice", /^User information updated successfully/
809 assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected]", false
811 # Changing to an uploaded image should work
812 image = Rack::Test::UploadedFile.new("test/traces/1.gif", "image/gif")
813 post :account, { :display_name => user.display_name, :image_action => "new", :user => user.attributes.merge(:image => image) }, { :user => user.id }
814 assert_response :success
815 assert_template :account
816 assert_select "div#errorExplanation", false
817 assert_select ".notice", /^User information updated successfully/
818 assert_select "form#accountForm > fieldset > div.form-row.accountImage input[name=image_action][checked][value=?]", "keep"
820 # Changing to a gravatar image should work
821 post :account, { :display_name => user.display_name, :image_action => "gravatar", :user => user.attributes }, { :user => user.id }
822 assert_response :success
823 assert_template :account
824 assert_select "div#errorExplanation", false
825 assert_select ".notice", /^User information updated successfully/
826 assert_select "form#accountForm > fieldset > div.form-row.accountImage input[name=image_action][checked][value=?]", "gravatar"
828 # Removing the image should work
829 post :account, { :display_name => user.display_name, :image_action => "delete", :user => user.attributes }, { :user => user.id }
830 assert_response :success
831 assert_template :account
832 assert_select "div#errorExplanation", false
833 assert_select ".notice", /^User information updated successfully/
834 assert_select "form#accountForm > fieldset > div.form-row.accountImage input[name=image_action][checked]", false
836 # Adding external authentication should redirect to the auth provider
837 post :account, { :display_name => user.display_name, :user => user.attributes.merge(:auth_provider => "openid", :auth_uid => "gmail.com") }, { :user => user.id }
838 assert_response :redirect
839 assert_redirected_to auth_path(:provider => "openid", :openid_url => "https://www.google.com/accounts/o8/id", :origin => "/user/#{user.display_name}/account")
841 # Changing name to one that exists should fail
842 new_attributes = user.attributes.dup.merge(:display_name => users(:public_user).display_name)
843 post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id }
844 assert_response :success
845 assert_template :account
846 assert_select ".notice", false
847 assert_select "div#errorExplanation"
848 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_display_name"
850 # Changing name to one that exists should fail, regardless of case
851 new_attributes = user.attributes.dup.merge(:display_name => users(:public_user).display_name.upcase)
852 post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id }
853 assert_response :success
854 assert_template :account
855 assert_select ".notice", false
856 assert_select "div#errorExplanation"
857 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_display_name"
859 # Changing name to one that doesn't exist should work
860 new_attributes = user.attributes.dup.merge(:display_name => "new tester")
861 post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id }
862 assert_response :success
863 assert_template :account
864 assert_select "div#errorExplanation", false
865 assert_select ".notice", /^User information updated successfully/
866 assert_select "form#accountForm > fieldset > div.form-row > input#user_display_name[value=?]", "new tester"
868 # Record the change of name
869 user.display_name = "new tester"
871 # Changing email to one that exists should fail
872 user.new_email = users(:public_user).email
873 assert_no_difference "ActionMailer::Base.deliveries.size" do
874 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
876 assert_response :success
877 assert_template :account
878 assert_select ".notice", false
879 assert_select "div#errorExplanation"
880 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_new_email"
882 # Changing email to one that exists should fail, regardless of case
883 user.new_email = users(:public_user).email.upcase
884 assert_no_difference "ActionMailer::Base.deliveries.size" do
885 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
887 assert_response :success
888 assert_template :account
889 assert_select ".notice", false
890 assert_select "div#errorExplanation"
891 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_new_email"
893 # Changing email to one that doesn't exist should work
894 user.new_email = "new_tester@example.com"
895 assert_difference "ActionMailer::Base.deliveries.size", 1 do
896 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
898 assert_response :success
899 assert_template :account
900 assert_select "div#errorExplanation", false
901 assert_select ".notice", /^User information updated successfully/
902 assert_select "form#accountForm > fieldset > div.form-row > input#user_new_email[value=?]", user.new_email
903 email = ActionMailer::Base.deliveries.first
904 assert_equal 1, email.to.count
905 assert_equal user.new_email, email.to.first
906 ActionMailer::Base.deliveries.clear
909 # Check that the user account page will display and contains some relevant
910 # information for the user
912 # Test a non-existent user
913 get :view, :display_name => "unknown"
914 assert_response :not_found
917 get :view, :display_name => "test"
918 assert_response :success
919 assert_select "div#userinformation" do
920 assert_select "a[href^='/user/test/history']", 1
921 assert_select "a[href='/user/test/traces']", 1
922 assert_select "a[href='/user/test/diary']", 1
923 assert_select "a[href='/user/test/diary/comments']", 1
924 assert_select "a[href='/user/test/account']", 0
925 assert_select "a[href='/user/test/blocks']", 0
926 assert_select "a[href='/user/test/blocks_by']", 0
927 assert_select "a[href='/blocks/new/test']", 0
930 # Test a user who has been blocked
931 create(:user_block, :user => users(:blocked_user))
932 get :view, :display_name => "blocked"
933 assert_response :success
934 assert_select "div#userinformation" do
935 assert_select "a[href^='/user/blocked/history']", 1
936 assert_select "a[href='/user/blocked/traces']", 1
937 assert_select "a[href='/user/blocked/diary']", 1
938 assert_select "a[href='/user/blocked/diary/comments']", 1
939 assert_select "a[href='/user/blocked/account']", 0
940 assert_select "a[href='/user/blocked/blocks']", 1
941 assert_select "a[href='/user/blocked/blocks_by']", 0
942 assert_select "a[href='/blocks/new/blocked']", 0
945 # Test a moderator who has applied blocks
946 create(:user_block, :creator => users(:moderator_user))
947 get :view, :display_name => "moderator"
948 assert_response :success
949 assert_select "div#userinformation" do
950 assert_select "a[href^='/user/moderator/history']", 1
951 assert_select "a[href='/user/moderator/traces']", 1
952 assert_select "a[href='/user/moderator/diary']", 1
953 assert_select "a[href='/user/moderator/diary/comments']", 1
954 assert_select "a[href='/user/moderator/account']", 0
955 assert_select "a[href='/user/moderator/blocks']", 0
956 assert_select "a[href='/user/moderator/blocks_by']", 1
957 assert_select "a[href='/blocks/new/moderator']", 0
960 # Login as a normal user
961 session[:user] = users(:normal_user).id
963 # Test the normal user
964 get :view, :display_name => "test"
965 assert_response :success
966 assert_select "div#userinformation" do
967 assert_select "a[href^='/user/test/history']", 1
968 assert_select "a[href='/traces/mine']", 1
969 assert_select "a[href='/user/test/diary']", 1
970 assert_select "a[href='/user/test/diary/comments']", 1
971 assert_select "a[href='/user/test/account']", 1
972 assert_select "a[href='/user/test/blocks']", 0
973 assert_select "a[href='/user/test/blocks_by']", 0
974 assert_select "a[href='/blocks/new/test']", 0
977 # Login as a moderator
978 session[:user] = users(:moderator_user).id
980 # Test the normal user
981 get :view, :display_name => "test"
982 assert_response :success
983 assert_select "div#userinformation" do
984 assert_select "a[href^='/user/test/history']", 1
985 assert_select "a[href='/user/test/traces']", 1
986 assert_select "a[href='/user/test/diary']", 1
987 assert_select "a[href='/user/test/diary/comments']", 1
988 assert_select "a[href='/user/test/account']", 0
989 assert_select "a[href='/user/test/blocks']", 0
990 assert_select "a[href='/user/test/blocks_by']", 0
991 assert_select "a[href='/blocks/new/test']", 1
996 # check that a visible user is returned properly
997 get :api_read, :id => users(:normal_user).id
998 assert_response :success
999 assert_equal "text/xml", response.content_type
1001 # check the data that is returned
1002 assert_select "description", :count => 1, :text => "test"
1003 assert_select "contributor-terms", :count => 1 do
1004 assert_select "[agreed='true']"
1006 assert_select "img", :count => 0
1007 assert_select "roles", :count => 1 do
1008 assert_select "role", :count => 0
1010 assert_select "changesets", :count => 1 do
1011 assert_select "[count='0']"
1013 assert_select "traces", :count => 1 do
1014 assert_select "[count='0']"
1016 assert_select "blocks", :count => 1 do
1017 assert_select "received", :count => 1 do
1018 assert_select "[count='0'][active='0']"
1020 assert_select "issued", :count => 0
1023 # check that we aren't revealing private information
1024 assert_select "contributor-terms[pd]", false
1025 assert_select "home", false
1026 assert_select "languages", false
1027 assert_select "messages", false
1029 # check that a suspended user is not returned
1030 get :api_read, :id => users(:suspended_user).id
1031 assert_response :gone
1033 # check that a deleted user is not returned
1034 get :api_read, :id => users(:deleted_user).id
1035 assert_response :gone
1037 # check that a non-existent user is not returned
1038 get :api_read, :id => 0
1039 assert_response :not_found
1042 def test_api_details
1043 create(:message, :read, :recipient => users(:normal_user))
1045 # check that nothing is returned when not logged in
1047 assert_response :unauthorized
1049 # check that we get a response when logged in
1050 basic_authorization(users(:normal_user).email, "test")
1052 assert_response :success
1053 assert_equal "text/xml", response.content_type
1055 # check the data that is returned
1056 assert_select "description", :count => 1, :text => "test"
1057 assert_select "contributor-terms", :count => 1 do
1058 assert_select "[agreed='true'][pd='false']"
1060 assert_select "img", :count => 0
1061 assert_select "roles", :count => 1 do
1062 assert_select "role", :count => 0
1064 assert_select "changesets", :count => 1 do
1065 assert_select "[count='0']", :count => 1
1067 assert_select "traces", :count => 1 do
1068 assert_select "[count='0']", :count => 1
1070 assert_select "blocks", :count => 1 do
1071 assert_select "received", :count => 1 do
1072 assert_select "[count='0'][active='0']"
1074 assert_select "issued", :count => 0
1076 assert_select "home", :count => 1 do
1077 assert_select "[lat='12.1'][lon='12.1'][zoom='3']"
1079 assert_select "languages", :count => 1 do
1080 assert_select "lang", :count => 1, :text => "en"
1082 assert_select "messages", :count => 1 do
1083 assert_select "received", :count => 1 do
1084 assert_select "[count='1'][unread='0']"
1086 assert_select "sent", :count => 1 do
1087 assert_select "[count='1']"
1092 def test_api_gpx_files
1093 # check that nothing is returned when not logged in
1095 assert_response :unauthorized
1097 # check that we get a response when logged in
1098 basic_authorization(users(:normal_user).email, "test")
1100 assert_response :success
1101 assert_equal "text/xml", response.content_type
1103 # check the data that is returned
1104 assert_select "gpx_file[id='1']", 1 do
1105 assert_select "tag", "London"
1107 assert_select "gpx_file[id='4']", 1 do
1108 assert_select "tag", "Birmingham"
1112 def test_make_friend
1113 # Get users to work with
1114 user = users(:normal_user)
1115 friend = users(:second_public_user)
1117 # Check that the users aren't already friends
1118 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1120 # When not logged in a GET should ask us to login
1121 get :make_friend, :display_name => friend.display_name
1122 assert_redirected_to :controller => :user, :action => "login", :referer => make_friend_path(:display_name => friend.display_name)
1124 # When not logged in a POST should error
1125 post :make_friend, :display_name => friend.display_name
1126 assert_response :forbidden
1127 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1129 # When logged in a GET should get a confirmation page
1130 get :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1131 assert_response :success
1132 assert_template :make_friend
1133 assert_select "form" do
1134 assert_select "input[type='hidden'][name='referer']", 0
1135 assert_select "input[type='submit']", 1
1137 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1139 # When logged in a POST should add the friendship
1140 assert_difference "ActionMailer::Base.deliveries.size", 1 do
1141 post :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1143 assert_redirected_to user_path(:display_name => friend.display_name)
1144 assert_match /is now your friend/, flash[:notice]
1145 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1146 email = ActionMailer::Base.deliveries.first
1147 assert_equal 1, email.to.count
1148 assert_equal friend.email, email.to.first
1149 ActionMailer::Base.deliveries.clear
1151 # A second POST should report that the friendship already exists
1152 assert_no_difference "ActionMailer::Base.deliveries.size" do
1153 post :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1155 assert_redirected_to user_path(:display_name => friend.display_name)
1156 assert_match /You are already friends with/, flash[:warning]
1157 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1160 def test_make_friend_with_referer
1161 # Get users to work with
1162 user = users(:normal_user)
1163 friend = users(:second_public_user)
1165 # Check that the users aren't already friends
1166 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1168 # The GET should preserve any referer
1169 get :make_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1170 assert_response :success
1171 assert_template :make_friend
1172 assert_select "form" do
1173 assert_select "input[type='hidden'][name='referer'][value='/test']", 1
1174 assert_select "input[type='submit']", 1
1176 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1178 # When logged in a POST should add the friendship and refer us
1179 assert_difference "ActionMailer::Base.deliveries.size", 1 do
1180 post :make_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1182 assert_redirected_to "/test"
1183 assert_match /is now your friend/, flash[:notice]
1184 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1185 email = ActionMailer::Base.deliveries.first
1186 assert_equal 1, email.to.count
1187 assert_equal friend.email, email.to.first
1188 ActionMailer::Base.deliveries.clear
1191 def test_make_friend_unkown_user
1192 # Should error when a bogus user is specified
1193 get :make_friend, { :display_name => "No Such User" }, { :user => users(:normal_user).id }
1194 assert_response :not_found
1195 assert_template :no_such_user
1198 def test_remove_friend
1199 # Get users to work with
1200 user = users(:normal_user)
1201 friend = users(:public_user)
1202 create(:friend, :befriender => user, :befriendee => friend)
1204 # Check that the users are friends
1205 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1207 # When not logged in a GET should ask us to login
1208 get :remove_friend, :display_name => friend.display_name
1209 assert_redirected_to :controller => :user, :action => "login", :referer => remove_friend_path(:display_name => friend.display_name)
1211 # When not logged in a POST should error
1212 post :remove_friend, :display_name => friend.display_name
1213 assert_response :forbidden
1214 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1216 # When logged in a GET should get a confirmation page
1217 get :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1218 assert_response :success
1219 assert_template :remove_friend
1220 assert_select "form" do
1221 assert_select "input[type='hidden'][name='referer']", 0
1222 assert_select "input[type='submit']", 1
1224 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1226 # When logged in a POST should remove the friendship
1227 post :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1228 assert_redirected_to user_path(:display_name => friend.display_name)
1229 assert_match /was removed from your friends/, flash[:notice]
1230 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1232 # A second POST should report that the friendship does not exist
1233 post :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1234 assert_redirected_to user_path(:display_name => friend.display_name)
1235 assert_match /is not one of your friends/, flash[:error]
1236 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1239 def test_remove_friend_with_referer
1240 # Get users to work with
1241 user = users(:normal_user)
1242 friend = users(:public_user)
1243 create(:friend, :user_id => user.id, :friend_user_id => friend.id)
1245 # Check that the users are friends
1246 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1248 # The GET should preserve any referer
1249 get :remove_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1250 assert_response :success
1251 assert_template :remove_friend
1252 assert_select "form" do
1253 assert_select "input[type='hidden'][name='referer'][value='/test']", 1
1254 assert_select "input[type='submit']", 1
1256 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1258 # When logged in a POST should remove the friendship and refer
1259 post :remove_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1260 assert_redirected_to "/test"
1261 assert_match /was removed from your friends/, flash[:notice]
1262 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1265 def test_remove_friend_unkown_user
1266 # Should error when a bogus user is specified
1267 get :remove_friend, { :display_name => "No Such User" }, { :user => users(:normal_user).id }
1268 assert_response :not_found
1269 assert_template :no_such_user
1273 # Try without logging in
1274 get :set_status, :display_name => users(:normal_user).display_name, :status => "suspended"
1275 assert_response :redirect
1276 assert_redirected_to :action => :login, :referer => set_status_user_path(:status => "suspended")
1278 # Now try as a normal user
1279 get :set_status, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:normal_user).id }
1280 assert_response :redirect
1281 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1283 # Finally try as an administrator
1284 get :set_status, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:administrator_user).id }
1285 assert_response :redirect
1286 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1287 assert_equal "suspended", User.find(users(:normal_user).id).status
1291 # Try without logging in
1292 get :delete, :display_name => users(:normal_user).display_name, :status => "suspended"
1293 assert_response :redirect
1294 assert_redirected_to :action => :login, :referer => delete_user_path(:status => "suspended")
1296 # Now try as a normal user
1297 get :delete, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:normal_user).id }
1298 assert_response :redirect
1299 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1301 # Finally try as an administrator
1302 get :delete, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:administrator_user).id }
1303 assert_response :redirect
1304 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1306 # Check that the user was deleted properly
1307 user = User.find(users(:normal_user).id)
1308 assert_equal "user_1", user.display_name
1309 assert_equal "", user.description
1310 assert_nil user.home_lat
1311 assert_nil user.home_lon
1312 assert_equal false, user.image.file?
1313 assert_equal false, user.email_valid
1314 assert_nil user.new_email
1315 assert_nil user.auth_provider
1316 assert_nil user.auth_uid
1317 assert_equal "deleted", user.status
1321 # Shouldn't work when not logged in
1323 assert_response :redirect
1324 assert_redirected_to :action => :login, :referer => users_path
1326 session[:user] = users(:normal_user).id
1328 # Shouldn't work when logged in as a normal user
1330 assert_response :redirect
1331 assert_redirected_to :action => :login, :referer => users_path
1333 session[:user] = users(:moderator_user).id
1335 # Shouldn't work when logged in as a moderator
1337 assert_response :redirect
1338 assert_redirected_to :action => :login, :referer => users_path
1340 session[:user] = users(:administrator_user).id
1342 # Should work when logged in as an administrator
1344 assert_response :success
1345 assert_template :list
1346 assert_select "table#user_list tr", :count => User.count + 1
1348 # Should be able to limit by status
1349 get :list, :status => "suspended"
1350 assert_response :success
1351 assert_template :list
1352 assert_select "table#user_list tr", :count => User.where(:status => "suspended").count + 1
1354 # Should be able to limit by IP address
1355 get :list, :ip => "1.2.3.4"
1356 assert_response :success
1357 assert_template :list
1358 assert_select "table#user_list tr", :count => User.where(:creation_ip => "1.2.3.4").count + 1
1361 def test_list_get_paginated
1362 1.upto(100).each do |n|
1363 User.create(:display_name => "extra_#{n}",
1364 :email => "extra#{n}@example.com",
1365 :pass_crypt => "extraextra")
1368 session[:user] = users(:administrator_user).id
1371 assert_response :success
1372 assert_template :list
1373 assert_select "table#user_list tr", :count => 51
1375 get :list, :page => 2
1376 assert_response :success
1377 assert_template :list
1378 assert_select "table#user_list tr", :count => 51
1380 get :list, :page => 3
1381 assert_response :success
1382 assert_template :list
1383 assert_select "table#user_list tr", :count => 25
1386 def test_list_post_confirm
1387 inactive_user = users(:inactive_user)
1388 suspended_user = users(:suspended_user)
1390 # Shouldn't work when not logged in
1391 assert_no_difference "User.active.count" do
1392 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1394 assert_response :redirect
1395 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1396 assert_equal "pending", inactive_user.reload.status
1397 assert_equal "suspended", suspended_user.reload.status
1399 session[:user] = users(:normal_user).id
1401 # Shouldn't work when logged in as a normal user
1402 assert_no_difference "User.active.count" do
1403 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1405 assert_response :redirect
1406 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1407 assert_equal "pending", inactive_user.reload.status
1408 assert_equal "suspended", suspended_user.reload.status
1410 session[:user] = users(:moderator_user).id
1412 # Shouldn't work when logged in as a moderator
1413 assert_no_difference "User.active.count" do
1414 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1416 assert_response :redirect
1417 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1418 assert_equal "pending", inactive_user.reload.status
1419 assert_equal "suspended", suspended_user.reload.status
1421 session[:user] = users(:administrator_user).id
1423 # Should work when logged in as an administrator
1424 assert_difference "User.active.count", 2 do
1425 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1427 assert_response :redirect
1428 assert_redirected_to :action => :list
1429 assert_equal "confirmed", inactive_user.reload.status
1430 assert_equal "confirmed", suspended_user.reload.status
1433 def test_list_post_hide
1434 normal_user = users(:normal_user)
1435 confirmed_user = users(:confirmed_user)
1437 # Shouldn't work when not logged in
1438 assert_no_difference "User.active.count" do
1439 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1441 assert_response :redirect
1442 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1443 assert_equal "active", normal_user.reload.status
1444 assert_equal "confirmed", confirmed_user.reload.status
1446 session[:user] = users(:normal_user).id
1448 # Shouldn't work when logged in as a normal user
1449 assert_no_difference "User.active.count" do
1450 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1452 assert_response :redirect
1453 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1454 assert_equal "active", normal_user.reload.status
1455 assert_equal "confirmed", confirmed_user.reload.status
1457 session[:user] = users(:moderator_user).id
1459 # Shouldn't work when logged in as a moderator
1460 assert_no_difference "User.active.count" do
1461 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1463 assert_response :redirect
1464 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1465 assert_equal "active", normal_user.reload.status
1466 assert_equal "confirmed", confirmed_user.reload.status
1468 session[:user] = users(:administrator_user).id
1470 # Should work when logged in as an administrator
1471 assert_difference "User.active.count", -2 do
1472 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1474 assert_response :redirect
1475 assert_redirected_to :action => :list
1476 assert_equal "deleted", normal_user.reload.status
1477 assert_equal "deleted", confirmed_user.reload.status
1484 user.status = "pending"
1485 user.display_name = "new_tester"
1486 user.email = "newtester@osm.org"
1487 user.email_confirmation = "newtester@osm.org"
1488 user.pass_crypt = "testtest"
1489 user.pass_crypt_confirmation = "testtest"