Skip to content

Commit

Permalink
heartcombo#1432 current_user still returning user after sign_out
Browse files Browse the repository at this point in the history
  • Loading branch information
artemk committed Nov 9, 2011
1 parent a5aa03b commit c3880e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/devise/controllers/helpers.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions test/controllers/helpers_test.rb
Expand Up @@ -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)
Expand Down

0 comments on commit c3880e5

Please sign in to comment.