mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Move duplicate sign_in logic to sign_in().
This commit is contained in:
parent
c27bc21af9
commit
13e8bc22e3
2 changed files with 19 additions and 7 deletions
|
@ -110,6 +110,8 @@ module Devise
|
|||
|
||||
if options[:bypass]
|
||||
warden.session_serializer.store(resource, scope)
|
||||
elsif warden.user(scope) == resource && !options.delete(:force)
|
||||
# Do nothing. User already signed in and we are not forcing it.
|
||||
else
|
||||
warden.set_user(resource, options.merge!(:scope => scope))
|
||||
end
|
||||
|
@ -199,13 +201,7 @@ module Devise
|
|||
options = args.extract_options!
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
resource = args.last || resource_or_scope
|
||||
|
||||
if warden.user(scope) == resource
|
||||
expire_session_data_after_sign_in!
|
||||
else
|
||||
sign_in(scope, resource, options)
|
||||
end
|
||||
|
||||
sign_in(scope, resource, options)
|
||||
redirect_for_sign_in(scope, resource)
|
||||
end
|
||||
|
||||
|
|
|
@ -90,16 +90,32 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
|||
|
||||
test 'sign in proxy to set_user on warden' do
|
||||
user = User.new
|
||||
@mock_warden.expects(:user).returns(nil)
|
||||
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
||||
@controller.sign_in(:user, user)
|
||||
end
|
||||
|
||||
test 'sign in accepts a resource as argument' do
|
||||
user = User.new
|
||||
@mock_warden.expects(:user).returns(nil)
|
||||
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
||||
@controller.sign_in(user)
|
||||
end
|
||||
|
||||
test 'does not sign in again if the user is already in' do
|
||||
user = User.new
|
||||
@mock_warden.expects(:user).returns(user)
|
||||
@mock_warden.expects(:set_user).never
|
||||
@controller.sign_in(user)
|
||||
end
|
||||
|
||||
test 'sign in again when the user is already in only if force is given' do
|
||||
user = User.new
|
||||
@mock_warden.expects(:user).returns(user)
|
||||
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
||||
@controller.sign_in(user, :force => true)
|
||||
end
|
||||
|
||||
test 'sign in accepts bypass as option' do
|
||||
user = User.new
|
||||
@mock_warden.expects(:session_serializer).returns(serializer = mock())
|
||||
|
|
Loading…
Reference in a new issue