1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

require_no_authentication now sets flash with I18n message

This commit is contained in:
Jack Dempsey 2011-04-13 09:18:49 +08:00 committed by José Valim
parent 5e2ee5eb6a
commit f89f71262d
3 changed files with 10 additions and 0 deletions

View file

@ -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.'

View file

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

View file

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