Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/controllers/devise/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def assert_reset_token_passed

# Check if the user should be signed in automatically after resetting the password.
def sign_in_after_reset_password?
resource_class.sign_in_after_reset_password
setting = resource_class.sign_in_after_reset_password
setting.respond_to?(:call) ? setting.call(resource) : setting
end

# Check if proper Lockable module methods are present & unlock strategy
Expand Down
23 changes: 23 additions & 0 deletions test/integration/recoverable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,29 @@ def reset_password(options = {}, &block)
end
end

test 'sign in user automatically with proc' do
swap Devise, sign_in_after_reset_password: ->(resource) { true } do
create_user
request_forgot_password
reset_password

assert warden.authenticated?(:user)
end
end

test 'does not sign in user automatically with proc' do
swap Devise, sign_in_after_reset_password: ->(resource) { false } do
create_user
request_forgot_password
reset_password

assert_contain 'Your password has been changed successfully.'
assert_not_contain 'You are now signed in.'
assert_equal new_user_session_path, @request.path
assert_not warden.authenticated?(:user)
end
end

test 'does not sign in user automatically after changing its password if it\'s locked and unlock strategy is :none or :time' do
[:none, :time].each do |strategy|
swap Devise, unlock_strategy: strategy do
Expand Down