Skip to content

Commit

Permalink
sign_out helper uses the new warden api
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo Flores committed Feb 16, 2012
1 parent 71f5a01 commit 9e7ab38
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/devise/controllers/helpers.rb
Expand Up @@ -136,7 +136,7 @@ def sign_in(resource_or_scope, *args)
def sign_out(resource_or_scope=nil)
return sign_out_all_scopes unless resource_or_scope
scope = Devise::Mapping.find_scope!(resource_or_scope)
warden.user(scope) # Without loading user here, before_logout hook is not called
warden.user(:scope => scope, :run_callbacks => false) # Without loading user here, before_logout hook is not called
warden.raw_session.inspect # Without this inspect here. The session does not clear.
warden.logout(scope)
instance_variable_set(:"@current_#{scope}", nil)
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/helpers_test.rb
Expand Up @@ -141,21 +141,21 @@ def setup

test 'sign out clears up any signed in user by scope' do
user = User.new
@mock_warden.expects(:user).with(:user).returns(user)
@mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(user)
@mock_warden.expects(:logout).with(:user).returns(true)
@controller.instance_variable_set(:@current_user, user)
@controller.sign_out(:user)
assert_equal nil, @controller.instance_variable_get(:@current_user)
end

test 'sign out proxy to logout on warden' do
@mock_warden.expects(:user).with(:user).returns(true)
@mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(true)
@mock_warden.expects(:logout).with(:user).returns(true)
@controller.sign_out(:user)
end

test 'sign out accepts a resource as argument' do
@mock_warden.expects(:user).with(:user).returns(true)
@mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(true)
@mock_warden.expects(:logout).with(:user).returns(true)
@controller.sign_out(User.new)
end
Expand Down Expand Up @@ -230,7 +230,7 @@ def setup

test 'sign out and redirect uses the configured after sign out path when signing out only the current scope' do
swap Devise, :sign_out_all_scopes => false do
@mock_warden.expects(:user).with(:admin).returns(true)
@mock_warden.expects(:user).with(:scope => :admin, :run_callbacks => false).returns(true)
@mock_warden.expects(:logout).with(:admin).returns(true)
@controller.expects(:redirect_to).with(admin_root_path)
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
Expand Down

0 comments on commit 9e7ab38

Please sign in to comment.