From 77d6d1e8c2faaa5be6c7edf3caa9d25acff443dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 22 Jun 2011 15:28:29 -0300 Subject: [PATCH] Do not try to authenticate with no_input_strategies are empty. --- lib/devise/controllers/internal_helpers.rb | 5 +++-- test/controllers/internal_helpers_test.rb | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/devise/controllers/internal_helpers.rb b/lib/devise/controllers/internal_helpers.rb index 930e37f3..805a3c5c 100644 --- a/lib/devise/controllers/internal_helpers.rb +++ b/lib/devise/controllers/internal_helpers.rb @@ -91,8 +91,9 @@ MESSAGE # Example: # before_filter :require_no_authentication, :only => :new def require_no_authentication - args = devise_mapping.no_input_strategies.dup.push :scope => resource_name - if warden.authenticate?(*args) + no_input = devise_mapping.no_input_strategies + args = no_input.dup.push :scope => resource_name + if no_input.present? && warden.authenticate?(*args) resource = warden.user(resource_name) flash[:alert] = I18n.t("devise.failure.already_authenticated") redirect_to after_sign_in_path_for(resource) diff --git a/test/controllers/internal_helpers_test.rb b/test/controllers/internal_helpers_test.rb index c2457817..30f45609 100644 --- a/test/controllers/internal_helpers_test.rb +++ b/test/controllers/internal_helpers_test.rb @@ -45,6 +45,13 @@ class HelpersTest < ActionController::TestCase @controller.send :require_no_authentication end + test 'require no authentication skips if no inputs are available' do + Devise.mappings[:user].expects(:no_input_strategies).returns([]) + @mock_warden.expects(:authenticate?).never + @controller.expects(:redirect_to).never + @controller.send :require_no_authentication + end + test 'require no authentication sets a flash message' do @mock_warden.expects(:authenticate?).with(:rememberable, :token_authenticatable, :scope => :user).returns(true) @mock_warden.expects(:user).with(:user).returns(User.new)