diff --git a/lib/devise/controllers/helpers.rb b/lib/devise/controllers/helpers.rb index 7f887120..834226e5 100644 --- a/lib/devise/controllers/helpers.rb +++ b/lib/devise/controllers/helpers.rb @@ -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 diff --git a/test/controllers/helpers_test.rb b/test/controllers/helpers_test.rb index d77a5c20..83578a6a 100644 --- a/test/controllers/helpers_test.rb +++ b/test/controllers/helpers_test.rb @@ -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