From: Tom Hughes Date: Tue, 15 Oct 2013 20:27:25 +0000 (+0100) Subject: Test user#reset_password X-Git-Tag: live~4693 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/1abb7bfa56318b293c7a57dd094961b241e0673d?hp=f892313c48d64a7b5453d2772d72648795cf363b Test user#reset_password --- diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index c1b7244cb..15e3cc394 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -46,6 +46,7 @@ inactive_user: terms_agreed: "2010-01-01 11:22:33" terms_seen: true languages: en + email_valid: false second_public_user: id: 4 diff --git a/test/functional/user_controller_test.rb b/test/functional/user_controller_test.rb index 381ec333a..9cf48f470 100644 --- a/test/functional/user_controller_test.rb +++ b/test/functional/user_controller_test.rb @@ -425,6 +425,34 @@ class UserControllerTest < ActionController::TestCase assert_equal users(:public_user).email, ActionMailer::Base.deliveries.last.to[0] end + def test_reset_password + # Test a request with no token + get :reset_password + assert_response :bad_request + + # Test a request with a bogus token + get :reset_password, :token => "made_up_token" + assert_response :redirect + assert_redirected_to :action => :lost_password + + # Create a valid token for a user + token = User.find(users(:inactive_user).id).tokens.create + + # Test a request with a valid token + get :reset_password, :token => token.token + assert_response :success + assert_template :reset_password + + # Test setting a new password + post :reset_password, :token => token.token, :user => { :pass_crypt => "new_password", :pass_crypt_confirmation => "new_password" } + assert_response :redirect + assert_redirected_to :action => :login + user = User.find(users(:inactive_user).id) + assert_equal "active", user.status + assert_equal true, user.email_valid + assert_equal user, User.authenticate(:username => "inactive@openstreetmap.org", :password => "new_password") + end + def test_user_update # Get a user to work with - note that this user deliberately # conflicts with uppercase_user in the email and display name