3 class UserControllerTest < ActionController::TestCase
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 create(:user_block, :user => users(:blocked_user))
928 get :view, :display_name => "blocked"
929 assert_response :success
930 assert_select "div#userinformation" do
931 assert_select "a[href^='/user/blocked/history']", 1
932 assert_select "a[href='/user/blocked/traces']", 1
933 assert_select "a[href='/user/blocked/diary']", 1
934 assert_select "a[href='/user/blocked/diary/comments']", 1
935 assert_select "a[href='/user/blocked/account']", 0
936 assert_select "a[href='/user/blocked/blocks']", 1
937 assert_select "a[href='/user/blocked/blocks_by']", 0
938 assert_select "a[href='/blocks/new/blocked']", 0
941 # Test a moderator who has applied blocks
942 create(:user_block, :creator => users(:moderator_user))
943 get :view, :display_name => "moderator"
944 assert_response :success
945 assert_select "div#userinformation" do
946 assert_select "a[href^='/user/moderator/history']", 1
947 assert_select "a[href='/user/moderator/traces']", 1
948 assert_select "a[href='/user/moderator/diary']", 1
949 assert_select "a[href='/user/moderator/diary/comments']", 1
950 assert_select "a[href='/user/moderator/account']", 0
951 assert_select "a[href='/user/moderator/blocks']", 0
952 assert_select "a[href='/user/moderator/blocks_by']", 1
953 assert_select "a[href='/blocks/new/moderator']", 0
956 # Login as a normal user
957 session[:user] = users(:normal_user).id
959 # Test the normal user
960 get :view, :display_name => "test"
961 assert_response :success
962 assert_select "div#userinformation" do
963 assert_select "a[href^='/user/test/history']", 1
964 assert_select "a[href='/traces/mine']", 1
965 assert_select "a[href='/user/test/diary']", 1
966 assert_select "a[href='/user/test/diary/comments']", 1
967 assert_select "a[href='/user/test/account']", 1
968 assert_select "a[href='/user/test/blocks']", 0
969 assert_select "a[href='/user/test/blocks_by']", 0
970 assert_select "a[href='/blocks/new/test']", 0
973 # Login as a moderator
974 session[:user] = users(:moderator_user).id
976 # Test the normal user
977 get :view, :display_name => "test"
978 assert_response :success
979 assert_select "div#userinformation" do
980 assert_select "a[href^='/user/test/history']", 1
981 assert_select "a[href='/user/test/traces']", 1
982 assert_select "a[href='/user/test/diary']", 1
983 assert_select "a[href='/user/test/diary/comments']", 1
984 assert_select "a[href='/user/test/account']", 0
985 assert_select "a[href='/user/test/blocks']", 0
986 assert_select "a[href='/user/test/blocks_by']", 0
987 assert_select "a[href='/blocks/new/test']", 1
992 # check that a visible user is returned properly
993 get :api_read, :id => users(:normal_user).id
994 assert_response :success
995 assert_equal "text/xml", response.content_type
997 # check the data that is returned
998 assert_select "description", :count => 1, :text => "test"
999 assert_select "contributor-terms", :count => 1 do
1000 assert_select "[agreed='true']"
1002 assert_select "img", :count => 0
1003 assert_select "roles", :count => 1 do
1004 assert_select "role", :count => 0
1006 assert_select "changesets", :count => 1 do
1007 assert_select "[count='0']"
1009 assert_select "traces", :count => 1 do
1010 assert_select "[count='0']"
1012 assert_select "blocks", :count => 1 do
1013 assert_select "received", :count => 1 do
1014 assert_select "[count='0'][active='0']"
1016 assert_select "issued", :count => 0
1019 # check that we aren't revealing private information
1020 assert_select "contributor-terms[pd]", false
1021 assert_select "home", false
1022 assert_select "languages", false
1023 assert_select "messages", false
1025 # check that a suspended user is not returned
1026 get :api_read, :id => users(:suspended_user).id
1027 assert_response :gone
1029 # check that a deleted user is not returned
1030 get :api_read, :id => users(:deleted_user).id
1031 assert_response :gone
1033 # check that a non-existent user is not returned
1034 get :api_read, :id => 0
1035 assert_response :not_found
1038 def test_api_details
1039 # check that nothing is returned when not logged in
1041 assert_response :unauthorized
1043 # check that we get a response when logged in
1044 basic_authorization(users(:normal_user).email, "test")
1046 assert_response :success
1047 assert_equal "text/xml", response.content_type
1049 # check the data that is returned
1050 assert_select "description", :count => 1, :text => "test"
1051 assert_select "contributor-terms", :count => 1 do
1052 assert_select "[agreed='true'][pd='false']"
1054 assert_select "img", :count => 0
1055 assert_select "roles", :count => 1 do
1056 assert_select "role", :count => 0
1058 assert_select "changesets", :count => 1 do
1059 assert_select "[count='0']", :count => 1
1061 assert_select "traces", :count => 1 do
1062 assert_select "[count='0']", :count => 1
1064 assert_select "blocks", :count => 1 do
1065 assert_select "received", :count => 1 do
1066 assert_select "[count='0'][active='0']"
1068 assert_select "issued", :count => 0
1070 assert_select "home", :count => 1 do
1071 assert_select "[lat='12.1'][lon='12.1'][zoom='3']"
1073 assert_select "languages", :count => 1 do
1074 assert_select "lang", :count => 1, :text => "en"
1076 assert_select "messages", :count => 1 do
1077 assert_select "received", :count => 1 do
1078 assert_select "[count='1'][unread='0']"
1080 assert_select "sent", :count => 1 do
1081 assert_select "[count='1']"
1086 def test_api_gpx_files
1087 # check that nothing is returned when not logged in
1089 assert_response :unauthorized
1091 # check that we get a response when logged in
1092 basic_authorization(users(:normal_user).email, "test")
1094 assert_response :success
1095 assert_equal "text/xml", response.content_type
1097 # check the data that is returned
1098 assert_select "gpx_file[id='1']", 1 do
1099 assert_select "tag", "London"
1101 assert_select "gpx_file[id='4']", 1 do
1102 assert_select "tag", "Birmingham"
1106 def test_make_friend
1107 # Get users to work with
1108 user = users(:normal_user)
1109 friend = users(:second_public_user)
1111 # Check that the users aren't already friends
1112 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1114 # When not logged in a GET should ask us to login
1115 get :make_friend, :display_name => friend.display_name
1116 assert_redirected_to :controller => :user, :action => "login", :referer => make_friend_path(:display_name => friend.display_name)
1118 # When not logged in a POST should error
1119 post :make_friend, :display_name => friend.display_name
1120 assert_response :forbidden
1121 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1123 # When logged in a GET should get a confirmation page
1124 get :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1125 assert_response :success
1126 assert_template :make_friend
1127 assert_select "form" do
1128 assert_select "input[type='hidden'][name='referer']", 0
1129 assert_select "input[type='submit']", 1
1131 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1133 # When logged in a POST should add the friendship
1134 assert_difference "ActionMailer::Base.deliveries.size", 1 do
1135 post :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1137 assert_redirected_to user_path(:display_name => friend.display_name)
1138 assert_match /is now your friend/, flash[:notice]
1139 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1140 email = ActionMailer::Base.deliveries.first
1141 assert_equal 1, email.to.count
1142 assert_equal friend.email, email.to.first
1143 ActionMailer::Base.deliveries.clear
1145 # A second POST should report that the friendship already exists
1146 assert_no_difference "ActionMailer::Base.deliveries.size" do
1147 post :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1149 assert_redirected_to user_path(:display_name => friend.display_name)
1150 assert_match /You are already friends with/, flash[:warning]
1151 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1154 def test_make_friend_with_referer
1155 # Get users to work with
1156 user = users(:normal_user)
1157 friend = users(:second_public_user)
1159 # Check that the users aren't already friends
1160 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1162 # The GET should preserve any referer
1163 get :make_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1164 assert_response :success
1165 assert_template :make_friend
1166 assert_select "form" do
1167 assert_select "input[type='hidden'][name='referer'][value='/test']", 1
1168 assert_select "input[type='submit']", 1
1170 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1172 # When logged in a POST should add the friendship and refer us
1173 assert_difference "ActionMailer::Base.deliveries.size", 1 do
1174 post :make_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1176 assert_redirected_to "/test"
1177 assert_match /is now your friend/, flash[:notice]
1178 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1179 email = ActionMailer::Base.deliveries.first
1180 assert_equal 1, email.to.count
1181 assert_equal friend.email, email.to.first
1182 ActionMailer::Base.deliveries.clear
1185 def test_make_friend_unkown_user
1186 # Should error when a bogus user is specified
1187 get :make_friend, { :display_name => "No Such User" }, { :user => users(:normal_user).id }
1188 assert_response :not_found
1189 assert_template :no_such_user
1192 def test_remove_friend
1193 # Get users to work with
1194 user = users(:normal_user)
1195 friend = users(:public_user)
1196 create(:friend, :befriender => user, :befriendee => friend)
1198 # Check that the users are friends
1199 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1201 # When not logged in a GET should ask us to login
1202 get :remove_friend, :display_name => friend.display_name
1203 assert_redirected_to :controller => :user, :action => "login", :referer => remove_friend_path(:display_name => friend.display_name)
1205 # When not logged in a POST should error
1206 post :remove_friend, :display_name => friend.display_name
1207 assert_response :forbidden
1208 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1210 # When logged in a GET should get a confirmation page
1211 get :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1212 assert_response :success
1213 assert_template :remove_friend
1214 assert_select "form" do
1215 assert_select "input[type='hidden'][name='referer']", 0
1216 assert_select "input[type='submit']", 1
1218 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1220 # When logged in a POST should remove the friendship
1221 post :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1222 assert_redirected_to user_path(:display_name => friend.display_name)
1223 assert_match /was removed from your friends/, flash[:notice]
1224 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1226 # A second POST should report that the friendship does not exist
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 /is not one of your friends/, flash[:error]
1230 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1233 def test_remove_friend_with_referer
1234 # Get users to work with
1235 user = users(:normal_user)
1236 friend = users(:public_user)
1237 create(:friend, :user_id => user.id, :friend_user_id => friend.id)
1239 # Check that the users are friends
1240 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1242 # The GET should preserve any referer
1243 get :remove_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1244 assert_response :success
1245 assert_template :remove_friend
1246 assert_select "form" do
1247 assert_select "input[type='hidden'][name='referer'][value='/test']", 1
1248 assert_select "input[type='submit']", 1
1250 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1252 # When logged in a POST should remove the friendship and refer
1253 post :remove_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1254 assert_redirected_to "/test"
1255 assert_match /was removed from your friends/, flash[:notice]
1256 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1259 def test_remove_friend_unkown_user
1260 # Should error when a bogus user is specified
1261 get :remove_friend, { :display_name => "No Such User" }, { :user => users(:normal_user).id }
1262 assert_response :not_found
1263 assert_template :no_such_user
1267 # Try without logging in
1268 get :set_status, :display_name => users(:normal_user).display_name, :status => "suspended"
1269 assert_response :redirect
1270 assert_redirected_to :action => :login, :referer => set_status_user_path(:status => "suspended")
1272 # Now try as a normal user
1273 get :set_status, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:normal_user).id }
1274 assert_response :redirect
1275 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1277 # Finally try as an administrator
1278 get :set_status, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:administrator_user).id }
1279 assert_response :redirect
1280 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1281 assert_equal "suspended", User.find(users(:normal_user).id).status
1285 # Try without logging in
1286 get :delete, :display_name => users(:normal_user).display_name, :status => "suspended"
1287 assert_response :redirect
1288 assert_redirected_to :action => :login, :referer => delete_user_path(:status => "suspended")
1290 # Now try as a normal user
1291 get :delete, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:normal_user).id }
1292 assert_response :redirect
1293 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1295 # Finally try as an administrator
1296 get :delete, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:administrator_user).id }
1297 assert_response :redirect
1298 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1300 # Check that the user was deleted properly
1301 user = User.find(users(:normal_user).id)
1302 assert_equal "user_1", user.display_name
1303 assert_equal "", user.description
1304 assert_nil user.home_lat
1305 assert_nil user.home_lon
1306 assert_equal false, user.image.file?
1307 assert_equal false, user.email_valid
1308 assert_nil user.new_email
1309 assert_nil user.auth_provider
1310 assert_nil user.auth_uid
1311 assert_equal "deleted", user.status
1315 # Shouldn't work when not logged in
1317 assert_response :redirect
1318 assert_redirected_to :action => :login, :referer => users_path
1320 session[:user] = users(:normal_user).id
1322 # Shouldn't work when logged in as a normal user
1324 assert_response :redirect
1325 assert_redirected_to :action => :login, :referer => users_path
1327 session[:user] = users(:moderator_user).id
1329 # Shouldn't work when logged in as a moderator
1331 assert_response :redirect
1332 assert_redirected_to :action => :login, :referer => users_path
1334 session[:user] = users(:administrator_user).id
1336 # Should work when logged in as an administrator
1338 assert_response :success
1339 assert_template :list
1340 assert_select "table#user_list tr", :count => User.count + 1
1342 # Should be able to limit by status
1343 get :list, :status => "suspended"
1344 assert_response :success
1345 assert_template :list
1346 assert_select "table#user_list tr", :count => User.where(:status => "suspended").count + 1
1348 # Should be able to limit by IP address
1349 get :list, :ip => "1.2.3.4"
1350 assert_response :success
1351 assert_template :list
1352 assert_select "table#user_list tr", :count => User.where(:creation_ip => "1.2.3.4").count + 1
1355 def test_list_get_paginated
1356 1.upto(100).each do |n|
1357 User.create(:display_name => "extra_#{n}",
1358 :email => "extra#{n}@example.com",
1359 :pass_crypt => "extraextra")
1362 session[:user] = users(:administrator_user).id
1365 assert_response :success
1366 assert_template :list
1367 assert_select "table#user_list tr", :count => 51
1369 get :list, :page => 2
1370 assert_response :success
1371 assert_template :list
1372 assert_select "table#user_list tr", :count => 51
1374 get :list, :page => 3
1375 assert_response :success
1376 assert_template :list
1377 assert_select "table#user_list tr", :count => 25
1380 def test_list_post_confirm
1381 inactive_user = users(:inactive_user)
1382 suspended_user = users(:suspended_user)
1384 # Shouldn't work when not logged in
1385 assert_no_difference "User.active.count" do
1386 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1388 assert_response :redirect
1389 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1390 assert_equal "pending", inactive_user.reload.status
1391 assert_equal "suspended", suspended_user.reload.status
1393 session[:user] = users(:normal_user).id
1395 # Shouldn't work when logged in as a normal user
1396 assert_no_difference "User.active.count" do
1397 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1399 assert_response :redirect
1400 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1401 assert_equal "pending", inactive_user.reload.status
1402 assert_equal "suspended", suspended_user.reload.status
1404 session[:user] = users(:moderator_user).id
1406 # Shouldn't work when logged in as a moderator
1407 assert_no_difference "User.active.count" do
1408 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1410 assert_response :redirect
1411 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1412 assert_equal "pending", inactive_user.reload.status
1413 assert_equal "suspended", suspended_user.reload.status
1415 session[:user] = users(:administrator_user).id
1417 # Should work when logged in as an administrator
1418 assert_difference "User.active.count", 2 do
1419 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1421 assert_response :redirect
1422 assert_redirected_to :action => :list
1423 assert_equal "confirmed", inactive_user.reload.status
1424 assert_equal "confirmed", suspended_user.reload.status
1427 def test_list_post_hide
1428 normal_user = users(:normal_user)
1429 confirmed_user = users(:confirmed_user)
1431 # Shouldn't work when not logged in
1432 assert_no_difference "User.active.count" do
1433 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1435 assert_response :redirect
1436 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1437 assert_equal "active", normal_user.reload.status
1438 assert_equal "confirmed", confirmed_user.reload.status
1440 session[:user] = users(:normal_user).id
1442 # Shouldn't work when logged in as a normal user
1443 assert_no_difference "User.active.count" do
1444 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1446 assert_response :redirect
1447 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1448 assert_equal "active", normal_user.reload.status
1449 assert_equal "confirmed", confirmed_user.reload.status
1451 session[:user] = users(:moderator_user).id
1453 # Shouldn't work when logged in as a moderator
1454 assert_no_difference "User.active.count" do
1455 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1457 assert_response :redirect
1458 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1459 assert_equal "active", normal_user.reload.status
1460 assert_equal "confirmed", confirmed_user.reload.status
1462 session[:user] = users(:administrator_user).id
1464 # Should work when logged in as an administrator
1465 assert_difference "User.active.count", -2 do
1466 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1468 assert_response :redirect
1469 assert_redirected_to :action => :list
1470 assert_equal "deleted", normal_user.reload.status
1471 assert_equal "deleted", confirmed_user.reload.status
1478 user.status = "pending"
1479 user.display_name = "new_tester"
1480 user.email = "newtester@osm.org"
1481 user.email_confirmation = "newtester@osm.org"
1482 user.pass_crypt = "testtest"
1483 user.pass_crypt_confirmation = "testtest"