3 class UserControllerTest < ActionController::TestCase
11 # test all routes which lead to this controller
14 { :path => "/api/0.6/user/1", :method => :get },
15 { :controller => "user", :action => "api_read", :id => "1" }
18 { :path => "/api/0.6/user/details", :method => :get },
19 { :controller => "user", :action => "api_details" }
22 { :path => "/api/0.6/user/gpx_files", :method => :get },
23 { :controller => "user", :action => "api_gpx_files" }
27 { :path => "/login", :method => :get },
28 { :controller => "user", :action => "login" }
31 { :path => "/login", :method => :post },
32 { :controller => "user", :action => "login" }
35 { :controller => "user", :action => "login", :format => "html" },
36 { :path => "/login.html", :method => :get }
40 { :path => "/logout", :method => :get },
41 { :controller => "user", :action => "logout" }
44 { :path => "/logout", :method => :post },
45 { :controller => "user", :action => "logout" }
48 { :controller => "user", :action => "logout", :format => "html" },
49 { :path => "/logout.html", :method => :get }
53 { :path => "/user/new", :method => :get },
54 { :controller => "user", :action => "new" }
58 { :path => "/user/new", :method => :post },
59 { :controller => "user", :action => "create" }
63 { :path => "/user/terms", :method => :get },
64 { :controller => "user", :action => "terms" }
68 { :path => "/user/save", :method => :post },
69 { :controller => "user", :action => "save" }
73 { :path => "/user/username/confirm", :method => :get },
74 { :controller => "user", :action => "confirm", :display_name => "username" }
77 { :path => "/user/username/confirm", :method => :post },
78 { :controller => "user", :action => "confirm", :display_name => "username" }
81 { :path => "/user/username/confirm/resend", :method => :get },
82 { :controller => "user", :action => "confirm_resend", :display_name => "username" }
86 { :path => "/user/confirm", :method => :get },
87 { :controller => "user", :action => "confirm" }
90 { :path => "/user/confirm", :method => :post },
91 { :controller => "user", :action => "confirm" }
94 { :path => "/user/confirm-email", :method => :get },
95 { :controller => "user", :action => "confirm_email" }
98 { :path => "/user/confirm-email", :method => :post },
99 { :controller => "user", :action => "confirm_email" }
103 { :path => "/user/go_public", :method => :post },
104 { :controller => "user", :action => "go_public" }
108 { :path => "/user/forgot-password", :method => :get },
109 { :controller => "user", :action => "lost_password" }
112 { :path => "/user/forgot-password", :method => :post },
113 { :controller => "user", :action => "lost_password" }
116 { :path => "/user/reset-password", :method => :get },
117 { :controller => "user", :action => "reset_password" }
120 { :path => "/user/reset-password", :method => :post },
121 { :controller => "user", :action => "reset_password" }
125 { :path => "/user/suspended", :method => :get },
126 { :controller => "user", :action => "suspended" }
130 { :path => "/user/username", :method => :get },
131 { :controller => "user", :action => "view", :display_name => "username" }
135 { :path => "/user/username/account", :method => :get },
136 { :controller => "user", :action => "account", :display_name => "username" }
139 { :path => "/user/username/account", :method => :post },
140 { :controller => "user", :action => "account", :display_name => "username" }
144 { :path => "/user/username/make_friend", :method => :get },
145 { :controller => "user", :action => "make_friend", :display_name => "username" }
148 { :path => "/user/username/make_friend", :method => :post },
149 { :controller => "user", :action => "make_friend", :display_name => "username" }
152 { :path => "/user/username/remove_friend", :method => :get },
153 { :controller => "user", :action => "remove_friend", :display_name => "username" }
156 { :path => "/user/username/remove_friend", :method => :post },
157 { :controller => "user", :action => "remove_friend", :display_name => "username" }
161 { :path => "/user/username/set_status", :method => :get },
162 { :controller => "user", :action => "set_status", :display_name => "username" }
165 { :path => "/user/username/delete", :method => :get },
166 { :controller => "user", :action => "delete", :display_name => "username" }
170 { :path => "/users", :method => :get },
171 { :controller => "user", :action => "list" }
174 { :path => "/users", :method => :post },
175 { :controller => "user", :action => "list" }
178 { :path => "/users/status", :method => :get },
179 { :controller => "user", :action => "list", :status => "status" }
182 { :path => "/users/status", :method => :post },
183 { :controller => "user", :action => "list", :status => "status" }
187 # The user creation page loads
190 assert_response :redirect
191 assert_redirected_to user_new_path(:cookie_test => "true")
193 get :new, { :cookie_test => "true" }, { :cookie_test => true }
194 assert_response :success
196 assert_select "html", :count => 1 do
197 assert_select "head", :count => 1 do
198 assert_select "title", :text => /Sign Up/, :count => 1
200 assert_select "body", :count => 1 do
201 assert_select "div#content", :count => 1 do
202 assert_select "form[action='/user/new'][method='post']", :count => 1 do
203 assert_select "input[id='user_email']", :count => 1
204 assert_select "input[id='user_email_confirmation']", :count => 1
205 assert_select "input[id='user_display_name']", :count => 1
206 assert_select "input[id='user_pass_crypt'][type='password']", :count => 1
207 assert_select "input[id='user_pass_crypt_confirmation'][type='password']", :count => 1
208 assert_select "input[type='submit'][value='Sign Up']", :count => 1
215 def test_new_view_logged_in
216 session[:user] = users(:normal_user).id
219 assert_response :redirect
220 assert_redirected_to user_new_path(:cookie_test => "true")
221 get :new, :cookie_test => "true"
222 assert_response :redirect
223 assert_redirected_to root_path
225 get :new, :referer => "/test"
226 assert_response :redirect
227 assert_redirected_to user_new_path(:referer => "/test", :cookie_test => "true")
228 get :new, :referer => "/test", :cookie_test => "true"
229 assert_response :redirect
230 assert_redirected_to "/test"
236 assert_difference "User.count", 1 do
237 assert_difference "ActionMailer::Base.deliveries.size", 1 do
238 post :save, {}, { :new_user => user }
243 register_email = ActionMailer::Base.deliveries.first
245 assert_equal register_email.to[0], user.email
246 assert_match /#{@url}/, register_email.body.to_s
249 assert_redirected_to :action => "confirm", :display_name => user.display_name
251 ActionMailer::Base.deliveries.clear
254 def test_new_duplicate_email
256 user.email = users(:public_user).email
258 assert_no_difference "User.count" do
259 assert_no_difference "ActionMailer::Base.deliveries.size" do
260 post :save, {}, { :new_user => user }
264 assert_response :success
265 assert_template "new"
266 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
269 def test_new_duplicate_email_uppercase
271 user.email = users(:public_user).email.upcase
273 assert_no_difference "User.count" do
274 assert_no_difference "ActionMailer::Base.deliveries.size" do
275 post :save, {}, { :new_user => user }
279 assert_response :success
280 assert_template "new"
281 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
284 def test_new_duplicate_name
286 user.display_name = users(:public_user).display_name
288 assert_no_difference "User.count" do
289 assert_no_difference "ActionMailer::Base.deliveries.size" do
290 post :save, {}, { :new_user => user }
294 assert_response :success
295 assert_template "new"
296 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
299 def test_new_duplicate_name_uppercase
301 user.display_name = users(:public_user).display_name.upcase
303 assert_no_difference "User.count" do
304 assert_no_difference "ActionMailer::Base.deliveries.size" do
305 post :save, {}, { :new_user => user }
309 assert_response :success
310 assert_template "new"
311 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
314 def test_save_referer_params
317 assert_difference "User.count", 1 do
318 assert_difference "ActionMailer::Base.deliveries.size", 1 do
319 post :save, {}, { :new_user => user,
320 :referer => "/edit?editor=id#map=1/2/3" }
324 assert_equal welcome_path(:editor => "id", :zoom => 1, :lat => 2, :lon => 3),
325 user.tokens.order("id DESC").first.referer
327 ActionMailer::Base.deliveries.clear
330 def test_logout_without_referer
332 assert_response :success
333 assert_template :logout
334 assert_select "input[name=referer][value=?]", ""
336 session_id = assert_select("input[name=session]").first["value"]
338 get :logout, :session => session_id
339 assert_response :redirect
340 assert_redirected_to root_path
343 def test_logout_with_referer
344 get :logout, :referer => "/test"
345 assert_response :success
346 assert_template :logout
347 assert_select "input[name=referer][value=?]", "/test"
349 session_id = assert_select("input[name=session]").first["value"]
351 get :logout, :session => session_id, :referer => "/test"
352 assert_response :redirect
353 assert_redirected_to "/test"
356 def test_logout_with_token
357 token = users(:normal_user).tokens.create
359 session[:token] = token.token
362 assert_response :success
363 assert_template :logout
364 assert_select "input[name=referer][value=?]", ""
365 assert_equal token.token, session[:token]
366 assert_not_nil UserToken.where(:id => token.id).first
368 session_id = assert_select("input[name=session]").first["value"]
370 get :logout, :session => session_id
371 assert_response :redirect
372 assert_redirected_to root_path
373 assert_nil session[:token]
374 assert_nil UserToken.where(:id => token.id).first
378 user = users(:inactive_user)
379 confirm_string = user.tokens.create.token
381 @request.cookies["_osm_session"] = user.display_name
382 get :confirm, :display_name => user.display_name, :confirm_string => confirm_string
383 assert_response :success
384 assert_template :confirm
387 def test_confirm_get_already_confirmed
388 user = users(:normal_user)
389 confirm_string = user.tokens.create.token
391 @request.cookies["_osm_session"] = user.display_name
392 get :confirm, :display_name => user.display_name, :confirm_string => confirm_string
393 assert_response :redirect
394 assert_redirected_to root_path
397 def test_confirm_success_no_token_no_referer
398 user = users(:inactive_user)
399 stub_gravatar_request(user.email)
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 stub_gravatar_request(user.email)
411 confirm_string = user.tokens.create.token
412 token = user.tokens.create.token
414 @request.cookies["_osm_session"] = user.display_name
415 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
416 assert_redirected_to welcome_path
419 def test_confirm_success_bad_token_no_referer
420 user = users(:inactive_user)
421 stub_gravatar_request(user.email)
422 confirm_string = user.tokens.create.token
423 token = users(:normal_user).tokens.create.token
425 @request.cookies["_osm_session"] = user.display_name
426 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
427 assert_redirected_to login_path
428 assert_match /Confirmed your account/, flash[:notice]
431 def test_confirm_success_no_token_with_referer
432 user = users(:inactive_user)
433 stub_gravatar_request(user.email)
434 confirm_string = user.tokens.create(:referer => diary_new_path).token
436 @request.cookies["_osm_session"] = user.display_name
437 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
438 assert_redirected_to login_path(:referer => diary_new_path)
439 assert_match /Confirmed your account/, flash[:notice]
442 def test_confirm_success_good_token_with_referer
443 user = users(:inactive_user)
444 stub_gravatar_request(user.email)
445 confirm_string = user.tokens.create(:referer => diary_new_path).token
446 token = user.tokens.create.token
448 @request.cookies["_osm_session"] = user.display_name
449 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
450 assert_redirected_to diary_new_path
453 def test_confirm_success_bad_token_with_referer
454 user = users(:inactive_user)
455 stub_gravatar_request(user.email)
456 confirm_string = user.tokens.create(:referer => diary_new_path).token
457 token = users(:normal_user).tokens.create.token
459 @request.cookies["_osm_session"] = user.display_name
460 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
461 assert_redirected_to login_path(:referer => diary_new_path)
462 assert_match /Confirmed your account/, flash[:notice]
465 def test_confirm_expired_token
466 user = users(:inactive_user)
467 confirm_string = user.tokens.create(:expiry => 1.day.ago).token
469 @request.cookies["_osm_session"] = user.display_name
470 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
471 assert_redirected_to :action => "confirm"
472 assert_match /confirmation code has expired/, flash[:error]
475 def test_confirm_already_confirmed
476 user = users(:normal_user)
477 confirm_string = user.tokens.create(:referer => diary_new_path).token
479 @request.cookies["_osm_session"] = user.display_name
480 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
481 assert_redirected_to :action => "login"
482 assert_match /already been confirmed/, flash[:error]
485 def test_confirm_resend_success
486 session[:token] = users(:inactive_user).tokens.create.token
488 assert_difference "ActionMailer::Base.deliveries.size", 1 do
489 get :confirm_resend, :display_name => users(:inactive_user).display_name
492 assert_response :redirect
493 assert_redirected_to login_path
494 assert_match /sent a new confirmation/, flash[:notice]
496 email = ActionMailer::Base.deliveries.last
498 assert_equal users(:inactive_user).email, email.to.first
500 ActionMailer::Base.deliveries.clear
503 def test_confirm_resend_no_token
504 assert_no_difference "ActionMailer::Base.deliveries.size" do
505 get :confirm_resend, :display_name => users(:inactive_user).display_name
508 assert_response :redirect
509 assert_redirected_to login_path
510 assert_match "User Inactive User not found.", flash[:error]
513 def test_confirm_resend_unknown_user
514 assert_no_difference "ActionMailer::Base.deliveries.size" do
515 get :confirm_resend, :display_name => "No Such User"
518 assert_response :redirect
519 assert_redirected_to login_path
520 assert_match "User No Such User not found.", flash[:error]
523 def test_confirm_email_get
524 user = users(:normal_user)
525 confirm_string = user.tokens.create.token
527 get :confirm_email, :confirm_string => confirm_string
528 assert_response :success
529 assert_template :confirm_email
532 def test_confirm_email_success
533 user = users(:second_public_user)
534 stub_gravatar_request(user.new_email)
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 /Confirmed your change of email address/, flash[:notice]
543 def test_confirm_email_already_confirmed
544 user = users(:normal_user)
545 confirm_string = user.tokens.create.token
547 post :confirm_email, :confirm_string => confirm_string
548 assert_response :redirect
549 assert_redirected_to :action => :account, :display_name => user.display_name
550 assert_match /already been confirmed/, flash[:error]
553 def test_confirm_email_bad_token
554 post :confirm_email, :confirm_string => "XXXXX"
555 assert_response :success
556 assert_template :confirm_email
557 assert_match /confirmation code has expired or does not exist/, flash[:error]
561 # test if testing for a gravatar works
562 # this happens when the email is actually changed
563 # which is triggered by the confirmation mail
564 def test_gravatar_auto_enable
565 # switch to email that has a gravatar
566 user = users(:first_gravatar_user)
567 stub_gravatar_request(user.new_email, 200)
568 confirm_string = user.tokens.create.token
569 # precondition gravatar should be turned off
570 assert !user.image_use_gravatar
571 post :confirm_email, :confirm_string => confirm_string
572 assert_response :redirect
573 assert_redirected_to :action => :account, :display_name => user.display_name
574 assert_match /Confirmed your change of email address/, flash[:notice]
575 # gravatar use should now be enabled
576 assert User.find(users(:first_gravatar_user).id).image_use_gravatar
579 def test_gravatar_auto_disable
580 # switch to email without a gravatar
581 user = users(:second_gravatar_user)
582 stub_gravatar_request(user.new_email, 404)
583 confirm_string = user.tokens.create.token
584 # precondition gravatar should be turned on
585 assert user.image_use_gravatar
586 post :confirm_email, :confirm_string => confirm_string
587 assert_response :redirect
588 assert_redirected_to :action => :account, :display_name => user.display_name
589 assert_match /Confirmed your change of email address/, flash[:notice]
590 # gravatar use should now be disabled
591 assert !User.find(users(:second_gravatar_user).id).image_use_gravatar
594 def test_terms_new_user
595 get :terms, {}, { :new_user => User.new }
596 assert_response :success
597 assert_template :terms
601 user = users(:normal_user)
603 session[:user] = user.id
606 assert_response :redirect
607 assert_redirected_to :action => :account, :display_name => user.display_name
610 def test_terms_not_seen_without_referer
611 user = users(:terms_not_seen_user)
613 session[:user] = user.id
616 assert_response :success
617 assert_template :terms
619 post :save, :user => { :consider_pd => true }
620 assert_response :redirect
621 assert_redirected_to :action => :account, :display_name => user.display_name
622 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
626 assert_equal true, user.consider_pd
627 assert_not_nil user.terms_agreed
628 assert_equal true, user.terms_seen
631 def test_terms_not_seen_with_referer
632 user = users(:terms_not_seen_user)
634 session[:user] = user.id
636 get :terms, :referer => "/test"
637 assert_response :success
638 assert_template :terms
640 post :save, :user => { :consider_pd => true }, :referer => "/test"
641 assert_response :redirect
642 assert_redirected_to "/test"
643 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
647 assert_equal true, user.consider_pd
648 assert_not_nil user.terms_agreed
649 assert_equal true, user.terms_seen
653 post :go_public, {}, { :user => users(:normal_user) }
654 assert_response :redirect
655 assert_redirected_to :action => :account, :display_name => users(:normal_user).display_name
656 assert_equal true, User.find(users(:normal_user).id).data_public
659 def test_lost_password
660 # Test fetching the lost password page
662 assert_response :success
663 assert_template :lost_password
664 assert_select "div#notice", false
666 # Test resetting using the address as recorded for a user that has an
667 # address which is duplicated in a different case by another user
668 assert_difference "ActionMailer::Base.deliveries.size", 1 do
669 post :lost_password, :user => { :email => users(:normal_user).email }
671 assert_response :redirect
672 assert_redirected_to :action => :login
673 assert_match /^Sorry you lost it/, flash[:notice]
674 email = ActionMailer::Base.deliveries.first
675 assert_equal 1, email.to.count
676 assert_equal users(:normal_user).email, email.to.first
677 ActionMailer::Base.deliveries.clear
679 # Test resetting using an address that matches a different user
680 # that has the same address in a different case
681 assert_difference "ActionMailer::Base.deliveries.size", 1 do
682 post :lost_password, :user => { :email => users(:normal_user).email.upcase }
684 assert_response :redirect
685 assert_redirected_to :action => :login
686 assert_match /^Sorry you lost it/, flash[:notice]
687 email = ActionMailer::Base.deliveries.first
688 assert_equal 1, email.to.count
689 assert_equal users(:uppercase_user).email, email.to.first
690 ActionMailer::Base.deliveries.clear
692 # Test resetting using an address that is a case insensitive match
693 # for more than one user but not an exact match for either
694 assert_no_difference "ActionMailer::Base.deliveries.size" do
695 post :lost_password, :user => { :email => users(:normal_user).email.titlecase }
697 assert_response :success
698 assert_template :lost_password
699 assert_select ".error", /^Could not find that email address/
701 # Test resetting using the address as recorded for a user that has an
702 # address which is case insensitively unique
703 assert_difference "ActionMailer::Base.deliveries.size", 1 do
704 post :lost_password, :user => { :email => users(:public_user).email }
706 assert_response :redirect
707 assert_redirected_to :action => :login
708 assert_match /^Sorry you lost it/, flash[:notice]
709 email = ActionMailer::Base.deliveries.first
710 assert_equal 1, email.to.count
711 assert_equal users(:public_user).email, email.to.first
712 ActionMailer::Base.deliveries.clear
714 # Test resetting using an address that matches a user that has the
715 # same (case insensitively unique) address in a different case
716 assert_difference "ActionMailer::Base.deliveries.size", 1 do
717 post :lost_password, :user => { :email => users(:public_user).email.upcase }
719 assert_response :redirect
720 assert_redirected_to :action => :login
721 assert_match /^Sorry you lost it/, flash[:notice]
722 email = ActionMailer::Base.deliveries.first
723 assert_equal 1, email.to.count
724 assert_equal users(:public_user).email, email.to.first
725 ActionMailer::Base.deliveries.clear
728 def test_reset_password
729 # Test a request with no token
731 assert_response :bad_request
733 # Test a request with a bogus token
734 get :reset_password, :token => "made_up_token"
735 assert_response :redirect
736 assert_redirected_to :action => :lost_password
738 # Create a valid token for a user
739 token = User.find(users(:inactive_user).id).tokens.create
741 # Test a request with a valid token
742 get :reset_password, :token => token.token
743 assert_response :success
744 assert_template :reset_password
746 # Test setting a new password
747 post :reset_password, :token => token.token, :user => { :pass_crypt => "new_password", :pass_crypt_confirmation => "new_password" }
748 assert_response :redirect
749 assert_redirected_to root_path
750 assert_equal users(:inactive_user).id, session[:user]
751 user = User.find(users(:inactive_user).id)
752 assert_equal "active", user.status
753 assert_equal true, user.email_valid
754 assert_equal user, User.authenticate(:username => "inactive@openstreetmap.org", :password => "new_password")
758 # Get a user to work with - note that this user deliberately
759 # conflicts with uppercase_user in the email and display name
760 # fields to test that we can change other fields without any
761 # validation errors being reported
762 user = users(:normal_user)
764 # Make sure that you are redirected to the login page when
765 # you are not logged in
766 get :account, :display_name => user.display_name
767 assert_response :redirect
768 assert_redirected_to :controller => :user, :action => "login", :referer => "/user/test/account"
770 # Make sure that you are blocked when not logged in as the right user
771 get :account, { :display_name => user.display_name }, { :user => users(:public_user).id }
772 assert_response :forbidden
774 # Make sure we get the page when we are logged in as the right user
775 get :account, { :display_name => user.display_name }, { :user => user }
776 assert_response :success
777 assert_template :account
779 # Updating the description should work
780 user.description = "new description"
781 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
782 assert_response :success
783 assert_template :account
784 assert_select "div#errorExplanation", false
785 assert_select ".notice", /^User information updated successfully/
786 assert_select "form#accountForm > fieldset > div.form-row > div#user_description_container > div#user_description_content > textarea#user_description", user.description
788 # Changing to a invalid editor should fail
789 user.preferred_editor = "unknown"
790 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
791 assert_response :success
792 assert_template :account
793 assert_select ".notice", false
794 assert_select "div#errorExplanation"
795 assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected]", false
797 # Changing to a valid editor should work
798 user.preferred_editor = "potlatch2"
799 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
800 assert_response :success
801 assert_template :account
802 assert_select "div#errorExplanation", false
803 assert_select ".notice", /^User information updated successfully/
804 assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected][value=?]", "potlatch2"
806 # Changing to the default editor should work
807 user.preferred_editor = "default"
808 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
809 assert_response :success
810 assert_template :account
811 assert_select "div#errorExplanation", false
812 assert_select ".notice", /^User information updated successfully/
813 assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected]", false
815 # Changing to an uploaded image should work
816 image = Rack::Test::UploadedFile.new("test/gpx/fixtures/a.gif", "image/gif")
817 post :account, { :display_name => user.display_name, :image_action => "new", :user => user.attributes.merge(:image => image) }, { :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=?]", "keep"
824 # Changing to a gravatar image should work
825 post :account, { :display_name => user.display_name, :image_action => "gravatar", :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][value=?]", "gravatar"
832 # Removing the image should work
833 post :account, { :display_name => user.display_name, :image_action => "delete", :user => user.attributes }, { :user => user.id }
834 assert_response :success
835 assert_template :account
836 assert_select "div#errorExplanation", false
837 assert_select ".notice", /^User information updated successfully/
838 assert_select "form#accountForm > fieldset > div.form-row.accountImage input[name=image_action][checked]", false
840 # Adding external authentication should redirect to the auth provider
841 post :account, { :display_name => user.display_name, :user => user.attributes.merge(:auth_provider => "openid", :auth_uid => "gmail.com") }, { :user => user.id }
842 assert_response :redirect
843 assert_redirected_to auth_path(:provider => "openid", :openid_url => "https://www.google.com/accounts/o8/id", :origin => "/user/#{user.display_name}/account")
845 # Changing name to one that exists should fail
846 new_attributes = user.attributes.dup.merge(:display_name => users(:public_user).display_name)
847 post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id }
848 assert_response :success
849 assert_template :account
850 assert_select ".notice", false
851 assert_select "div#errorExplanation"
852 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_display_name"
854 # Changing name to one that exists should fail, regardless of case
855 new_attributes = user.attributes.dup.merge(:display_name => users(:public_user).display_name.upcase)
856 post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id }
857 assert_response :success
858 assert_template :account
859 assert_select ".notice", false
860 assert_select "div#errorExplanation"
861 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_display_name"
863 # Changing name to one that doesn't exist should work
864 new_attributes = user.attributes.dup.merge(:display_name => "new tester")
865 post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id }
866 assert_response :success
867 assert_template :account
868 assert_select "div#errorExplanation", false
869 assert_select ".notice", /^User information updated successfully/
870 assert_select "form#accountForm > fieldset > div.form-row > input#user_display_name[value=?]", "new tester"
872 # Record the change of name
873 user.display_name = "new tester"
875 # Changing email to one that exists should fail
876 user.new_email = users(:public_user).email
877 assert_no_difference "ActionMailer::Base.deliveries.size" do
878 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
880 assert_response :success
881 assert_template :account
882 assert_select ".notice", false
883 assert_select "div#errorExplanation"
884 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_new_email"
886 # Changing email to one that exists should fail, regardless of case
887 user.new_email = users(:public_user).email.upcase
888 assert_no_difference "ActionMailer::Base.deliveries.size" do
889 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
891 assert_response :success
892 assert_template :account
893 assert_select ".notice", false
894 assert_select "div#errorExplanation"
895 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_new_email"
897 # Changing email to one that doesn't exist should work
898 user.new_email = "new_tester@example.com"
899 assert_difference "ActionMailer::Base.deliveries.size", 1 do
900 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
902 assert_response :success
903 assert_template :account
904 assert_select "div#errorExplanation", false
905 assert_select ".notice", /^User information updated successfully/
906 assert_select "form#accountForm > fieldset > div.form-row > input#user_new_email[value=?]", user.new_email
907 email = ActionMailer::Base.deliveries.first
908 assert_equal 1, email.to.count
909 assert_equal user.new_email, email.to.first
910 ActionMailer::Base.deliveries.clear
913 # Check that the user account page will display and contains some relevant
914 # information for the user
916 # Test a non-existent user
917 get :view, :display_name => "unknown"
918 assert_response :not_found
921 get :view, :display_name => "test"
922 assert_response :success
923 assert_select "div#userinformation" do
924 assert_select "a[href^='/user/test/history']", 1
925 assert_select "a[href='/user/test/traces']", 1
926 assert_select "a[href='/user/test/diary']", 1
927 assert_select "a[href='/user/test/diary/comments']", 1
928 assert_select "a[href='/user/test/account']", 0
929 assert_select "a[href='/user/test/blocks']", 0
930 assert_select "a[href='/user/test/blocks_by']", 0
931 assert_select "a[href='/blocks/new/test']", 0
934 # Test a user who has been blocked
935 create(:user_block, :user => users(:blocked_user))
936 get :view, :display_name => "blocked"
937 assert_response :success
938 assert_select "div#userinformation" do
939 assert_select "a[href^='/user/blocked/history']", 1
940 assert_select "a[href='/user/blocked/traces']", 1
941 assert_select "a[href='/user/blocked/diary']", 1
942 assert_select "a[href='/user/blocked/diary/comments']", 1
943 assert_select "a[href='/user/blocked/account']", 0
944 assert_select "a[href='/user/blocked/blocks']", 1
945 assert_select "a[href='/user/blocked/blocks_by']", 0
946 assert_select "a[href='/blocks/new/blocked']", 0
949 # Test a moderator who has applied blocks
950 create(:user_block, :creator => users(:moderator_user))
951 get :view, :display_name => "moderator"
952 assert_response :success
953 assert_select "div#userinformation" do
954 assert_select "a[href^='/user/moderator/history']", 1
955 assert_select "a[href='/user/moderator/traces']", 1
956 assert_select "a[href='/user/moderator/diary']", 1
957 assert_select "a[href='/user/moderator/diary/comments']", 1
958 assert_select "a[href='/user/moderator/account']", 0
959 assert_select "a[href='/user/moderator/blocks']", 0
960 assert_select "a[href='/user/moderator/blocks_by']", 1
961 assert_select "a[href='/blocks/new/moderator']", 0
964 # Login as a normal user
965 session[:user] = users(:normal_user).id
967 # Test the normal user
968 get :view, :display_name => "test"
969 assert_response :success
970 assert_select "div#userinformation" do
971 assert_select "a[href^='/user/test/history']", 1
972 assert_select "a[href='/traces/mine']", 1
973 assert_select "a[href='/user/test/diary']", 1
974 assert_select "a[href='/user/test/diary/comments']", 1
975 assert_select "a[href='/user/test/account']", 1
976 assert_select "a[href='/user/test/blocks']", 0
977 assert_select "a[href='/user/test/blocks_by']", 0
978 assert_select "a[href='/blocks/new/test']", 0
981 # Login as a moderator
982 session[:user] = users(:moderator_user).id
984 # Test the normal user
985 get :view, :display_name => "test"
986 assert_response :success
987 assert_select "div#userinformation" do
988 assert_select "a[href^='/user/test/history']", 1
989 assert_select "a[href='/user/test/traces']", 1
990 assert_select "a[href='/user/test/diary']", 1
991 assert_select "a[href='/user/test/diary/comments']", 1
992 assert_select "a[href='/user/test/account']", 0
993 assert_select "a[href='/user/test/blocks']", 0
994 assert_select "a[href='/user/test/blocks_by']", 0
995 assert_select "a[href='/blocks/new/test']", 1
1000 # check that a visible user is returned properly
1001 get :api_read, :id => users(:normal_user).id
1002 assert_response :success
1003 assert_equal "text/xml", response.content_type
1005 # check the data that is returned
1006 assert_select "description", :count => 1, :text => "test"
1007 assert_select "contributor-terms", :count => 1 do
1008 assert_select "[agreed='true']"
1010 assert_select "img", :count => 0
1011 assert_select "roles", :count => 1 do
1012 assert_select "role", :count => 0
1014 assert_select "changesets", :count => 1 do
1015 assert_select "[count='0']"
1017 assert_select "traces", :count => 1 do
1018 assert_select "[count='0']"
1020 assert_select "blocks", :count => 1 do
1021 assert_select "received", :count => 1 do
1022 assert_select "[count='0'][active='0']"
1024 assert_select "issued", :count => 0
1027 # check that we aren't revealing private information
1028 assert_select "contributor-terms[pd]", false
1029 assert_select "home", false
1030 assert_select "languages", false
1031 assert_select "messages", false
1033 # check that a suspended user is not returned
1034 get :api_read, :id => users(:suspended_user).id
1035 assert_response :gone
1037 # check that a deleted user is not returned
1038 get :api_read, :id => users(:deleted_user).id
1039 assert_response :gone
1041 # check that a non-existent user is not returned
1042 get :api_read, :id => 0
1043 assert_response :not_found
1046 def test_api_details
1047 create(:message, :read, :recipient => users(:normal_user))
1049 # check that nothing is returned when not logged in
1051 assert_response :unauthorized
1053 # check that we get a response when logged in
1054 basic_authorization(users(:normal_user).email, "test")
1056 assert_response :success
1057 assert_equal "text/xml", response.content_type
1059 # check the data that is returned
1060 assert_select "description", :count => 1, :text => "test"
1061 assert_select "contributor-terms", :count => 1 do
1062 assert_select "[agreed='true'][pd='false']"
1064 assert_select "img", :count => 0
1065 assert_select "roles", :count => 1 do
1066 assert_select "role", :count => 0
1068 assert_select "changesets", :count => 1 do
1069 assert_select "[count='0']", :count => 1
1071 assert_select "traces", :count => 1 do
1072 assert_select "[count='0']", :count => 1
1074 assert_select "blocks", :count => 1 do
1075 assert_select "received", :count => 1 do
1076 assert_select "[count='0'][active='0']"
1078 assert_select "issued", :count => 0
1080 assert_select "home", :count => 1 do
1081 assert_select "[lat='12.1'][lon='12.1'][zoom='3']"
1083 assert_select "languages", :count => 1 do
1084 assert_select "lang", :count => 1, :text => "en"
1086 assert_select "messages", :count => 1 do
1087 assert_select "received", :count => 1 do
1088 assert_select "[count='1'][unread='0']"
1090 assert_select "sent", :count => 1 do
1091 assert_select "[count='1']"
1096 def test_api_gpx_files
1097 trace1 = create(:trace, :user => users(:normal_user)) do |trace|
1098 create(:tracetag, :trace => trace, :tag => "London")
1100 trace2 = create(:trace, :user => users(:normal_user)) do |trace|
1101 create(:tracetag, :trace => trace, :tag => "Birmingham")
1103 # check that nothing is returned when not logged in
1105 assert_response :unauthorized
1107 # check that we get a response when logged in
1108 basic_authorization(users(:normal_user).email, "test")
1110 assert_response :success
1111 assert_equal "text/xml", response.content_type
1113 # check the data that is returned
1114 assert_select "gpx_file[id='#{trace1.id}']", 1 do
1115 assert_select "tag", "London"
1117 assert_select "gpx_file[id='#{trace2.id}']", 1 do
1118 assert_select "tag", "Birmingham"
1122 def test_make_friend
1123 # Get users to work with
1124 user = users(:normal_user)
1125 friend = users(:second_public_user)
1127 # Check that the users aren't already friends
1128 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1130 # When not logged in a GET should ask us to login
1131 get :make_friend, :display_name => friend.display_name
1132 assert_redirected_to :controller => :user, :action => "login", :referer => make_friend_path(:display_name => friend.display_name)
1134 # When not logged in a POST should error
1135 post :make_friend, :display_name => friend.display_name
1136 assert_response :forbidden
1137 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1139 # When logged in a GET should get a confirmation page
1140 get :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1141 assert_response :success
1142 assert_template :make_friend
1143 assert_select "form" do
1144 assert_select "input[type='hidden'][name='referer']", 0
1145 assert_select "input[type='submit']", 1
1147 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1149 # When logged in a POST should add the friendship
1150 assert_difference "ActionMailer::Base.deliveries.size", 1 do
1151 post :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1153 assert_redirected_to user_path(:display_name => friend.display_name)
1154 assert_match /is now your friend/, flash[:notice]
1155 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1156 email = ActionMailer::Base.deliveries.first
1157 assert_equal 1, email.to.count
1158 assert_equal friend.email, email.to.first
1159 ActionMailer::Base.deliveries.clear
1161 # A second POST should report that the friendship already exists
1162 assert_no_difference "ActionMailer::Base.deliveries.size" do
1163 post :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1165 assert_redirected_to user_path(:display_name => friend.display_name)
1166 assert_match /You are already friends with/, flash[:warning]
1167 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1170 def test_make_friend_with_referer
1171 # Get users to work with
1172 user = users(:normal_user)
1173 friend = users(:second_public_user)
1175 # Check that the users aren't already friends
1176 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1178 # The GET should preserve any referer
1179 get :make_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1180 assert_response :success
1181 assert_template :make_friend
1182 assert_select "form" do
1183 assert_select "input[type='hidden'][name='referer'][value='/test']", 1
1184 assert_select "input[type='submit']", 1
1186 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1188 # When logged in a POST should add the friendship and refer us
1189 assert_difference "ActionMailer::Base.deliveries.size", 1 do
1190 post :make_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1192 assert_redirected_to "/test"
1193 assert_match /is now your friend/, flash[:notice]
1194 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1195 email = ActionMailer::Base.deliveries.first
1196 assert_equal 1, email.to.count
1197 assert_equal friend.email, email.to.first
1198 ActionMailer::Base.deliveries.clear
1201 def test_make_friend_unkown_user
1202 # Should error when a bogus user is specified
1203 get :make_friend, { :display_name => "No Such User" }, { :user => users(:normal_user).id }
1204 assert_response :not_found
1205 assert_template :no_such_user
1208 def test_remove_friend
1209 # Get users to work with
1210 user = users(:normal_user)
1211 friend = users(:public_user)
1212 create(:friend, :befriender => user, :befriendee => friend)
1214 # Check that the users are friends
1215 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1217 # When not logged in a GET should ask us to login
1218 get :remove_friend, :display_name => friend.display_name
1219 assert_redirected_to :controller => :user, :action => "login", :referer => remove_friend_path(:display_name => friend.display_name)
1221 # When not logged in a POST should error
1222 post :remove_friend, :display_name => friend.display_name
1223 assert_response :forbidden
1224 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1226 # When logged in a GET should get a confirmation page
1227 get :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1228 assert_response :success
1229 assert_template :remove_friend
1230 assert_select "form" do
1231 assert_select "input[type='hidden'][name='referer']", 0
1232 assert_select "input[type='submit']", 1
1234 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1236 # When logged in a POST should remove the friendship
1237 post :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1238 assert_redirected_to user_path(:display_name => friend.display_name)
1239 assert_match /was removed from your friends/, flash[:notice]
1240 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1242 # A second POST should report that the friendship does not exist
1243 post :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1244 assert_redirected_to user_path(:display_name => friend.display_name)
1245 assert_match /is not one of your friends/, flash[:error]
1246 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1249 def test_remove_friend_with_referer
1250 # Get users to work with
1251 user = users(:normal_user)
1252 friend = users(:public_user)
1253 create(:friend, :user_id => user.id, :friend_user_id => friend.id)
1255 # Check that the users are friends
1256 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1258 # The GET should preserve any referer
1259 get :remove_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1260 assert_response :success
1261 assert_template :remove_friend
1262 assert_select "form" do
1263 assert_select "input[type='hidden'][name='referer'][value='/test']", 1
1264 assert_select "input[type='submit']", 1
1266 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1268 # When logged in a POST should remove the friendship and refer
1269 post :remove_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1270 assert_redirected_to "/test"
1271 assert_match /was removed from your friends/, flash[:notice]
1272 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1275 def test_remove_friend_unkown_user
1276 # Should error when a bogus user is specified
1277 get :remove_friend, { :display_name => "No Such User" }, { :user => users(:normal_user).id }
1278 assert_response :not_found
1279 assert_template :no_such_user
1283 # Try without logging in
1284 get :set_status, :display_name => users(:normal_user).display_name, :status => "suspended"
1285 assert_response :redirect
1286 assert_redirected_to :action => :login, :referer => set_status_user_path(:status => "suspended")
1288 # Now try as a normal user
1289 get :set_status, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:normal_user).id }
1290 assert_response :redirect
1291 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1293 # Finally try as an administrator
1294 get :set_status, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:administrator_user).id }
1295 assert_response :redirect
1296 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1297 assert_equal "suspended", User.find(users(:normal_user).id).status
1301 # Try without logging in
1302 get :delete, :display_name => users(:normal_user).display_name, :status => "suspended"
1303 assert_response :redirect
1304 assert_redirected_to :action => :login, :referer => delete_user_path(:status => "suspended")
1306 # Now try as a normal user
1307 get :delete, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:normal_user).id }
1308 assert_response :redirect
1309 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1311 # Finally try as an administrator
1312 get :delete, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:administrator_user).id }
1313 assert_response :redirect
1314 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1316 # Check that the user was deleted properly
1317 user = User.find(users(:normal_user).id)
1318 assert_equal "user_1", user.display_name
1319 assert_equal "", user.description
1320 assert_nil user.home_lat
1321 assert_nil user.home_lon
1322 assert_equal false, user.image.file?
1323 assert_equal false, user.email_valid
1324 assert_nil user.new_email
1325 assert_nil user.auth_provider
1326 assert_nil user.auth_uid
1327 assert_equal "deleted", user.status
1331 # Shouldn't work when not logged in
1333 assert_response :redirect
1334 assert_redirected_to :action => :login, :referer => users_path
1336 session[:user] = users(:normal_user).id
1338 # Shouldn't work when logged in as a normal user
1340 assert_response :redirect
1341 assert_redirected_to :action => :login, :referer => users_path
1343 session[:user] = users(:moderator_user).id
1345 # Shouldn't work when logged in as a moderator
1347 assert_response :redirect
1348 assert_redirected_to :action => :login, :referer => users_path
1350 session[:user] = users(:administrator_user).id
1352 # Should work when logged in as an administrator
1354 assert_response :success
1355 assert_template :list
1356 assert_select "table#user_list tr", :count => User.count + 1
1358 # Should be able to limit by status
1359 get :list, :status => "suspended"
1360 assert_response :success
1361 assert_template :list
1362 assert_select "table#user_list tr", :count => User.where(:status => "suspended").count + 1
1364 # Should be able to limit by IP address
1365 get :list, :ip => "1.2.3.4"
1366 assert_response :success
1367 assert_template :list
1368 assert_select "table#user_list tr", :count => User.where(:creation_ip => "1.2.3.4").count + 1
1371 def test_list_get_paginated
1372 1.upto(100).each do |n|
1373 User.create(:display_name => "extra_#{n}",
1374 :email => "extra#{n}@example.com",
1375 :pass_crypt => "extraextra")
1378 session[:user] = users(:administrator_user).id
1381 assert_response :success
1382 assert_template :list
1383 assert_select "table#user_list tr", :count => 51
1385 get :list, :page => 2
1386 assert_response :success
1387 assert_template :list
1388 assert_select "table#user_list tr", :count => 51
1390 get :list, :page => 3
1391 assert_response :success
1392 assert_template :list
1393 assert_select "table#user_list tr", :count => 26
1396 def test_list_post_confirm
1397 inactive_user = users(:inactive_user)
1398 suspended_user = users(:suspended_user)
1400 # Shouldn't work when not logged in
1401 assert_no_difference "User.active.count" do
1402 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1404 assert_response :redirect
1405 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1406 assert_equal "pending", inactive_user.reload.status
1407 assert_equal "suspended", suspended_user.reload.status
1409 session[:user] = users(:normal_user).id
1411 # Shouldn't work when logged in as a normal user
1412 assert_no_difference "User.active.count" do
1413 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1415 assert_response :redirect
1416 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1417 assert_equal "pending", inactive_user.reload.status
1418 assert_equal "suspended", suspended_user.reload.status
1420 session[:user] = users(:moderator_user).id
1422 # Shouldn't work when logged in as a moderator
1423 assert_no_difference "User.active.count" do
1424 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1426 assert_response :redirect
1427 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1428 assert_equal "pending", inactive_user.reload.status
1429 assert_equal "suspended", suspended_user.reload.status
1431 session[:user] = users(:administrator_user).id
1433 # Should work when logged in as an administrator
1434 assert_difference "User.active.count", 2 do
1435 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1437 assert_response :redirect
1438 assert_redirected_to :action => :list
1439 assert_equal "confirmed", inactive_user.reload.status
1440 assert_equal "confirmed", suspended_user.reload.status
1443 def test_list_post_hide
1444 normal_user = users(:normal_user)
1445 confirmed_user = users(:confirmed_user)
1447 # Shouldn't work when not logged in
1448 assert_no_difference "User.active.count" do
1449 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1451 assert_response :redirect
1452 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1453 assert_equal "active", normal_user.reload.status
1454 assert_equal "confirmed", confirmed_user.reload.status
1456 session[:user] = users(:normal_user).id
1458 # Shouldn't work when logged in as a normal user
1459 assert_no_difference "User.active.count" do
1460 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1462 assert_response :redirect
1463 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1464 assert_equal "active", normal_user.reload.status
1465 assert_equal "confirmed", confirmed_user.reload.status
1467 session[:user] = users(:moderator_user).id
1469 # Shouldn't work when logged in as a moderator
1470 assert_no_difference "User.active.count" do
1471 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1473 assert_response :redirect
1474 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1475 assert_equal "active", normal_user.reload.status
1476 assert_equal "confirmed", confirmed_user.reload.status
1478 session[:user] = users(:administrator_user).id
1480 # Should work when logged in as an administrator
1481 assert_difference "User.active.count", -2 do
1482 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1484 assert_response :redirect
1485 assert_redirected_to :action => :list
1486 assert_equal "deleted", normal_user.reload.status
1487 assert_equal "deleted", confirmed_user.reload.status
1494 user.status = "pending"
1495 user.display_name = "new_tester"
1496 user.email = "newtester@osm.org"
1497 user.email_confirmation = "newtester@osm.org"
1498 user.pass_crypt = "testtest"
1499 user.pass_crypt_confirmation = "testtest"