Do not try to authenticate with no_input_strategies are empty.

This commit is contained in:
José Valim
2011-06-22 15:28:29 -03:00
parent 04b614ce10
commit 77d6d1e8c2
2 changed files with 10 additions and 2 deletions

View File

@@ -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)

View File

@@ -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)