Deprecate anybody_signed_in? in favor of signed_in?(nil)

This commit is contained in:
Gavin Hughes 2010-11-27 20:33:38 +08:00 committed by José Valim
parent 1d6944d201
commit fe5ef25614
2 changed files with 14 additions and 12 deletions

View File

@ -72,16 +72,18 @@ module Devise
false
end
# Check if the given scope is signed in session, without running
# authentication hooks.
def signed_in?(scope)
warden.authenticate?(:scope => scope)
# Return true if the given scope is signed in session. If no scope given, return
# true if any scope is signed in. Does not run authentication hooks.
def signed_in?(scope=nil)
[ scope || Devise.mappings.keys ].flatten.any? do |scope|
warden.authenticate?(:scope => scope)
end
end
# Check if the any scope is signed in session, without running
# authentication hooks.
def anybody_signed_in?
Devise.mappings.keys.any? { |scope| signed_in?(scope) }
ActiveSupport::Deprecation.warn "Devise#anybody_signed_in? is deprecated. "
"Please use Devise#signed_in?(nil) instead."
signed_in?
end
# Sign in an user that already was authenticated. This helper is useful for logging

View File

@ -13,16 +13,16 @@ class ControllerAuthenticableTest < ActionController::TestCase
assert_equal @mock_warden, @controller.warden
end
test 'proxy signed_in? to authenticated' do
test 'proxy signed_in?(scope) to authenticate?' do
@mock_warden.expects(:authenticate?).with(:scope => :my_scope)
@controller.signed_in?(:my_scope)
end
test 'proxy anybody_signed_in? to signed_in?' do
test 'proxy signed_in?(nil) to authenticate?' do
Devise.mappings.keys.each do |scope| # :user, :admin, :manager
@controller.expects(:signed_in?).with(scope)
@mock_warden.expects(:authenticate?).with(:scope => scope)
end
@controller.anybody_signed_in?
@controller.signed_in?
end
test 'proxy current_user to authenticate with user scope' do