mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-10 08:08:00 -05:00
Add ability to override the redirect path after user has reset their password
This commit is contained in:
@@ -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)
|
||||
|
||||
29
test/controllers/passwords_controller_test.rb
Normal file
29
test/controllers/passwords_controller_test.rb
Normal 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
|
||||
Reference in New Issue
Block a user