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:
parent
5e2ee5eb6a
commit
f89f71262d
3 changed files with 10 additions and 0 deletions
|
@ -12,6 +12,7 @@ en:
|
||||||
|
|
||||||
devise:
|
devise:
|
||||||
failure:
|
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.'
|
unauthenticated: 'You need to sign in or sign up before continuing.'
|
||||||
unconfirmed: 'You have to confirm your account before continuing.'
|
unconfirmed: 'You have to confirm your account before continuing.'
|
||||||
locked: 'Your account is locked.'
|
locked: 'Your account is locked.'
|
||||||
|
|
|
@ -114,6 +114,7 @@ MESSAGE
|
||||||
def require_no_authentication
|
def require_no_authentication
|
||||||
if warden.authenticated?(resource_name)
|
if warden.authenticated?(resource_name)
|
||||||
resource = warden.user(resource_name)
|
resource = warden.user(resource_name)
|
||||||
|
flash[:alert] = I18n.t("devise.failure.no_authentication_allowed")
|
||||||
redirect_to after_sign_in_path_for(resource)
|
redirect_to after_sign_in_path_for(resource)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,6 +45,14 @@ class HelpersTest < ActionController::TestCase
|
||||||
@controller.send :require_no_authentication
|
@controller.send :require_no_authentication
|
||||||
end
|
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
|
test 'signed in resource returns signed in resource for current scope' do
|
||||||
@mock_warden.expects(:authenticate).with(:scope => :user).returns(User.new)
|
@mock_warden.expects(:authenticate).with(:scope => :user).returns(User.new)
|
||||||
assert_kind_of User, @controller.signed_in_resource
|
assert_kind_of User, @controller.signed_in_resource
|
||||||
|
|
Loading…
Reference in a new issue