3 class UserControllerTest < ActionController::TestCase
7 stub_request(:get, "http://api.hostip.info/country.php?ip=0.0.0.0")
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 confirm_string = user.tokens.create.token
401 @request.cookies["_osm_session"] = user.display_name
402 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
403 assert_redirected_to login_path
404 assert_match /Confirmed your account/, flash[:notice]
407 def test_confirm_success_good_token_no_referer
408 user = users(:inactive_user)
409 confirm_string = user.tokens.create.token
410 token = user.tokens.create.token
412 @request.cookies["_osm_session"] = user.display_name
413 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
414 assert_redirected_to welcome_path
417 def test_confirm_success_bad_token_no_referer
418 user = users(:inactive_user)
419 confirm_string = user.tokens.create.token
420 token = users(:normal_user).tokens.create.token
422 @request.cookies["_osm_session"] = user.display_name
423 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
424 assert_redirected_to login_path
425 assert_match /Confirmed your account/, flash[:notice]
428 def test_confirm_success_no_token_with_referer
429 user = users(:inactive_user)
430 confirm_string = user.tokens.create(:referer => diary_new_path).token
432 @request.cookies["_osm_session"] = user.display_name
433 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
434 assert_redirected_to login_path(:referer => diary_new_path)
435 assert_match /Confirmed your account/, flash[:notice]
438 def test_confirm_success_good_token_with_referer
439 user = users(:inactive_user)
440 confirm_string = user.tokens.create(:referer => diary_new_path).token
441 token = user.tokens.create.token
443 @request.cookies["_osm_session"] = user.display_name
444 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
445 assert_redirected_to diary_new_path
448 def test_confirm_success_bad_token_with_referer
449 user = users(:inactive_user)
450 confirm_string = user.tokens.create(:referer => diary_new_path).token
451 token = users(:normal_user).tokens.create.token
453 @request.cookies["_osm_session"] = user.display_name
454 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
455 assert_redirected_to login_path(:referer => diary_new_path)
456 assert_match /Confirmed your account/, flash[:notice]
459 def test_confirm_expired_token
460 user = users(:inactive_user)
461 confirm_string = user.tokens.create(:expiry => 1.day.ago).token
463 @request.cookies["_osm_session"] = user.display_name
464 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
465 assert_redirected_to :action => "confirm"
466 assert_match /confirmation code has expired/, flash[:error]
469 def test_confirm_already_confirmed
470 user = users(:normal_user)
471 confirm_string = user.tokens.create(:referer => diary_new_path).token
473 @request.cookies["_osm_session"] = user.display_name
474 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
475 assert_redirected_to :action => "login"
476 assert_match /already been confirmed/, flash[:error]
479 def test_confirm_resend_success
480 session[:token] = users(:inactive_user).tokens.create.token
482 assert_difference "ActionMailer::Base.deliveries.size", 1 do
483 get :confirm_resend, :display_name => users(:inactive_user).display_name
486 assert_response :redirect
487 assert_redirected_to login_path
488 assert_match /sent a new confirmation/, flash[:notice]
490 email = ActionMailer::Base.deliveries.last
492 assert_equal users(:inactive_user).email, email.to.first
494 ActionMailer::Base.deliveries.clear
497 def test_confirm_resend_no_token
498 assert_no_difference "ActionMailer::Base.deliveries.size" do
499 get :confirm_resend, :display_name => users(:inactive_user).display_name
502 assert_response :redirect
503 assert_redirected_to login_path
504 assert_match "User Inactive User not found.", flash[:error]
507 def test_confirm_resend_unknown_user
508 assert_no_difference "ActionMailer::Base.deliveries.size" do
509 get :confirm_resend, :display_name => "No Such User"
512 assert_response :redirect
513 assert_redirected_to login_path
514 assert_match "User No Such User not found.", flash[:error]
517 def test_confirm_email_get
518 user = users(:normal_user)
519 confirm_string = user.tokens.create.token
521 get :confirm_email, :confirm_string => confirm_string
522 assert_response :success
523 assert_template :confirm_email
526 def test_confirm_email_success
527 user = users(:second_public_user)
528 confirm_string = user.tokens.create.token
530 post :confirm_email, :confirm_string => confirm_string
531 assert_response :redirect
532 assert_redirected_to :action => :account, :display_name => user.display_name
533 assert_match /Confirmed your change of email address/, flash[:notice]
536 def test_confirm_email_already_confirmed
537 user = users(:normal_user)
538 confirm_string = user.tokens.create.token
540 post :confirm_email, :confirm_string => confirm_string
541 assert_response :redirect
542 assert_redirected_to :action => :account, :display_name => user.display_name
543 assert_match /already been confirmed/, flash[:error]
546 def test_confirm_email_bad_token
547 post :confirm_email, :confirm_string => "XXXXX"
548 assert_response :success
549 assert_template :confirm_email
550 assert_match /confirmation code has expired or does not exist/, flash[:error]
554 # test if testing for a gravatar works
555 # this happens when the email is actually changed
556 # which is triggered by the confirmation mail
557 def test_gravatar_auto_enable
558 with_http_stubs "gravatar" do
559 # switch to email that has a gravatar
560 user = users(:first_gravatar_user)
561 confirm_string = user.tokens.create.token
562 # precondition gravatar should be turned off
563 assert !user.image_use_gravatar
564 post :confirm_email, :confirm_string => confirm_string
565 assert_response :redirect
566 assert_redirected_to :action => :account, :display_name => user.display_name
567 assert_match /Confirmed your change of email address/, flash[:notice]
568 # gravatar use should now be enabled
569 assert User.find(users(:first_gravatar_user).id).image_use_gravatar
573 def test_gravatar_auto_disable
574 with_http_stubs "gravatar" do
575 # switch to email without a gravatar
576 user = users(:second_gravatar_user)
577 confirm_string = user.tokens.create.token
578 # precondition gravatar should be turned on
579 assert user.image_use_gravatar
580 post :confirm_email, :confirm_string => confirm_string
581 assert_response :redirect
582 assert_redirected_to :action => :account, :display_name => user.display_name
583 assert_match /Confirmed your change of email address/, flash[:notice]
584 # gravatar use should now be disabled
585 assert !User.find(users(:second_gravatar_user).id).image_use_gravatar
589 def test_terms_new_user
590 get :terms, {}, { :new_user => User.new }
591 assert_response :success
592 assert_template :terms
596 user = users(:normal_user)
598 session[:user] = user.id
601 assert_response :redirect
602 assert_redirected_to :action => :account, :display_name => user.display_name
605 def test_terms_not_seen_without_referer
606 user = users(:terms_not_seen_user)
608 session[:user] = user.id
611 assert_response :success
612 assert_template :terms
614 post :save, :user => { :consider_pd => true }
615 assert_response :redirect
616 assert_redirected_to :action => :account, :display_name => user.display_name
617 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
621 assert_equal true, user.consider_pd
622 assert_not_nil user.terms_agreed
623 assert_equal true, user.terms_seen
626 def test_terms_not_seen_with_referer
627 user = users(:terms_not_seen_user)
629 session[:user] = user.id
631 get :terms, :referer => "/test"
632 assert_response :success
633 assert_template :terms
635 post :save, :user => { :consider_pd => true }, :referer => "/test"
636 assert_response :redirect
637 assert_redirected_to "/test"
638 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
642 assert_equal true, user.consider_pd
643 assert_not_nil user.terms_agreed
644 assert_equal true, user.terms_seen
648 post :go_public, {}, { :user => users(:normal_user) }
649 assert_response :redirect
650 assert_redirected_to :action => :account, :display_name => users(:normal_user).display_name
651 assert_equal true, User.find(users(:normal_user).id).data_public
654 def test_lost_password
655 # Test fetching the lost password page
657 assert_response :success
658 assert_template :lost_password
659 assert_select "div#notice", false
661 # Test resetting using the address as recorded for a user that has an
662 # address which is duplicated in a different case by another user
663 assert_difference "ActionMailer::Base.deliveries.size", 1 do
664 post :lost_password, :user => { :email => users(:normal_user).email }
666 assert_response :redirect
667 assert_redirected_to :action => :login
668 assert_match /^Sorry you lost it/, flash[:notice]
669 email = ActionMailer::Base.deliveries.first
670 assert_equal 1, email.to.count
671 assert_equal users(:normal_user).email, email.to.first
672 ActionMailer::Base.deliveries.clear
674 # Test resetting using an address that matches a different user
675 # that has the same address in a different case
676 assert_difference "ActionMailer::Base.deliveries.size", 1 do
677 post :lost_password, :user => { :email => users(:normal_user).email.upcase }
679 assert_response :redirect
680 assert_redirected_to :action => :login
681 assert_match /^Sorry you lost it/, flash[:notice]
682 email = ActionMailer::Base.deliveries.first
683 assert_equal 1, email.to.count
684 assert_equal users(:uppercase_user).email, email.to.first
685 ActionMailer::Base.deliveries.clear
687 # Test resetting using an address that is a case insensitive match
688 # for more than one user but not an exact match for either
689 assert_no_difference "ActionMailer::Base.deliveries.size" do
690 post :lost_password, :user => { :email => users(:normal_user).email.titlecase }
692 assert_response :success
693 assert_template :lost_password
694 assert_select ".error", /^Could not find that email address/
696 # Test resetting using the address as recorded for a user that has an
697 # address which is case insensitively unique
698 assert_difference "ActionMailer::Base.deliveries.size", 1 do
699 post :lost_password, :user => { :email => users(:public_user).email }
701 assert_response :redirect
702 assert_redirected_to :action => :login
703 assert_match /^Sorry you lost it/, flash[:notice]
704 email = ActionMailer::Base.deliveries.first
705 assert_equal 1, email.to.count
706 assert_equal users(:public_user).email, email.to.first
707 ActionMailer::Base.deliveries.clear
709 # Test resetting using an address that matches a user that has the
710 # same (case insensitively unique) address in a different case
711 assert_difference "ActionMailer::Base.deliveries.size", 1 do
712 post :lost_password, :user => { :email => users(:public_user).email.upcase }
714 assert_response :redirect
715 assert_redirected_to :action => :login
716 assert_match /^Sorry you lost it/, flash[:notice]
717 email = ActionMailer::Base.deliveries.first
718 assert_equal 1, email.to.count
719 assert_equal users(:public_user).email, email.to.first
720 ActionMailer::Base.deliveries.clear
723 def test_reset_password
724 # Test a request with no token
726 assert_response :bad_request
728 # Test a request with a bogus token
729 get :reset_password, :token => "made_up_token"
730 assert_response :redirect
731 assert_redirected_to :action => :lost_password
733 # Create a valid token for a user
734 token = User.find(users(:inactive_user).id).tokens.create
736 # Test a request with a valid token
737 get :reset_password, :token => token.token
738 assert_response :success
739 assert_template :reset_password
741 # Test setting a new password
742 post :reset_password, :token => token.token, :user => { :pass_crypt => "new_password", :pass_crypt_confirmation => "new_password" }
743 assert_response :redirect
744 assert_redirected_to root_path
745 assert_equal users(:inactive_user).id, session[:user]
746 user = User.find(users(:inactive_user).id)
747 assert_equal "active", user.status
748 assert_equal true, user.email_valid
749 assert_equal user, User.authenticate(:username => "inactive@openstreetmap.org", :password => "new_password")
753 # Get a user to work with - note that this user deliberately
754 # conflicts with uppercase_user in the email and display name
755 # fields to test that we can change other fields without any
756 # validation errors being reported
757 user = users(:normal_user)
759 # Make sure that you are redirected to the login page when
760 # you are not logged in
761 get :account, :display_name => user.display_name
762 assert_response :redirect
763 assert_redirected_to :controller => :user, :action => "login", :referer => "/user/test/account"
765 # Make sure that you are blocked when not logged in as the right user
766 get :account, { :display_name => user.display_name }, { :user => users(:public_user).id }
767 assert_response :forbidden
769 # Make sure we get the page when we are logged in as the right user
770 get :account, { :display_name => user.display_name }, { :user => user }
771 assert_response :success
772 assert_template :account
774 # Updating the description should work
775 user.description = "new description"
776 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
777 assert_response :success
778 assert_template :account
779 assert_select "div#errorExplanation", false
780 assert_select ".notice", /^User information updated successfully/
781 assert_select "form#accountForm > fieldset > div.form-row > div#user_description_container > div#user_description_content > textarea#user_description", user.description
783 # Changing to a invalid editor should fail
784 user.preferred_editor = "unknown"
785 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
786 assert_response :success
787 assert_template :account
788 assert_select ".notice", false
789 assert_select "div#errorExplanation"
790 assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected]", false
792 # Changing to a valid editor should work
793 user.preferred_editor = "potlatch2"
794 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
795 assert_response :success
796 assert_template :account
797 assert_select "div#errorExplanation", false
798 assert_select ".notice", /^User information updated successfully/
799 assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected][value=?]", "potlatch2"
801 # Changing to the default editor should work
802 user.preferred_editor = "default"
803 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
804 assert_response :success
805 assert_template :account
806 assert_select "div#errorExplanation", false
807 assert_select ".notice", /^User information updated successfully/
808 assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected]", false
810 # Changing to an uploaded image should work
811 image = Rack::Test::UploadedFile.new("test/traces/1.gif", "image/gif")
812 post :account, { :display_name => user.display_name, :image_action => "new", :user => user.attributes.merge(:image => image) }, { :user => user.id }
813 assert_response :success
814 assert_template :account
815 assert_select "div#errorExplanation", false
816 assert_select ".notice", /^User information updated successfully/
817 assert_select "form#accountForm > fieldset > div.form-row.accountImage input[name=image_action][checked][value=?]", "keep"
819 # Changing to a gravatar image should work
820 post :account, { :display_name => user.display_name, :image_action => "gravatar", :user => user.attributes }, { :user => user.id }
821 assert_response :success
822 assert_template :account
823 assert_select "div#errorExplanation", false
824 assert_select ".notice", /^User information updated successfully/
825 assert_select "form#accountForm > fieldset > div.form-row.accountImage input[name=image_action][checked][value=?]", "gravatar"
827 # Removing the image should work
828 post :account, { :display_name => user.display_name, :image_action => "delete", :user => user.attributes }, { :user => user.id }
829 assert_response :success
830 assert_template :account
831 assert_select "div#errorExplanation", false
832 assert_select ".notice", /^User information updated successfully/
833 assert_select "form#accountForm > fieldset > div.form-row.accountImage input[name=image_action][checked]", false
835 # Adding external authentication should redirect to the auth provider
836 post :account, { :display_name => user.display_name, :user => user.attributes.merge(:auth_provider => "openid", :auth_uid => "gmail.com") }, { :user => user.id }
837 assert_response :redirect
838 assert_redirected_to auth_path(:provider => "openid", :openid_url => "https://www.google.com/accounts/o8/id", :origin => "/user/#{user.display_name}/account")
840 # Changing name to one that exists should fail
841 new_attributes = user.attributes.dup.merge(:display_name => users(:public_user).display_name)
842 post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id }
843 assert_response :success
844 assert_template :account
845 assert_select ".notice", false
846 assert_select "div#errorExplanation"
847 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_display_name"
849 # Changing name to one that exists should fail, regardless of case
850 new_attributes = user.attributes.dup.merge(:display_name => users(:public_user).display_name.upcase)
851 post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id }
852 assert_response :success
853 assert_template :account
854 assert_select ".notice", false
855 assert_select "div#errorExplanation"
856 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_display_name"
858 # Changing name to one that doesn't exist should work
859 new_attributes = user.attributes.dup.merge(:display_name => "new tester")
860 post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id }
861 assert_response :success
862 assert_template :account
863 assert_select "div#errorExplanation", false
864 assert_select ".notice", /^User information updated successfully/
865 assert_select "form#accountForm > fieldset > div.form-row > input#user_display_name[value=?]", "new tester"
867 # Record the change of name
868 user.display_name = "new tester"
870 # Changing email to one that exists should fail
871 user.new_email = users(:public_user).email
872 assert_no_difference "ActionMailer::Base.deliveries.size" do
873 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
875 assert_response :success
876 assert_template :account
877 assert_select ".notice", false
878 assert_select "div#errorExplanation"
879 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_new_email"
881 # Changing email to one that exists should fail, regardless of case
882 user.new_email = users(:public_user).email.upcase
883 assert_no_difference "ActionMailer::Base.deliveries.size" do
884 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
886 assert_response :success
887 assert_template :account
888 assert_select ".notice", false
889 assert_select "div#errorExplanation"
890 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_new_email"
892 # Changing email to one that doesn't exist should work
893 user.new_email = "new_tester@example.com"
894 assert_difference "ActionMailer::Base.deliveries.size", 1 do
895 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
897 assert_response :success
898 assert_template :account
899 assert_select "div#errorExplanation", false
900 assert_select ".notice", /^User information updated successfully/
901 assert_select "form#accountForm > fieldset > div.form-row > input#user_new_email[value=?]", user.new_email
902 email = ActionMailer::Base.deliveries.first
903 assert_equal 1, email.to.count
904 assert_equal user.new_email, email.to.first
905 ActionMailer::Base.deliveries.clear
908 # Check that the user account page will display and contains some relevant
909 # information for the user
911 # Test a non-existent user
912 get :view, :display_name => "unknown"
913 assert_response :not_found
916 get :view, :display_name => "test"
917 assert_response :success
918 assert_select "div#userinformation" do
919 assert_select "a[href^='/user/test/history']", 1
920 assert_select "a[href='/user/test/traces']", 1
921 assert_select "a[href='/user/test/diary']", 1
922 assert_select "a[href='/user/test/diary/comments']", 1
923 assert_select "a[href='/user/test/account']", 0
924 assert_select "a[href='/user/test/blocks']", 0
925 assert_select "a[href='/user/test/blocks_by']", 0
926 assert_select "a[href='/blocks/new/test']", 0
929 # Test a user who has been blocked
930 create(:user_block, :user => users(:blocked_user))
931 get :view, :display_name => "blocked"
932 assert_response :success
933 assert_select "div#userinformation" do
934 assert_select "a[href^='/user/blocked/history']", 1
935 assert_select "a[href='/user/blocked/traces']", 1
936 assert_select "a[href='/user/blocked/diary']", 1
937 assert_select "a[href='/user/blocked/diary/comments']", 1
938 assert_select "a[href='/user/blocked/account']", 0
939 assert_select "a[href='/user/blocked/blocks']", 1
940 assert_select "a[href='/user/blocked/blocks_by']", 0
941 assert_select "a[href='/blocks/new/blocked']", 0
944 # Test a moderator who has applied blocks
945 create(:user_block, :creator => users(:moderator_user))
946 get :view, :display_name => "moderator"
947 assert_response :success
948 assert_select "div#userinformation" do
949 assert_select "a[href^='/user/moderator/history']", 1
950 assert_select "a[href='/user/moderator/traces']", 1
951 assert_select "a[href='/user/moderator/diary']", 1
952 assert_select "a[href='/user/moderator/diary/comments']", 1
953 assert_select "a[href='/user/moderator/account']", 0
954 assert_select "a[href='/user/moderator/blocks']", 0
955 assert_select "a[href='/user/moderator/blocks_by']", 1
956 assert_select "a[href='/blocks/new/moderator']", 0
959 # Login as a normal user
960 session[:user] = users(:normal_user).id
962 # Test the normal user
963 get :view, :display_name => "test"
964 assert_response :success
965 assert_select "div#userinformation" do
966 assert_select "a[href^='/user/test/history']", 1
967 assert_select "a[href='/traces/mine']", 1
968 assert_select "a[href='/user/test/diary']", 1
969 assert_select "a[href='/user/test/diary/comments']", 1
970 assert_select "a[href='/user/test/account']", 1
971 assert_select "a[href='/user/test/blocks']", 0
972 assert_select "a[href='/user/test/blocks_by']", 0
973 assert_select "a[href='/blocks/new/test']", 0
976 # Login as a moderator
977 session[:user] = users(:moderator_user).id
979 # Test the normal user
980 get :view, :display_name => "test"
981 assert_response :success
982 assert_select "div#userinformation" do
983 assert_select "a[href^='/user/test/history']", 1
984 assert_select "a[href='/user/test/traces']", 1
985 assert_select "a[href='/user/test/diary']", 1
986 assert_select "a[href='/user/test/diary/comments']", 1
987 assert_select "a[href='/user/test/account']", 0
988 assert_select "a[href='/user/test/blocks']", 0
989 assert_select "a[href='/user/test/blocks_by']", 0
990 assert_select "a[href='/blocks/new/test']", 1
995 # check that a visible user is returned properly
996 get :api_read, :id => users(:normal_user).id
997 assert_response :success
998 assert_equal "text/xml", response.content_type
1000 # check the data that is returned
1001 assert_select "description", :count => 1, :text => "test"
1002 assert_select "contributor-terms", :count => 1 do
1003 assert_select "[agreed='true']"
1005 assert_select "img", :count => 0
1006 assert_select "roles", :count => 1 do
1007 assert_select "role", :count => 0
1009 assert_select "changesets", :count => 1 do
1010 assert_select "[count='0']"
1012 assert_select "traces", :count => 1 do
1013 assert_select "[count='0']"
1015 assert_select "blocks", :count => 1 do
1016 assert_select "received", :count => 1 do
1017 assert_select "[count='0'][active='0']"
1019 assert_select "issued", :count => 0
1022 # check that we aren't revealing private information
1023 assert_select "contributor-terms[pd]", false
1024 assert_select "home", false
1025 assert_select "languages", false
1026 assert_select "messages", false
1028 # check that a suspended user is not returned
1029 get :api_read, :id => users(:suspended_user).id
1030 assert_response :gone
1032 # check that a deleted user is not returned
1033 get :api_read, :id => users(:deleted_user).id
1034 assert_response :gone
1036 # check that a non-existent user is not returned
1037 get :api_read, :id => 0
1038 assert_response :not_found
1041 def test_api_details
1042 create(:message, :read, :recipient => users(:normal_user))
1044 # check that nothing is returned when not logged in
1046 assert_response :unauthorized
1048 # check that we get a response when logged in
1049 basic_authorization(users(:normal_user).email, "test")
1051 assert_response :success
1052 assert_equal "text/xml", response.content_type
1054 # check the data that is returned
1055 assert_select "description", :count => 1, :text => "test"
1056 assert_select "contributor-terms", :count => 1 do
1057 assert_select "[agreed='true'][pd='false']"
1059 assert_select "img", :count => 0
1060 assert_select "roles", :count => 1 do
1061 assert_select "role", :count => 0
1063 assert_select "changesets", :count => 1 do
1064 assert_select "[count='0']", :count => 1
1066 assert_select "traces", :count => 1 do
1067 assert_select "[count='0']", :count => 1
1069 assert_select "blocks", :count => 1 do
1070 assert_select "received", :count => 1 do
1071 assert_select "[count='0'][active='0']"
1073 assert_select "issued", :count => 0
1075 assert_select "home", :count => 1 do
1076 assert_select "[lat='12.1'][lon='12.1'][zoom='3']"
1078 assert_select "languages", :count => 1 do
1079 assert_select "lang", :count => 1, :text => "en"
1081 assert_select "messages", :count => 1 do
1082 assert_select "received", :count => 1 do
1083 assert_select "[count='1'][unread='0']"
1085 assert_select "sent", :count => 1 do
1086 assert_select "[count='1']"
1091 def test_api_gpx_files
1092 # check that nothing is returned when not logged in
1094 assert_response :unauthorized
1096 # check that we get a response when logged in
1097 basic_authorization(users(:normal_user).email, "test")
1099 assert_response :success
1100 assert_equal "text/xml", response.content_type
1102 # check the data that is returned
1103 assert_select "gpx_file[id='1']", 1 do
1104 assert_select "tag", "London"
1106 assert_select "gpx_file[id='4']", 1 do
1107 assert_select "tag", "Birmingham"
1111 def test_make_friend
1112 # Get users to work with
1113 user = users(:normal_user)
1114 friend = users(:second_public_user)
1116 # Check that the users aren't already friends
1117 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1119 # When not logged in a GET should ask us to login
1120 get :make_friend, :display_name => friend.display_name
1121 assert_redirected_to :controller => :user, :action => "login", :referer => make_friend_path(:display_name => friend.display_name)
1123 # When not logged in a POST should error
1124 post :make_friend, :display_name => friend.display_name
1125 assert_response :forbidden
1126 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1128 # When logged in a GET should get a confirmation page
1129 get :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1130 assert_response :success
1131 assert_template :make_friend
1132 assert_select "form" do
1133 assert_select "input[type='hidden'][name='referer']", 0
1134 assert_select "input[type='submit']", 1
1136 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1138 # When logged in a POST should add the friendship
1139 assert_difference "ActionMailer::Base.deliveries.size", 1 do
1140 post :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1142 assert_redirected_to user_path(:display_name => friend.display_name)
1143 assert_match /is now your friend/, flash[:notice]
1144 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1145 email = ActionMailer::Base.deliveries.first
1146 assert_equal 1, email.to.count
1147 assert_equal friend.email, email.to.first
1148 ActionMailer::Base.deliveries.clear
1150 # A second POST should report that the friendship already exists
1151 assert_no_difference "ActionMailer::Base.deliveries.size" do
1152 post :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1154 assert_redirected_to user_path(:display_name => friend.display_name)
1155 assert_match /You are already friends with/, flash[:warning]
1156 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1159 def test_make_friend_with_referer
1160 # Get users to work with
1161 user = users(:normal_user)
1162 friend = users(:second_public_user)
1164 # Check that the users aren't already friends
1165 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1167 # The GET should preserve any referer
1168 get :make_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1169 assert_response :success
1170 assert_template :make_friend
1171 assert_select "form" do
1172 assert_select "input[type='hidden'][name='referer'][value='/test']", 1
1173 assert_select "input[type='submit']", 1
1175 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1177 # When logged in a POST should add the friendship and refer us
1178 assert_difference "ActionMailer::Base.deliveries.size", 1 do
1179 post :make_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1181 assert_redirected_to "/test"
1182 assert_match /is now your friend/, flash[:notice]
1183 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1184 email = ActionMailer::Base.deliveries.first
1185 assert_equal 1, email.to.count
1186 assert_equal friend.email, email.to.first
1187 ActionMailer::Base.deliveries.clear
1190 def test_make_friend_unkown_user
1191 # Should error when a bogus user is specified
1192 get :make_friend, { :display_name => "No Such User" }, { :user => users(:normal_user).id }
1193 assert_response :not_found
1194 assert_template :no_such_user
1197 def test_remove_friend
1198 # Get users to work with
1199 user = users(:normal_user)
1200 friend = users(:public_user)
1201 create(:friend, :befriender => user, :befriendee => friend)
1203 # Check that the users are friends
1204 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1206 # When not logged in a GET should ask us to login
1207 get :remove_friend, :display_name => friend.display_name
1208 assert_redirected_to :controller => :user, :action => "login", :referer => remove_friend_path(:display_name => friend.display_name)
1210 # When not logged in a POST should error
1211 post :remove_friend, :display_name => friend.display_name
1212 assert_response :forbidden
1213 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1215 # When logged in a GET should get a confirmation page
1216 get :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1217 assert_response :success
1218 assert_template :remove_friend
1219 assert_select "form" do
1220 assert_select "input[type='hidden'][name='referer']", 0
1221 assert_select "input[type='submit']", 1
1223 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1225 # When logged in a POST should remove the friendship
1226 post :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1227 assert_redirected_to user_path(:display_name => friend.display_name)
1228 assert_match /was removed from your friends/, flash[:notice]
1229 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1231 # A second POST should report that the friendship does not exist
1232 post :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1233 assert_redirected_to user_path(:display_name => friend.display_name)
1234 assert_match /is not one of your friends/, flash[:error]
1235 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1238 def test_remove_friend_with_referer
1239 # Get users to work with
1240 user = users(:normal_user)
1241 friend = users(:public_user)
1242 create(:friend, :user_id => user.id, :friend_user_id => friend.id)
1244 # Check that the users are friends
1245 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1247 # The GET should preserve any referer
1248 get :remove_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1249 assert_response :success
1250 assert_template :remove_friend
1251 assert_select "form" do
1252 assert_select "input[type='hidden'][name='referer'][value='/test']", 1
1253 assert_select "input[type='submit']", 1
1255 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1257 # When logged in a POST should remove the friendship and refer
1258 post :remove_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1259 assert_redirected_to "/test"
1260 assert_match /was removed from your friends/, flash[:notice]
1261 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1264 def test_remove_friend_unkown_user
1265 # Should error when a bogus user is specified
1266 get :remove_friend, { :display_name => "No Such User" }, { :user => users(:normal_user).id }
1267 assert_response :not_found
1268 assert_template :no_such_user
1272 # Try without logging in
1273 get :set_status, :display_name => users(:normal_user).display_name, :status => "suspended"
1274 assert_response :redirect
1275 assert_redirected_to :action => :login, :referer => set_status_user_path(:status => "suspended")
1277 # Now try as a normal user
1278 get :set_status, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:normal_user).id }
1279 assert_response :redirect
1280 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1282 # Finally try as an administrator
1283 get :set_status, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:administrator_user).id }
1284 assert_response :redirect
1285 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1286 assert_equal "suspended", User.find(users(:normal_user).id).status
1290 # Try without logging in
1291 get :delete, :display_name => users(:normal_user).display_name, :status => "suspended"
1292 assert_response :redirect
1293 assert_redirected_to :action => :login, :referer => delete_user_path(:status => "suspended")
1295 # Now try as a normal user
1296 get :delete, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:normal_user).id }
1297 assert_response :redirect
1298 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1300 # Finally try as an administrator
1301 get :delete, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:administrator_user).id }
1302 assert_response :redirect
1303 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1305 # Check that the user was deleted properly
1306 user = User.find(users(:normal_user).id)
1307 assert_equal "user_1", user.display_name
1308 assert_equal "", user.description
1309 assert_nil user.home_lat
1310 assert_nil user.home_lon
1311 assert_equal false, user.image.file?
1312 assert_equal false, user.email_valid
1313 assert_nil user.new_email
1314 assert_nil user.auth_provider
1315 assert_nil user.auth_uid
1316 assert_equal "deleted", user.status
1320 # Shouldn't work when not logged in
1322 assert_response :redirect
1323 assert_redirected_to :action => :login, :referer => users_path
1325 session[:user] = users(:normal_user).id
1327 # Shouldn't work when logged in as a normal user
1329 assert_response :redirect
1330 assert_redirected_to :action => :login, :referer => users_path
1332 session[:user] = users(:moderator_user).id
1334 # Shouldn't work when logged in as a moderator
1336 assert_response :redirect
1337 assert_redirected_to :action => :login, :referer => users_path
1339 session[:user] = users(:administrator_user).id
1341 # Should work when logged in as an administrator
1343 assert_response :success
1344 assert_template :list
1345 assert_select "table#user_list tr", :count => User.count + 1
1347 # Should be able to limit by status
1348 get :list, :status => "suspended"
1349 assert_response :success
1350 assert_template :list
1351 assert_select "table#user_list tr", :count => User.where(:status => "suspended").count + 1
1353 # Should be able to limit by IP address
1354 get :list, :ip => "1.2.3.4"
1355 assert_response :success
1356 assert_template :list
1357 assert_select "table#user_list tr", :count => User.where(:creation_ip => "1.2.3.4").count + 1
1360 def test_list_get_paginated
1361 1.upto(100).each do |n|
1362 User.create(:display_name => "extra_#{n}",
1363 :email => "extra#{n}@example.com",
1364 :pass_crypt => "extraextra")
1367 session[:user] = users(:administrator_user).id
1370 assert_response :success
1371 assert_template :list
1372 assert_select "table#user_list tr", :count => 51
1374 get :list, :page => 2
1375 assert_response :success
1376 assert_template :list
1377 assert_select "table#user_list tr", :count => 51
1379 get :list, :page => 3
1380 assert_response :success
1381 assert_template :list
1382 assert_select "table#user_list tr", :count => 25
1385 def test_list_post_confirm
1386 inactive_user = users(:inactive_user)
1387 suspended_user = users(:suspended_user)
1389 # Shouldn't work when not logged in
1390 assert_no_difference "User.active.count" do
1391 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1393 assert_response :redirect
1394 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1395 assert_equal "pending", inactive_user.reload.status
1396 assert_equal "suspended", suspended_user.reload.status
1398 session[:user] = users(:normal_user).id
1400 # Shouldn't work when logged in as a normal user
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(:moderator_user).id
1411 # Shouldn't work when logged in as a moderator
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(:administrator_user).id
1422 # Should work when logged in as an administrator
1423 assert_difference "User.active.count", 2 do
1424 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1426 assert_response :redirect
1427 assert_redirected_to :action => :list
1428 assert_equal "confirmed", inactive_user.reload.status
1429 assert_equal "confirmed", suspended_user.reload.status
1432 def test_list_post_hide
1433 normal_user = users(:normal_user)
1434 confirmed_user = users(:confirmed_user)
1436 # Shouldn't work when not logged in
1437 assert_no_difference "User.active.count" do
1438 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1440 assert_response :redirect
1441 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1442 assert_equal "active", normal_user.reload.status
1443 assert_equal "confirmed", confirmed_user.reload.status
1445 session[:user] = users(:normal_user).id
1447 # Shouldn't work when logged in as a normal user
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(:moderator_user).id
1458 # Shouldn't work when logged in as a moderator
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(:administrator_user).id
1469 # Should work when logged in as an administrator
1470 assert_difference "User.active.count", -2 do
1471 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1473 assert_response :redirect
1474 assert_redirected_to :action => :list
1475 assert_equal "deleted", normal_user.reload.status
1476 assert_equal "deleted", confirmed_user.reload.status
1483 user.status = "pending"
1484 user.display_name = "new_tester"
1485 user.email = "newtester@osm.org"
1486 user.email_confirmation = "newtester@osm.org"
1487 user.pass_crypt = "testtest"
1488 user.pass_crypt_confirmation = "testtest"