diff --git a/config/locales/en.yml b/config/locales/en.yml index e70ad899..258316ca 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -12,6 +12,7 @@ en: devise: failure: + no_authentication_allowed: 'You are attempting to access a resource as an authenticated user when that is not allowed. Please sign out and try again.' unauthenticated: 'You need to sign in or sign up before continuing.' unconfirmed: 'You have to confirm your account before continuing.' locked: 'Your account is locked.' diff --git a/lib/devise/controllers/internal_helpers.rb b/lib/devise/controllers/internal_helpers.rb index 3195f492..ce078936 100644 --- a/lib/devise/controllers/internal_helpers.rb +++ b/lib/devise/controllers/internal_helpers.rb @@ -114,6 +114,7 @@ MESSAGE def require_no_authentication if warden.authenticated?(resource_name) resource = warden.user(resource_name) + flash[:alert] = I18n.t("devise.failure.no_authentication_allowed") redirect_to after_sign_in_path_for(resource) end end diff --git a/test/controllers/internal_helpers_test.rb b/test/controllers/internal_helpers_test.rb index 518b887f..a44269d8 100644 --- a/test/controllers/internal_helpers_test.rb +++ b/test/controllers/internal_helpers_test.rb @@ -45,6 +45,14 @@ class HelpersTest < ActionController::TestCase @controller.send :require_no_authentication end + test 'require no authentication sets a flash message' do + @mock_warden.expects(:authenticated?).with(:user).returns(true) + @mock_warden.expects(:user).with(:user).returns(User.new) + @controller.expects(:redirect_to).with(root_path) + @controller.send :require_no_authentication + assert flash[:alert] == I18n.t("devise.failure.no_authentication_allowed") + end + test 'signed in resource returns signed in resource for current scope' do @mock_warden.expects(:authenticate).with(:scope => :user).returns(User.new) assert_kind_of User, @controller.signed_in_resource