From c3880e52e4ee09a4d6540aa04ae6b68fa03e14cc Mon Sep 17 00:00:00 2001 From: artemk Date: Wed, 9 Nov 2011 20:35:19 +0200 Subject: [PATCH] #1432 current_user still returning user after sign_out --- lib/devise/controllers/helpers.rb | 2 ++ test/controllers/helpers_test.rb | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/devise/controllers/helpers.rb b/lib/devise/controllers/helpers.rb index 501aca9a8e..1018332d1c 100644 --- a/lib/devise/controllers/helpers.rb +++ b/lib/devise/controllers/helpers.rb @@ -139,6 +139,7 @@ def sign_out(resource_or_scope=nil) warden.user(scope) # 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) + @current_user = nil end # Sign out all active users or scopes. This helper is useful for signing out all roles @@ -147,6 +148,7 @@ def sign_out_all_scopes Devise.mappings.keys.each { |s| warden.user(s) } warden.raw_session.inspect warden.logout + @current_user = nil end # Returns and delete the url stored in the session for the given scope. Useful diff --git a/test/controllers/helpers_test.rb b/test/controllers/helpers_test.rb index 08a4c9c2a4..2d0a796b30 100644 --- a/test/controllers/helpers_test.rb +++ b/test/controllers/helpers_test.rb @@ -137,6 +137,24 @@ def setup @controller.sign_in(user, :bypass => true) end + test 'sign out clears up any signed in user from all scopes' do + user = User.new + @mock_warden.expects(:user).times(Devise.mappings.size) + @mock_warden.expects(:logout).with().returns(true) + @controller.instance_variable_set(:@current_user, user) + @controller.sign_out + assert_equal nil, @controller.instance_variable_get(:@current_user) + end + + 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(: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(:logout).with(:user).returns(true)