3 class UserControllerTest < ActionController::TestCase
7 # test all routes which lead to this controller
10 { :path => "/api/0.6/user/1", :method => :get },
11 { :controller => "user", :action => "api_read", :id => "1" }
14 { :path => "/api/0.6/user/details", :method => :get },
15 { :controller => "user", :action => "api_details" }
18 { :path => "/api/0.6/user/gpx_files", :method => :get },
19 { :controller => "user", :action => "api_gpx_files" }
23 { :path => "/login", :method => :get },
24 { :controller => "user", :action => "login" }
27 { :path => "/login", :method => :post },
28 { :controller => "user", :action => "login" }
31 { :controller => "user", :action => "login", :format => "html" },
32 { :path => "/login.html", :method => :get }
36 { :path => "/logout", :method => :get },
37 { :controller => "user", :action => "logout" }
40 { :path => "/logout", :method => :post },
41 { :controller => "user", :action => "logout" }
44 { :controller => "user", :action => "logout", :format => "html" },
45 { :path => "/logout.html", :method => :get }
49 { :path => "/user/new", :method => :get },
50 { :controller => "user", :action => "new" }
54 { :path => "/user/new", :method => :post },
55 { :controller => "user", :action => "create" }
59 { :path => "/user/terms", :method => :get },
60 { :controller => "user", :action => "terms" }
64 { :path => "/user/save", :method => :post },
65 { :controller => "user", :action => "save" }
69 { :path => "/user/username/confirm", :method => :get },
70 { :controller => "user", :action => "confirm", :display_name => "username" }
73 { :path => "/user/username/confirm", :method => :post },
74 { :controller => "user", :action => "confirm", :display_name => "username" }
77 { :path => "/user/username/confirm/resend", :method => :get },
78 { :controller => "user", :action => "confirm_resend", :display_name => "username" }
82 { :path => "/user/confirm", :method => :get },
83 { :controller => "user", :action => "confirm" }
86 { :path => "/user/confirm", :method => :post },
87 { :controller => "user", :action => "confirm" }
90 { :path => "/user/confirm-email", :method => :get },
91 { :controller => "user", :action => "confirm_email" }
94 { :path => "/user/confirm-email", :method => :post },
95 { :controller => "user", :action => "confirm_email" }
99 { :path => "/user/go_public", :method => :post },
100 { :controller => "user", :action => "go_public" }
104 { :path => "/user/forgot-password", :method => :get },
105 { :controller => "user", :action => "lost_password" }
108 { :path => "/user/forgot-password", :method => :post },
109 { :controller => "user", :action => "lost_password" }
112 { :path => "/user/reset-password", :method => :get },
113 { :controller => "user", :action => "reset_password" }
116 { :path => "/user/reset-password", :method => :post },
117 { :controller => "user", :action => "reset_password" }
121 { :path => "/user/suspended", :method => :get },
122 { :controller => "user", :action => "suspended" }
126 { :path => "/user/username", :method => :get },
127 { :controller => "user", :action => "view", :display_name => "username" }
131 { :path => "/user/username/account", :method => :get },
132 { :controller => "user", :action => "account", :display_name => "username" }
135 { :path => "/user/username/account", :method => :post },
136 { :controller => "user", :action => "account", :display_name => "username" }
140 { :path => "/user/username/make_friend", :method => :get },
141 { :controller => "user", :action => "make_friend", :display_name => "username" }
144 { :path => "/user/username/make_friend", :method => :post },
145 { :controller => "user", :action => "make_friend", :display_name => "username" }
148 { :path => "/user/username/remove_friend", :method => :get },
149 { :controller => "user", :action => "remove_friend", :display_name => "username" }
152 { :path => "/user/username/remove_friend", :method => :post },
153 { :controller => "user", :action => "remove_friend", :display_name => "username" }
157 { :path => "/user/username/set_status", :method => :get },
158 { :controller => "user", :action => "set_status", :display_name => "username" }
161 { :path => "/user/username/delete", :method => :get },
162 { :controller => "user", :action => "delete", :display_name => "username" }
166 { :path => "/users", :method => :get },
167 { :controller => "user", :action => "list" }
170 { :path => "/users", :method => :post },
171 { :controller => "user", :action => "list" }
174 { :path => "/users/status", :method => :get },
175 { :controller => "user", :action => "list", :status => "status" }
178 { :path => "/users/status", :method => :post },
179 { :controller => "user", :action => "list", :status => "status" }
183 # The user creation page loads
186 assert_response :redirect
187 assert_redirected_to user_new_path(:cookie_test => "true")
189 get :new, { :cookie_test => "true" }, { :cookie_test => true }
190 assert_response :success
192 assert_select "html", :count => 1 do
193 assert_select "head", :count => 1 do
194 assert_select "title", :text => /Sign Up/, :count => 1
196 assert_select "body", :count => 1 do
197 assert_select "div#content", :count => 1 do
198 assert_select "form[action='/user/new'][method='post']", :count => 1 do
199 assert_select "input[id='user_email']", :count => 1
200 assert_select "input[id='user_email_confirmation']", :count => 1
201 assert_select "input[id='user_display_name']", :count => 1
202 assert_select "input[id='user_pass_crypt'][type='password']", :count => 1
203 assert_select "input[id='user_pass_crypt_confirmation'][type='password']", :count => 1
204 assert_select "input[type='submit'][value='Sign Up']", :count => 1
211 def test_new_view_logged_in
212 session[:user] = users(:normal_user).id
215 assert_response :redirect
216 assert_redirected_to user_new_path(:cookie_test => "true")
217 get :new, :cookie_test => "true"
218 assert_response :redirect
219 assert_redirected_to root_path
221 get :new, :referer => "/test"
222 assert_response :redirect
223 assert_redirected_to user_new_path(:referer => "/test", :cookie_test => "true")
224 get :new, :referer => "/test", :cookie_test => "true"
225 assert_response :redirect
226 assert_redirected_to "/test"
232 assert_difference "User.count", 1 do
233 assert_difference "ActionMailer::Base.deliveries.size", 1 do
234 post :save, {}, { :new_user => user }
239 register_email = ActionMailer::Base.deliveries.first
241 assert_equal register_email.to[0], user.email
242 assert_match /#{@url}/, register_email.body.to_s
245 assert_redirected_to :action => "confirm", :display_name => user.display_name
247 ActionMailer::Base.deliveries.clear
250 def test_new_duplicate_email
252 user.email = users(:public_user).email
254 assert_no_difference "User.count" do
255 assert_no_difference "ActionMailer::Base.deliveries.size" do
256 post :save, {}, { :new_user => user }
260 assert_response :success
261 assert_template "new"
262 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
265 def test_new_duplicate_email_uppercase
267 user.email = users(:public_user).email.upcase
269 assert_no_difference "User.count" do
270 assert_no_difference "ActionMailer::Base.deliveries.size" do
271 post :save, {}, { :new_user => user }
275 assert_response :success
276 assert_template "new"
277 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
280 def test_new_duplicate_name
282 user.display_name = users(:public_user).display_name
284 assert_no_difference "User.count" do
285 assert_no_difference "ActionMailer::Base.deliveries.size" do
286 post :save, {}, { :new_user => user }
290 assert_response :success
291 assert_template "new"
292 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
295 def test_new_duplicate_name_uppercase
297 user.display_name = users(:public_user).display_name.upcase
299 assert_no_difference "User.count" do
300 assert_no_difference "ActionMailer::Base.deliveries.size" do
301 post :save, {}, { :new_user => user }
305 assert_response :success
306 assert_template "new"
307 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
310 def test_save_referer_params
313 assert_difference "User.count", 1 do
314 assert_difference "ActionMailer::Base.deliveries.size", 1 do
315 post :save, {}, { :new_user => user,
316 :referer => "/edit?editor=id#map=1/2/3" }
320 assert_equal welcome_path(:editor => "id", :zoom => 1, :lat => 2, :lon => 3),
321 user.tokens.order("id DESC").first.referer
323 ActionMailer::Base.deliveries.clear
326 def test_logout_without_referer
328 assert_response :success
329 assert_template :logout
330 assert_select "input[name=referer][value=?]", ""
332 session_id = assert_select("input[name=session]").first["value"]
334 get :logout, :session => session_id
335 assert_response :redirect
336 assert_redirected_to root_path
339 def test_logout_with_referer
340 get :logout, :referer => "/test"
341 assert_response :success
342 assert_template :logout
343 assert_select "input[name=referer][value=?]", "/test"
345 session_id = assert_select("input[name=session]").first["value"]
347 get :logout, :session => session_id, :referer => "/test"
348 assert_response :redirect
349 assert_redirected_to "/test"
352 def test_logout_with_token
353 token = users(:normal_user).tokens.create
355 session[:token] = token.token
358 assert_response :success
359 assert_template :logout
360 assert_select "input[name=referer][value=?]", ""
361 assert_equal token.token, session[:token]
362 assert_not_nil UserToken.where(:id => token.id).first
364 session_id = assert_select("input[name=session]").first["value"]
366 get :logout, :session => session_id
367 assert_response :redirect
368 assert_redirected_to root_path
369 assert_nil session[:token]
370 assert_nil UserToken.where(:id => token.id).first
374 user = users(:inactive_user)
375 confirm_string = user.tokens.create.token
377 @request.cookies["_osm_session"] = user.display_name
378 get :confirm, :display_name => user.display_name, :confirm_string => confirm_string
379 assert_response :success
380 assert_template :confirm
383 def test_confirm_get_already_confirmed
384 user = users(:normal_user)
385 confirm_string = user.tokens.create.token
387 @request.cookies["_osm_session"] = user.display_name
388 get :confirm, :display_name => user.display_name, :confirm_string => confirm_string
389 assert_response :redirect
390 assert_redirected_to root_path
393 def test_confirm_success_no_token_no_referer
394 user = users(:inactive_user)
395 confirm_string = user.tokens.create.token
397 @request.cookies["_osm_session"] = user.display_name
398 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
399 assert_redirected_to login_path
400 assert_match /Confirmed your account/, flash[:notice]
403 def test_confirm_success_good_token_no_referer
404 user = users(:inactive_user)
405 confirm_string = user.tokens.create.token
406 token = user.tokens.create.token
408 @request.cookies["_osm_session"] = user.display_name
409 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
410 assert_redirected_to welcome_path
413 def test_confirm_success_bad_token_no_referer
414 user = users(:inactive_user)
415 confirm_string = user.tokens.create.token
416 token = users(:normal_user).tokens.create.token
418 @request.cookies["_osm_session"] = user.display_name
419 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
420 assert_redirected_to login_path
421 assert_match /Confirmed your account/, flash[:notice]
424 def test_confirm_success_no_token_with_referer
425 user = users(:inactive_user)
426 confirm_string = user.tokens.create(:referer => diary_new_path).token
428 @request.cookies["_osm_session"] = user.display_name
429 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
430 assert_redirected_to login_path(:referer => diary_new_path)
431 assert_match /Confirmed your account/, flash[:notice]
434 def test_confirm_success_good_token_with_referer
435 user = users(:inactive_user)
436 confirm_string = user.tokens.create(:referer => diary_new_path).token
437 token = user.tokens.create.token
439 @request.cookies["_osm_session"] = user.display_name
440 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
441 assert_redirected_to diary_new_path
444 def test_confirm_success_bad_token_with_referer
445 user = users(:inactive_user)
446 confirm_string = user.tokens.create(:referer => diary_new_path).token
447 token = users(:normal_user).tokens.create.token
449 @request.cookies["_osm_session"] = user.display_name
450 post :confirm, { :display_name => user.display_name, :confirm_string => confirm_string }, { :token => token }
451 assert_redirected_to login_path(:referer => diary_new_path)
452 assert_match /Confirmed your account/, flash[:notice]
455 def test_confirm_expired_token
456 user = users(:inactive_user)
457 confirm_string = user.tokens.create(:expiry => 1.day.ago).token
459 @request.cookies["_osm_session"] = user.display_name
460 post :confirm, :display_name => user.display_name, :confirm_string => confirm_string
461 assert_redirected_to :action => "confirm"
462 assert_match /confirmation code has expired/, flash[:error]
465 def test_confirm_already_confirmed
466 user = users(:normal_user)
467 confirm_string = user.tokens.create(:referer => diary_new_path).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 => "login"
472 assert_match /already been confirmed/, flash[:error]
475 def test_confirm_resend_success
476 session[:token] = users(:inactive_user).tokens.create.token
478 assert_difference "ActionMailer::Base.deliveries.size", 1 do
479 get :confirm_resend, :display_name => users(:inactive_user).display_name
482 assert_response :redirect
483 assert_redirected_to login_path
484 assert_match /sent a new confirmation/, flash[:notice]
486 email = ActionMailer::Base.deliveries.last
488 assert_equal users(:inactive_user).email, email.to.first
490 ActionMailer::Base.deliveries.clear
493 def test_confirm_resend_no_token
494 assert_no_difference "ActionMailer::Base.deliveries.size" do
495 get :confirm_resend, :display_name => users(:inactive_user).display_name
498 assert_response :redirect
499 assert_redirected_to login_path
500 assert_match "User Inactive User not found.", flash[:error]
503 def test_confirm_resend_unknown_user
504 assert_no_difference "ActionMailer::Base.deliveries.size" do
505 get :confirm_resend, :display_name => "No Such User"
508 assert_response :redirect
509 assert_redirected_to login_path
510 assert_match "User No Such User not found.", flash[:error]
513 def test_confirm_email_get
514 user = users(:normal_user)
515 confirm_string = user.tokens.create.token
517 get :confirm_email, :confirm_string => confirm_string
518 assert_response :success
519 assert_template :confirm_email
522 def test_confirm_email_success
523 user = users(:second_public_user)
524 confirm_string = user.tokens.create.token
526 post :confirm_email, :confirm_string => confirm_string
527 assert_response :redirect
528 assert_redirected_to :action => :account, :display_name => user.display_name
529 assert_match /Confirmed your change of email address/, flash[:notice]
532 def test_confirm_email_already_confirmed
533 user = users(:normal_user)
534 confirm_string = user.tokens.create.token
536 post :confirm_email, :confirm_string => confirm_string
537 assert_response :redirect
538 assert_redirected_to :action => :account, :display_name => user.display_name
539 assert_match /already been confirmed/, flash[:error]
542 def test_confirm_email_bad_token
543 post :confirm_email, :confirm_string => "XXXXX"
544 assert_response :success
545 assert_template :confirm_email
546 assert_match /confirmation code has expired or does not exist/, flash[:error]
550 # test if testing for a gravatar works
551 # this happens when the email is actually changed
552 # which is triggered by the confirmation mail
553 def test_gravatar_auto_enable
554 with_http_stubs "gravatar" do
555 # switch to email that has a gravatar
556 user = users(:first_gravatar_user)
557 confirm_string = user.tokens.create.token
558 # precondition gravatar should be turned off
559 assert !user.image_use_gravatar
560 post :confirm_email, :confirm_string => confirm_string
561 assert_response :redirect
562 assert_redirected_to :action => :account, :display_name => user.display_name
563 assert_match /Confirmed your change of email address/, flash[:notice]
564 # gravatar use should now be enabled
565 assert User.find(users(:first_gravatar_user).id).image_use_gravatar
569 def test_gravatar_auto_disable
570 with_http_stubs "gravatar" do
571 # switch to email without a gravatar
572 user = users(:second_gravatar_user)
573 confirm_string = user.tokens.create.token
574 # precondition gravatar should be turned on
575 assert user.image_use_gravatar
576 post :confirm_email, :confirm_string => confirm_string
577 assert_response :redirect
578 assert_redirected_to :action => :account, :display_name => user.display_name
579 assert_match /Confirmed your change of email address/, flash[:notice]
580 # gravatar use should now be disabled
581 assert !User.find(users(:second_gravatar_user).id).image_use_gravatar
585 def test_terms_new_user
586 get :terms, {}, { :new_user => User.new }
587 assert_response :success
588 assert_template :terms
592 user = users(:normal_user)
594 session[:user] = user.id
597 assert_response :redirect
598 assert_redirected_to :action => :account, :display_name => user.display_name
601 def test_terms_not_seen_without_referer
602 user = users(:terms_not_seen_user)
604 session[:user] = user.id
607 assert_response :success
608 assert_template :terms
610 post :save, :user => { :consider_pd => true }
611 assert_response :redirect
612 assert_redirected_to :action => :account, :display_name => user.display_name
613 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
617 assert_equal true, user.consider_pd
618 assert_not_nil user.terms_agreed
619 assert_equal true, user.terms_seen
622 def test_terms_not_seen_with_referer
623 user = users(:terms_not_seen_user)
625 session[:user] = user.id
627 get :terms, :referer => "/test"
628 assert_response :success
629 assert_template :terms
631 post :save, :user => { :consider_pd => true }, :referer => "/test"
632 assert_response :redirect
633 assert_redirected_to "/test"
634 assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
638 assert_equal true, user.consider_pd
639 assert_not_nil user.terms_agreed
640 assert_equal true, user.terms_seen
644 post :go_public, {}, { :user => users(:normal_user) }
645 assert_response :redirect
646 assert_redirected_to :action => :account, :display_name => users(:normal_user).display_name
647 assert_equal true, User.find(users(:normal_user).id).data_public
650 def test_lost_password
651 # Test fetching the lost password page
653 assert_response :success
654 assert_template :lost_password
655 assert_select "div#notice", false
657 # Test resetting using the address as recorded for a user that has an
658 # address which is duplicated in a different case by another user
659 assert_difference "ActionMailer::Base.deliveries.size", 1 do
660 post :lost_password, :user => { :email => users(:normal_user).email }
662 assert_response :redirect
663 assert_redirected_to :action => :login
664 assert_match /^Sorry you lost it/, flash[:notice]
665 email = ActionMailer::Base.deliveries.first
666 assert_equal 1, email.to.count
667 assert_equal users(:normal_user).email, email.to.first
668 ActionMailer::Base.deliveries.clear
670 # Test resetting using an address that matches a different user
671 # that has the same address in a different case
672 assert_difference "ActionMailer::Base.deliveries.size", 1 do
673 post :lost_password, :user => { :email => users(:normal_user).email.upcase }
675 assert_response :redirect
676 assert_redirected_to :action => :login
677 assert_match /^Sorry you lost it/, flash[:notice]
678 email = ActionMailer::Base.deliveries.first
679 assert_equal 1, email.to.count
680 assert_equal users(:uppercase_user).email, email.to.first
681 ActionMailer::Base.deliveries.clear
683 # Test resetting using an address that is a case insensitive match
684 # for more than one user but not an exact match for either
685 assert_no_difference "ActionMailer::Base.deliveries.size" do
686 post :lost_password, :user => { :email => users(:normal_user).email.titlecase }
688 assert_response :success
689 assert_template :lost_password
690 assert_select ".error", /^Could not find that email address/
692 # Test resetting using the address as recorded for a user that has an
693 # address which is case insensitively unique
694 assert_difference "ActionMailer::Base.deliveries.size", 1 do
695 post :lost_password, :user => { :email => users(:public_user).email }
697 assert_response :redirect
698 assert_redirected_to :action => :login
699 assert_match /^Sorry you lost it/, flash[:notice]
700 email = ActionMailer::Base.deliveries.first
701 assert_equal 1, email.to.count
702 assert_equal users(:public_user).email, email.to.first
703 ActionMailer::Base.deliveries.clear
705 # Test resetting using an address that matches a user that has the
706 # same (case insensitively unique) address in a different case
707 assert_difference "ActionMailer::Base.deliveries.size", 1 do
708 post :lost_password, :user => { :email => users(:public_user).email.upcase }
710 assert_response :redirect
711 assert_redirected_to :action => :login
712 assert_match /^Sorry you lost it/, flash[:notice]
713 email = ActionMailer::Base.deliveries.first
714 assert_equal 1, email.to.count
715 assert_equal users(:public_user).email, email.to.first
716 ActionMailer::Base.deliveries.clear
719 def test_reset_password
720 # Test a request with no token
722 assert_response :bad_request
724 # Test a request with a bogus token
725 get :reset_password, :token => "made_up_token"
726 assert_response :redirect
727 assert_redirected_to :action => :lost_password
729 # Create a valid token for a user
730 token = User.find(users(:inactive_user).id).tokens.create
732 # Test a request with a valid token
733 get :reset_password, :token => token.token
734 assert_response :success
735 assert_template :reset_password
737 # Test setting a new password
738 post :reset_password, :token => token.token, :user => { :pass_crypt => "new_password", :pass_crypt_confirmation => "new_password" }
739 assert_response :redirect
740 assert_redirected_to root_path
741 assert_equal users(:inactive_user).id, session[:user]
742 user = User.find(users(:inactive_user).id)
743 assert_equal "active", user.status
744 assert_equal true, user.email_valid
745 assert_equal user, User.authenticate(:username => "inactive@openstreetmap.org", :password => "new_password")
749 # Get a user to work with - note that this user deliberately
750 # conflicts with uppercase_user in the email and display name
751 # fields to test that we can change other fields without any
752 # validation errors being reported
753 user = users(:normal_user)
755 # Make sure that you are redirected to the login page when
756 # you are not logged in
757 get :account, :display_name => user.display_name
758 assert_response :redirect
759 assert_redirected_to :controller => :user, :action => "login", :referer => "/user/test/account"
761 # Make sure that you are blocked when not logged in as the right user
762 get :account, { :display_name => user.display_name }, { :user => users(:public_user).id }
763 assert_response :forbidden
765 # Make sure we get the page when we are logged in as the right user
766 get :account, { :display_name => user.display_name }, { :user => user }
767 assert_response :success
768 assert_template :account
770 # Updating the description should work
771 user.description = "new description"
772 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
773 assert_response :success
774 assert_template :account
775 assert_select "div#errorExplanation", false
776 assert_select ".notice", /^User information updated successfully/
777 assert_select "form#accountForm > fieldset > div.form-row > div#user_description_container > div#user_description_content > textarea#user_description", user.description
779 # Changing to a invalid editor should fail
780 user.preferred_editor = "unknown"
781 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
782 assert_response :success
783 assert_template :account
784 assert_select ".notice", false
785 assert_select "div#errorExplanation"
786 assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected]", false
788 # Changing to a valid editor should work
789 user.preferred_editor = "potlatch2"
790 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
791 assert_response :success
792 assert_template :account
793 assert_select "div#errorExplanation", false
794 assert_select ".notice", /^User information updated successfully/
795 assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected][value=?]", "potlatch2"
797 # Changing to the default editor should work
798 user.preferred_editor = "default"
799 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
800 assert_response :success
801 assert_template :account
802 assert_select "div#errorExplanation", false
803 assert_select ".notice", /^User information updated successfully/
804 assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected]", false
806 # Changing to an uploaded image should work
807 image = Rack::Test::UploadedFile.new("test/traces/1.gif", "image/gif")
808 post :account, { :display_name => user.display_name, :image_action => "new", :user => user.attributes.merge(:image => image) }, { :user => user.id }
809 assert_response :success
810 assert_template :account
811 assert_select "div#errorExplanation", false
812 assert_select ".notice", /^User information updated successfully/
813 assert_select "form#accountForm > fieldset > div.form-row.accountImage input[name=image_action][checked][value=?]", "keep"
815 # Changing to a gravatar image should work
816 post :account, { :display_name => user.display_name, :image_action => "gravatar", :user => user.attributes }, { :user => user.id }
817 assert_response :success
818 assert_template :account
819 assert_select "div#errorExplanation", false
820 assert_select ".notice", /^User information updated successfully/
821 assert_select "form#accountForm > fieldset > div.form-row.accountImage input[name=image_action][checked][value=?]", "gravatar"
823 # Removing the image should work
824 post :account, { :display_name => user.display_name, :image_action => "delete", :user => user.attributes }, { :user => user.id }
825 assert_response :success
826 assert_template :account
827 assert_select "div#errorExplanation", false
828 assert_select ".notice", /^User information updated successfully/
829 assert_select "form#accountForm > fieldset > div.form-row.accountImage input[name=image_action][checked]", false
831 # Adding external authentication should redirect to the auth provider
832 post :account, { :display_name => user.display_name, :user => user.attributes.merge(:auth_provider => "openid", :auth_uid => "gmail.com") }, { :user => user.id }
833 assert_response :redirect
834 assert_redirected_to auth_path(:provider => "openid", :openid_url => "https://www.google.com/accounts/o8/id", :origin => "/user/#{user.display_name}/account")
836 # Changing name to one that exists should fail
837 new_attributes = user.attributes.dup.merge(:display_name => users(:public_user).display_name)
838 post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id }
839 assert_response :success
840 assert_template :account
841 assert_select ".notice", false
842 assert_select "div#errorExplanation"
843 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_display_name"
845 # Changing name to one that exists should fail, regardless of case
846 new_attributes = user.attributes.dup.merge(:display_name => users(:public_user).display_name.upcase)
847 post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id }
848 assert_response :success
849 assert_template :account
850 assert_select ".notice", false
851 assert_select "div#errorExplanation"
852 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_display_name"
854 # Changing name to one that doesn't exist should work
855 new_attributes = user.attributes.dup.merge(:display_name => "new tester")
856 post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id }
857 assert_response :success
858 assert_template :account
859 assert_select "div#errorExplanation", false
860 assert_select ".notice", /^User information updated successfully/
861 assert_select "form#accountForm > fieldset > div.form-row > input#user_display_name[value=?]", "new tester"
863 # Record the change of name
864 user.display_name = "new tester"
866 # Changing email to one that exists should fail
867 user.new_email = users(:public_user).email
868 assert_no_difference "ActionMailer::Base.deliveries.size" do
869 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
871 assert_response :success
872 assert_template :account
873 assert_select ".notice", false
874 assert_select "div#errorExplanation"
875 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_new_email"
877 # Changing email to one that exists should fail, regardless of case
878 user.new_email = users(:public_user).email.upcase
879 assert_no_difference "ActionMailer::Base.deliveries.size" do
880 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
882 assert_response :success
883 assert_template :account
884 assert_select ".notice", false
885 assert_select "div#errorExplanation"
886 assert_select "form#accountForm > fieldset > div.form-row > input.field_with_errors#user_new_email"
888 # Changing email to one that doesn't exist should work
889 user.new_email = "new_tester@example.com"
890 assert_difference "ActionMailer::Base.deliveries.size", 1 do
891 post :account, { :display_name => user.display_name, :user => user.attributes }, { :user => user.id }
893 assert_response :success
894 assert_template :account
895 assert_select "div#errorExplanation", false
896 assert_select ".notice", /^User information updated successfully/
897 assert_select "form#accountForm > fieldset > div.form-row > input#user_new_email[value=?]", user.new_email
898 email = ActionMailer::Base.deliveries.first
899 assert_equal 1, email.to.count
900 assert_equal user.new_email, email.to.first
901 ActionMailer::Base.deliveries.clear
904 # Check that the user account page will display and contains some relevant
905 # information for the user
907 # Test a non-existent user
908 get :view, :display_name => "unknown"
909 assert_response :not_found
912 get :view, :display_name => "test"
913 assert_response :success
914 assert_select "div#userinformation" do
915 assert_select "a[href^='/user/test/history']", 1
916 assert_select "a[href='/user/test/traces']", 1
917 assert_select "a[href='/user/test/diary']", 1
918 assert_select "a[href='/user/test/diary/comments']", 1
919 assert_select "a[href='/user/test/account']", 0
920 assert_select "a[href='/user/test/blocks']", 0
921 assert_select "a[href='/user/test/blocks_by']", 0
922 assert_select "a[href='/blocks/new/test']", 0
925 # Test a user who has been blocked
926 create(:user_block, :user => users(:blocked_user))
927 get :view, :display_name => "blocked"
928 assert_response :success
929 assert_select "div#userinformation" do
930 assert_select "a[href^='/user/blocked/history']", 1
931 assert_select "a[href='/user/blocked/traces']", 1
932 assert_select "a[href='/user/blocked/diary']", 1
933 assert_select "a[href='/user/blocked/diary/comments']", 1
934 assert_select "a[href='/user/blocked/account']", 0
935 assert_select "a[href='/user/blocked/blocks']", 1
936 assert_select "a[href='/user/blocked/blocks_by']", 0
937 assert_select "a[href='/blocks/new/blocked']", 0
940 # Test a moderator who has applied blocks
941 create(:user_block, :creator => users(:moderator_user))
942 get :view, :display_name => "moderator"
943 assert_response :success
944 assert_select "div#userinformation" do
945 assert_select "a[href^='/user/moderator/history']", 1
946 assert_select "a[href='/user/moderator/traces']", 1
947 assert_select "a[href='/user/moderator/diary']", 1
948 assert_select "a[href='/user/moderator/diary/comments']", 1
949 assert_select "a[href='/user/moderator/account']", 0
950 assert_select "a[href='/user/moderator/blocks']", 0
951 assert_select "a[href='/user/moderator/blocks_by']", 1
952 assert_select "a[href='/blocks/new/moderator']", 0
955 # Login as a normal user
956 session[:user] = users(:normal_user).id
958 # Test the normal user
959 get :view, :display_name => "test"
960 assert_response :success
961 assert_select "div#userinformation" do
962 assert_select "a[href^='/user/test/history']", 1
963 assert_select "a[href='/traces/mine']", 1
964 assert_select "a[href='/user/test/diary']", 1
965 assert_select "a[href='/user/test/diary/comments']", 1
966 assert_select "a[href='/user/test/account']", 1
967 assert_select "a[href='/user/test/blocks']", 0
968 assert_select "a[href='/user/test/blocks_by']", 0
969 assert_select "a[href='/blocks/new/test']", 0
972 # Login as a moderator
973 session[:user] = users(:moderator_user).id
975 # Test the normal user
976 get :view, :display_name => "test"
977 assert_response :success
978 assert_select "div#userinformation" do
979 assert_select "a[href^='/user/test/history']", 1
980 assert_select "a[href='/user/test/traces']", 1
981 assert_select "a[href='/user/test/diary']", 1
982 assert_select "a[href='/user/test/diary/comments']", 1
983 assert_select "a[href='/user/test/account']", 0
984 assert_select "a[href='/user/test/blocks']", 0
985 assert_select "a[href='/user/test/blocks_by']", 0
986 assert_select "a[href='/blocks/new/test']", 1
991 # check that a visible user is returned properly
992 get :api_read, :id => users(:normal_user).id
993 assert_response :success
994 assert_equal "text/xml", response.content_type
996 # check the data that is returned
997 assert_select "description", :count => 1, :text => "test"
998 assert_select "contributor-terms", :count => 1 do
999 assert_select "[agreed='true']"
1001 assert_select "img", :count => 0
1002 assert_select "roles", :count => 1 do
1003 assert_select "role", :count => 0
1005 assert_select "changesets", :count => 1 do
1006 assert_select "[count='0']"
1008 assert_select "traces", :count => 1 do
1009 assert_select "[count='0']"
1011 assert_select "blocks", :count => 1 do
1012 assert_select "received", :count => 1 do
1013 assert_select "[count='0'][active='0']"
1015 assert_select "issued", :count => 0
1018 # check that we aren't revealing private information
1019 assert_select "contributor-terms[pd]", false
1020 assert_select "home", false
1021 assert_select "languages", false
1022 assert_select "messages", false
1024 # check that a suspended user is not returned
1025 get :api_read, :id => users(:suspended_user).id
1026 assert_response :gone
1028 # check that a deleted user is not returned
1029 get :api_read, :id => users(:deleted_user).id
1030 assert_response :gone
1032 # check that a non-existent user is not returned
1033 get :api_read, :id => 0
1034 assert_response :not_found
1037 def test_api_details
1038 create(:message, :read, :recipient => users(:normal_user))
1040 # check that nothing is returned when not logged in
1042 assert_response :unauthorized
1044 # check that we get a response when logged in
1045 basic_authorization(users(:normal_user).email, "test")
1047 assert_response :success
1048 assert_equal "text/xml", response.content_type
1050 # check the data that is returned
1051 assert_select "description", :count => 1, :text => "test"
1052 assert_select "contributor-terms", :count => 1 do
1053 assert_select "[agreed='true'][pd='false']"
1055 assert_select "img", :count => 0
1056 assert_select "roles", :count => 1 do
1057 assert_select "role", :count => 0
1059 assert_select "changesets", :count => 1 do
1060 assert_select "[count='0']", :count => 1
1062 assert_select "traces", :count => 1 do
1063 assert_select "[count='0']", :count => 1
1065 assert_select "blocks", :count => 1 do
1066 assert_select "received", :count => 1 do
1067 assert_select "[count='0'][active='0']"
1069 assert_select "issued", :count => 0
1071 assert_select "home", :count => 1 do
1072 assert_select "[lat='12.1'][lon='12.1'][zoom='3']"
1074 assert_select "languages", :count => 1 do
1075 assert_select "lang", :count => 1, :text => "en"
1077 assert_select "messages", :count => 1 do
1078 assert_select "received", :count => 1 do
1079 assert_select "[count='1'][unread='0']"
1081 assert_select "sent", :count => 1 do
1082 assert_select "[count='1']"
1087 def test_api_gpx_files
1088 # check that nothing is returned when not logged in
1090 assert_response :unauthorized
1092 # check that we get a response when logged in
1093 basic_authorization(users(:normal_user).email, "test")
1095 assert_response :success
1096 assert_equal "text/xml", response.content_type
1098 # check the data that is returned
1099 assert_select "gpx_file[id='1']", 1 do
1100 assert_select "tag", "London"
1102 assert_select "gpx_file[id='4']", 1 do
1103 assert_select "tag", "Birmingham"
1107 def test_make_friend
1108 # Get users to work with
1109 user = users(:normal_user)
1110 friend = users(:second_public_user)
1112 # Check that the users aren't already friends
1113 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1115 # When not logged in a GET should ask us to login
1116 get :make_friend, :display_name => friend.display_name
1117 assert_redirected_to :controller => :user, :action => "login", :referer => make_friend_path(:display_name => friend.display_name)
1119 # When not logged in a POST should error
1120 post :make_friend, :display_name => friend.display_name
1121 assert_response :forbidden
1122 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1124 # When logged in a GET should get a confirmation page
1125 get :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1126 assert_response :success
1127 assert_template :make_friend
1128 assert_select "form" do
1129 assert_select "input[type='hidden'][name='referer']", 0
1130 assert_select "input[type='submit']", 1
1132 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1134 # When logged in a POST should add the friendship
1135 assert_difference "ActionMailer::Base.deliveries.size", 1 do
1136 post :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1138 assert_redirected_to user_path(:display_name => friend.display_name)
1139 assert_match /is now your friend/, flash[:notice]
1140 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1141 email = ActionMailer::Base.deliveries.first
1142 assert_equal 1, email.to.count
1143 assert_equal friend.email, email.to.first
1144 ActionMailer::Base.deliveries.clear
1146 # A second POST should report that the friendship already exists
1147 assert_no_difference "ActionMailer::Base.deliveries.size" do
1148 post :make_friend, { :display_name => friend.display_name }, { :user => user.id }
1150 assert_redirected_to user_path(:display_name => friend.display_name)
1151 assert_match /You are already friends with/, flash[:warning]
1152 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1155 def test_make_friend_with_referer
1156 # Get users to work with
1157 user = users(:normal_user)
1158 friend = users(:second_public_user)
1160 # Check that the users aren't already friends
1161 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1163 # The GET should preserve any referer
1164 get :make_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1165 assert_response :success
1166 assert_template :make_friend
1167 assert_select "form" do
1168 assert_select "input[type='hidden'][name='referer'][value='/test']", 1
1169 assert_select "input[type='submit']", 1
1171 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1173 # When logged in a POST should add the friendship and refer us
1174 assert_difference "ActionMailer::Base.deliveries.size", 1 do
1175 post :make_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1177 assert_redirected_to "/test"
1178 assert_match /is now your friend/, flash[:notice]
1179 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1180 email = ActionMailer::Base.deliveries.first
1181 assert_equal 1, email.to.count
1182 assert_equal friend.email, email.to.first
1183 ActionMailer::Base.deliveries.clear
1186 def test_make_friend_unkown_user
1187 # Should error when a bogus user is specified
1188 get :make_friend, { :display_name => "No Such User" }, { :user => users(:normal_user).id }
1189 assert_response :not_found
1190 assert_template :no_such_user
1193 def test_remove_friend
1194 # Get users to work with
1195 user = users(:normal_user)
1196 friend = users(:public_user)
1197 create(:friend, :befriender => user, :befriendee => friend)
1199 # Check that the users are friends
1200 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1202 # When not logged in a GET should ask us to login
1203 get :remove_friend, :display_name => friend.display_name
1204 assert_redirected_to :controller => :user, :action => "login", :referer => remove_friend_path(:display_name => friend.display_name)
1206 # When not logged in a POST should error
1207 post :remove_friend, :display_name => friend.display_name
1208 assert_response :forbidden
1209 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1211 # When logged in a GET should get a confirmation page
1212 get :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1213 assert_response :success
1214 assert_template :remove_friend
1215 assert_select "form" do
1216 assert_select "input[type='hidden'][name='referer']", 0
1217 assert_select "input[type='submit']", 1
1219 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1221 # When logged in a POST should remove the friendship
1222 post :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1223 assert_redirected_to user_path(:display_name => friend.display_name)
1224 assert_match /was removed from your friends/, flash[:notice]
1225 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1227 # A second POST should report that the friendship does not exist
1228 post :remove_friend, { :display_name => friend.display_name }, { :user => user.id }
1229 assert_redirected_to user_path(:display_name => friend.display_name)
1230 assert_match /is not one of your friends/, flash[:error]
1231 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1234 def test_remove_friend_with_referer
1235 # Get users to work with
1236 user = users(:normal_user)
1237 friend = users(:public_user)
1238 create(:friend, :user_id => user.id, :friend_user_id => friend.id)
1240 # Check that the users are friends
1241 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1243 # The GET should preserve any referer
1244 get :remove_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1245 assert_response :success
1246 assert_template :remove_friend
1247 assert_select "form" do
1248 assert_select "input[type='hidden'][name='referer'][value='/test']", 1
1249 assert_select "input[type='submit']", 1
1251 assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1253 # When logged in a POST should remove the friendship and refer
1254 post :remove_friend, { :display_name => friend.display_name, :referer => "/test" }, { :user => user.id }
1255 assert_redirected_to "/test"
1256 assert_match /was removed from your friends/, flash[:notice]
1257 assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
1260 def test_remove_friend_unkown_user
1261 # Should error when a bogus user is specified
1262 get :remove_friend, { :display_name => "No Such User" }, { :user => users(:normal_user).id }
1263 assert_response :not_found
1264 assert_template :no_such_user
1268 # Try without logging in
1269 get :set_status, :display_name => users(:normal_user).display_name, :status => "suspended"
1270 assert_response :redirect
1271 assert_redirected_to :action => :login, :referer => set_status_user_path(:status => "suspended")
1273 # Now try as a normal user
1274 get :set_status, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:normal_user).id }
1275 assert_response :redirect
1276 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1278 # Finally try as an administrator
1279 get :set_status, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:administrator_user).id }
1280 assert_response :redirect
1281 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1282 assert_equal "suspended", User.find(users(:normal_user).id).status
1286 # Try without logging in
1287 get :delete, :display_name => users(:normal_user).display_name, :status => "suspended"
1288 assert_response :redirect
1289 assert_redirected_to :action => :login, :referer => delete_user_path(:status => "suspended")
1291 # Now try as a normal user
1292 get :delete, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:normal_user).id }
1293 assert_response :redirect
1294 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1296 # Finally try as an administrator
1297 get :delete, { :display_name => users(:normal_user).display_name, :status => "suspended" }, { :user => users(:administrator_user).id }
1298 assert_response :redirect
1299 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name
1301 # Check that the user was deleted properly
1302 user = User.find(users(:normal_user).id)
1303 assert_equal "user_1", user.display_name
1304 assert_equal "", user.description
1305 assert_nil user.home_lat
1306 assert_nil user.home_lon
1307 assert_equal false, user.image.file?
1308 assert_equal false, user.email_valid
1309 assert_nil user.new_email
1310 assert_nil user.auth_provider
1311 assert_nil user.auth_uid
1312 assert_equal "deleted", user.status
1316 # Shouldn't work when not logged in
1318 assert_response :redirect
1319 assert_redirected_to :action => :login, :referer => users_path
1321 session[:user] = users(:normal_user).id
1323 # Shouldn't work when logged in as a normal user
1325 assert_response :redirect
1326 assert_redirected_to :action => :login, :referer => users_path
1328 session[:user] = users(:moderator_user).id
1330 # Shouldn't work when logged in as a moderator
1332 assert_response :redirect
1333 assert_redirected_to :action => :login, :referer => users_path
1335 session[:user] = users(:administrator_user).id
1337 # Should work when logged in as an administrator
1339 assert_response :success
1340 assert_template :list
1341 assert_select "table#user_list tr", :count => User.count + 1
1343 # Should be able to limit by status
1344 get :list, :status => "suspended"
1345 assert_response :success
1346 assert_template :list
1347 assert_select "table#user_list tr", :count => User.where(:status => "suspended").count + 1
1349 # Should be able to limit by IP address
1350 get :list, :ip => "1.2.3.4"
1351 assert_response :success
1352 assert_template :list
1353 assert_select "table#user_list tr", :count => User.where(:creation_ip => "1.2.3.4").count + 1
1356 def test_list_get_paginated
1357 1.upto(100).each do |n|
1358 User.create(:display_name => "extra_#{n}",
1359 :email => "extra#{n}@example.com",
1360 :pass_crypt => "extraextra")
1363 session[:user] = users(:administrator_user).id
1366 assert_response :success
1367 assert_template :list
1368 assert_select "table#user_list tr", :count => 51
1370 get :list, :page => 2
1371 assert_response :success
1372 assert_template :list
1373 assert_select "table#user_list tr", :count => 51
1375 get :list, :page => 3
1376 assert_response :success
1377 assert_template :list
1378 assert_select "table#user_list tr", :count => 25
1381 def test_list_post_confirm
1382 inactive_user = users(:inactive_user)
1383 suspended_user = users(:suspended_user)
1385 # Shouldn't work when not logged in
1386 assert_no_difference "User.active.count" do
1387 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1389 assert_response :redirect
1390 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1391 assert_equal "pending", inactive_user.reload.status
1392 assert_equal "suspended", suspended_user.reload.status
1394 session[:user] = users(:normal_user).id
1396 # Shouldn't work when logged in as a normal user
1397 assert_no_difference "User.active.count" do
1398 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1400 assert_response :redirect
1401 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1402 assert_equal "pending", inactive_user.reload.status
1403 assert_equal "suspended", suspended_user.reload.status
1405 session[:user] = users(:moderator_user).id
1407 # Shouldn't work when logged in as a moderator
1408 assert_no_difference "User.active.count" do
1409 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1411 assert_response :redirect
1412 assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
1413 assert_equal "pending", inactive_user.reload.status
1414 assert_equal "suspended", suspended_user.reload.status
1416 session[:user] = users(:administrator_user).id
1418 # Should work when logged in as an administrator
1419 assert_difference "User.active.count", 2 do
1420 post :list, :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 }
1422 assert_response :redirect
1423 assert_redirected_to :action => :list
1424 assert_equal "confirmed", inactive_user.reload.status
1425 assert_equal "confirmed", suspended_user.reload.status
1428 def test_list_post_hide
1429 normal_user = users(:normal_user)
1430 confirmed_user = users(:confirmed_user)
1432 # Shouldn't work when not logged in
1433 assert_no_difference "User.active.count" do
1434 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1436 assert_response :redirect
1437 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1438 assert_equal "active", normal_user.reload.status
1439 assert_equal "confirmed", confirmed_user.reload.status
1441 session[:user] = users(:normal_user).id
1443 # Shouldn't work when logged in as a normal user
1444 assert_no_difference "User.active.count" do
1445 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1447 assert_response :redirect
1448 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1449 assert_equal "active", normal_user.reload.status
1450 assert_equal "confirmed", confirmed_user.reload.status
1452 session[:user] = users(:moderator_user).id
1454 # Shouldn't work when logged in as a moderator
1455 assert_no_difference "User.active.count" do
1456 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1458 assert_response :redirect
1459 assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
1460 assert_equal "active", normal_user.reload.status
1461 assert_equal "confirmed", confirmed_user.reload.status
1463 session[:user] = users(:administrator_user).id
1465 # Should work when logged in as an administrator
1466 assert_difference "User.active.count", -2 do
1467 post :list, :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 }
1469 assert_response :redirect
1470 assert_redirected_to :action => :list
1471 assert_equal "deleted", normal_user.reload.status
1472 assert_equal "deleted", confirmed_user.reload.status
1479 user.status = "pending"
1480 user.display_name = "new_tester"
1481 user.email = "newtester@osm.org"
1482 user.email_confirmation = "newtester@osm.org"
1483 user.pass_crypt = "testtest"
1484 user.pass_crypt_confirmation = "testtest"