Add ability to override the redirect path after user has reset their password

This commit is contained in:
Tan Jun Rong
2013-04-22 20:22:53 +08:00
parent c8aa5f3e62
commit 9d5a9c8a61
2 changed files with 33 additions and 1 deletions

View File

@@ -34,13 +34,16 @@ class Devise::PasswordsController < DeviseController
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
set_flash_message(:notice, flash_message) if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_in_path_for(resource)
respond_with resource, :location => after_reseting_password_path_for(resource)
else
respond_with resource
end
end
protected
def after_reseting_password_path_for(resource_name)
after_sign_in_path_for(resource)
end
# The path used after sending reset password instructions
def after_sending_reset_password_instructions_path_for(resource_name)

View File

@@ -0,0 +1,29 @@
require 'test_helper'
class PasswordsControllerTest < ActionController::TestCase
tests Devise::PasswordsController
include Devise::TestHelpers
def setup
request.env["devise.mapping"] = Devise.mappings[:user]
@user = create_user
@user.send_reset_password_instructions
end
def put_update_with_params
put :update, "user"=>{"reset_password_token"=>@user.reset_password_token, "password"=>"123456", "password_confirmation"=>"123456"}
end
test 'redirect to after_sign_in_path_for if after_reseting_password_path_for is not overridden' do
put_update_with_params
assert_redirected_to "http://test.host/"
end
test 'redirect accordingly if after_reseting_password_path_for is overridden' do
custom_path = "http://custom.path/"
# Overwrite after_reseting_password_path_for with custom_path
Devise::PasswordsController.any_instance.stubs(:after_reseting_password_path_for).with(@user).returns(custom_path)
put_update_with_params
assert_redirected_to custom_path
end
end