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) }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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))
1048 create(:message, :sender => users(:normal_user))
1050 # check that nothing is returned when not logged in
1052 assert_response :unauthorized
1054 # check that we get a response when logged in
1055 basic_authorization(users(:normal_user).email, "test")
1057 assert_response :success
1058 assert_equal "text/xml", response.content_type
1060 # check the data that is returned
1061 assert_select "description", :count => 1, :text => "test"
1062 assert_select "contributor-terms", :count => 1 do
1063 assert_select "[agreed='true'][pd='false']"
1065 assert_select "img", :count => 0
1066 assert_select "roles", :count => 1 do
1067 assert_select "role", :count => 0
1069 assert_select "changesets", :count => 1 do
1070 assert_select "[count='0']", :count => 1
1072 assert_select "traces", :count => 1 do
1073 assert_select "[count='0']", :count => 1
1075 assert_select "blocks", :count => 1 do
1076 assert_select "received", :count => 1 do
1077 assert_select "[count='0'][active='0']"
1079 assert_select "issued", :count => 0
1081 assert_select "home", :count => 1 do
1082 assert_select "[lat='12.1'][lon='12.1'][zoom='3']"
1084 assert_select "languages", :count => 1 do
1085 assert_select "lang", :count => 1, :text => "en"
1087 assert_select "messages", :count => 1 do
1088 assert_select "received", :count => 1 do
1089 assert_select "[count='1'][unread='0']"
1091 assert_select "sent", :count => 1 do
1092 assert_select "[count='1']"
1097 def test_api_gpx_files
1098 trace1 = create(:trace, :user => users(:normal_user)) do |trace|
1099 create(:tracetag, :trace => trace, :tag => "London")
1101 trace2 = create(:trace, :user => users(:normal_user)) do |trace|
1102 create(:tracetag, :trace => trace, :tag => "Birmingham")
1104 # check that nothing is returned when not logged in
1106 assert_response :unauthorized
1108 # check that we get a response when logged in
1109 basic_authorization(users(:normal_user).email, "test")
1111 assert_response :success
1112 assert_equal "text/xml", response.content_type
1114 # check the data that is returned
1115 assert_select "gpx_file[id='#{trace1.id}']", 1 do
1116 assert_select "tag", "London"
1118 assert_select "gpx_file[id='#{trace2.id}']", 1 do
1119 assert_select "tag", "Birmingham"
1123 def test_make_friend
1124 # Get users to work with
1125 user = users(:normal_user)
1126 friend = users(:second_public_user)
1128 # Check that the users aren't already friends
1129 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1131 # When not logged in a GET should ask us to login
1132 get :make_friend, :display_name => friend.display_name
1133 assert_redirected_to :controller => :user, :action => "login", :referer => make_friend_path(:display_name => friend.display_name)
1135 # When not logged in a POST should error
1136 post :make_friend, :display_name => friend.display_name
1137 assert_response :forbidden
1138 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1140 # When logged in a GET should get a confirmation page
1141 get :make_friend, { :display_name => friend.display_name }, { :user => user }
1142 assert_response :success
1143 assert_template :make_friend
1144 assert_select "form" do
1145 assert_select "input[type='hidden'][name='referer']", 0
1146 assert_select "input[type='submit']", 1
1148 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1150 # When logged in a POST should add the friendship
1151 assert_difference "ActionMailer::Base.deliveries.size", 1 do
1152 post :make_friend, { :display_name => friend.display_name }, { :user => user }
1154 assert_redirected_to user_path(:display_name => friend.display_name)
1155 assert_match /is now your friend/, flash[:notice]
1156 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1157 email = ActionMailer::Base.deliveries.first
1158 assert_equal 1, email.to.count
1159 assert_equal friend.email, email.to.first
1160 ActionMailer::Base.deliveries.clear
1162 # A second POST should report that the friendship already exists
1163 assert_no_difference "ActionMailer::Base.deliveries.size" do
1164 post :make_friend, { :display_name => friend.display_name }, { :user => user }
1166 assert_redirected_to user_path(:display_name => friend.display_name)
1167 assert_match /You are already friends with/, flash[:warning]
1168 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1171 def test_make_friend_with_referer
1172 # Get users to work with
1173 user = users(:normal_user)
1174 friend = users(:second_public_user)
1176 # Check that the users aren't already friends
1177 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1179 # The GET should preserve any referer
1180 get :make_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user }
1181 assert_response :success
1182 assert_template :make_friend
1183 assert_select "form" do
1184 assert_select "input[type='hidden'][name='referer'][value='/test']", 1
1185 assert_select "input[type='submit']", 1
1187 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1189 # When logged in a POST should add the friendship and refer us
1190 assert_difference "ActionMailer::Base.deliveries.size", 1 do
1191 post :make_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user }
1193 assert_redirected_to "/test"
1194 assert_match /is now your friend/, flash[:notice]
1195 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1196 email = ActionMailer::Base.deliveries.first
1197 assert_equal 1, email.to.count
1198 assert_equal friend.email, email.to.first
1199 ActionMailer::Base.deliveries.clear
1202 def test_make_friend_unkown_user
1203 # Should error when a bogus user is specified
1204 get :make_friend, { :display_name => "No Such User" }, { :user => users(:normal_user) }
1205 assert_response :not_found
1206 assert_template :no_such_user
1209 def test_remove_friend
1210 # Get users to work with
1211 user = users(:normal_user)
1212 friend = users(:public_user)
1213 create(:friend, :befriender => user, :befriendee => friend)
1215 # Check that the users are friends
1216 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1218 # When not logged in a GET should ask us to login
1219 get :remove_friend, :display_name => friend.display_name
1220 assert_redirected_to :controller => :user, :action => "login", :referer => remove_friend_path(:display_name => friend.display_name)
1222 # When not logged in a POST should error
1223 post :remove_friend, :display_name => friend.display_name
1224 assert_response :forbidden
1225 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1227 # When logged in a GET should get a confirmation page
1228 get :remove_friend, { :display_name => friend.display_name }, { :user => user }
1229 assert_response :success
1230 assert_template :remove_friend
1231 assert_select "form" do
1232 assert_select "input[type='hidden'][name='referer']", 0
1233 assert_select "input[type='submit']", 1
1235 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1237 # When logged in a POST should remove the friendship
1238 post :remove_friend, { :display_name => friend.display_name }, { :user => user }
1239 assert_redirected_to user_path(:display_name => friend.display_name)
1240 assert_match /was removed from your friends/, flash[:notice]
1241 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1243 # A second POST should report that the friendship does not exist
1244 post :remove_friend, { :display_name => friend.display_name }, { :user => user }
1245 assert_redirected_to user_path(:display_name => friend.display_name)
1246 assert_match /is not one of your friends/, flash[:error]
1247 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1250 def test_remove_friend_with_referer
1251 # Get users to work with
1252 user = users(:normal_user)
1253 friend = users(:public_user)
1254 create(:friend, :user_id => user.id, :friend_user_id => friend.id)
1256 # Check that the users are friends
1257 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1259 # The GET should preserve any referer
1260 get :remove_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user }
1261 assert_response :success
1262 assert_template :remove_friend
1263 assert_select "form" do
1264 assert_select "input[type='hidden'][name='referer'][value='/test']", 1
1265 assert_select "input[type='submit']", 1
1267 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1269 # When logged in a POST should remove the friendship and refer
1270 post :remove_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user }
1271 assert_redirected_to "/test"
1272 assert_match /was removed from your friends/, flash[:notice]
1273 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1276 def test_remove_friend_unkown_user
1277 # Should error when a bogus user is specified
1278 get :remove_friend, { :display_name => "No Such User" }, { :user => users(:normal_user) }
1279 assert_response :not_found
1280 assert_template :no_such_user
1284 # Try without logging in
1285 get :set_status, :display_name => users(:normal_user).display_name, :status => "suspended"
1286 assert_response :redirect
1287 assert_redirected_to :action => :login, :referer => set_status_user_path(:status => "suspended")
1289 # Now try as a normal user
1290 get :set_status, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:normal_user) }
1291 assert_response :redirect
1292 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1294 # Finally try as an administrator
1295 get :set_status, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:administrator_user) }
1296 assert_response :redirect
1297 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1298 assert_equal "suspended", User.find(users(:normal_user).id).status
1302 # Try without logging in
1303 get :delete, :display_name => users(:normal_user).display_name, :status => "suspended"
1304 assert_response :redirect
1305 assert_redirected_to :action => :login, :referer => delete_user_path(:status => "suspended")
1307 # Now try as a normal user
1308 get :delete, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:normal_user) }
1309 assert_response :redirect
1310 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1312 # Finally try as an administrator
1313 get :delete, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:administrator_user) }
1314 assert_response :redirect
1315 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1317 # Check that the user was deleted properly
1318 user = User.find(users(:normal_user).id)
1319 assert_equal "user_1", user.display_name
1320 assert_equal "", user.description
1321 assert_nil user.home_lat
1322 assert_nil user.home_lon
1323 assert_equal false, user.image.file?
1324 assert_equal false, user.email_valid
1325 assert_nil user.new_email
1326 assert_nil user.auth_provider
1327 assert_nil user.auth_uid
1328 assert_equal "deleted", user.status
1332 # Shouldn't work when not logged in
1334 assert_response :redirect
1335 assert_redirected_to :action => :login, :referer => users_path
1337 session[:user] = users(:normal_user).id
1339 # Shouldn't work when logged in as a normal user
1341 assert_response :redirect
1342 assert_redirected_to :action => :login, :referer => users_path
1344 session[:user] = users(:moderator_user).id
1346 # Shouldn't work when logged in as a moderator
1348 assert_response :redirect
1349 assert_redirected_to :action => :login, :referer => users_path
1351 session[:user] = users(:administrator_user).id
1353 # Should work when logged in as an administrator
1355 assert_response :success
1356 assert_template :list
1357 assert_select "table#user_list tr", :count => User.count + 1
1359 # Should be able to limit by status
1360 get :list, :status => "suspended"
1361 assert_response :success
1362 assert_template :list
1363 assert_select "table#user_list tr", :count => User.where(:status => "suspended").count + 1
1365 # Should be able to limit by IP address
1366 get :list, :ip => "1.2.3.4"
1367 assert_response :success
1368 assert_template :list
1369 assert_select "table#user_list tr", :count => User.where(:creation_ip => "1.2.3.4").count + 1
1372 def test_list_get_paginated
1373 1.upto(100).each do |n|
1374 User.create(:display_name => "extra_#{n}",
1375 :email => "extra#{n}@example.com",
1376 :pass_crypt => "extraextra")
1379 session[:user] = users(:administrator_user).id
1382 assert_response :success
1383 assert_template :list
1384 assert_select "table#user_list tr", :count => 51
1386 get :list, :page => 2
1387 assert_response :success
1388 assert_template :list
1389 assert_select "table#user_list tr", :count => 51
1391 get :list, :page => 3
1392 assert_response :success
1393 assert_template :list
1394 assert_select "table#user_list tr", :count => 26
1397 def test_list_post_confirm
1398 inactive_user = users(:inactive_user)
1399 suspended_user = users(:suspended_user)
1401 # Shouldn't work when not logged in
1402 assert_no_difference "User.active.count" do
1403 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1405 assert_response :redirect
1406 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1407 assert_equal "pending", inactive_user.reload.status
1408 assert_equal "suspended", suspended_user.reload.status
1410 session[:user] = users(:normal_user).id
1412 # Shouldn't work when logged in as a normal user
1413 assert_no_difference "User.active.count" do
1414 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1416 assert_response :redirect
1417 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1418 assert_equal "pending", inactive_user.reload.status
1419 assert_equal "suspended", suspended_user.reload.status
1421 session[:user] = users(:moderator_user).id
1423 # Shouldn't work when logged in as a moderator
1424 assert_no_difference "User.active.count" do
1425 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1427 assert_response :redirect
1428 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1429 assert_equal "pending", inactive_user.reload.status
1430 assert_equal "suspended", suspended_user.reload.status
1432 session[:user] = users(:administrator_user).id
1434 # Should work when logged in as an administrator
1435 assert_difference "User.active.count", 2 do
1436 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1438 assert_response :redirect
1439 assert_redirected_to :action => :list
1440 assert_equal "confirmed", inactive_user.reload.status
1441 assert_equal "confirmed", suspended_user.reload.status
1444 def test_list_post_hide
1445 normal_user = users(:normal_user)
1446 confirmed_user = users(:confirmed_user)
1448 # Shouldn't work when not logged in
1449 assert_no_difference "User.active.count" do
1450 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1452 assert_response :redirect
1453 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1454 assert_equal "active", normal_user.reload.status
1455 assert_equal "confirmed", confirmed_user.reload.status
1457 session[:user] = users(:normal_user).id
1459 # Shouldn't work when logged in as a normal user
1460 assert_no_difference "User.active.count" do
1461 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1463 assert_response :redirect
1464 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1465 assert_equal "active", normal_user.reload.status
1466 assert_equal "confirmed", confirmed_user.reload.status
1468 session[:user] = users(:moderator_user).id
1470 # Shouldn't work when logged in as a moderator
1471 assert_no_difference "User.active.count" do
1472 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1474 assert_response :redirect
1475 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1476 assert_equal "active", normal_user.reload.status
1477 assert_equal "confirmed", confirmed_user.reload.status
1479 session[:user] = users(:administrator_user).id
1481 # Should work when logged in as an administrator
1482 assert_difference "User.active.count", -2 do
1483 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1485 assert_response :redirect
1486 assert_redirected_to :action => :list
1487 assert_equal "deleted", normal_user.reload.status
1488 assert_equal "deleted", confirmed_user.reload.status
1495 user.status = "pending"
1496 user.display_name = "new_tester"
1497 user.email = "newtester@osm.org"
1498 user.email_confirmation = "newtester@osm.org"
1499 user.pass_crypt = "testtest"
1500 user.pass_crypt_confirmation = "testtest"