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

Check for a Hash when using the authentication_keys to generate the FailureApp flash message.

Fixes #3270.
This commit is contained in:
Lucas Mazza 2014-10-27 22:32:19 -02:00
parent b910f5eb83
commit a93edc72fd
2 changed files with 10 additions and 1 deletions

View file

@ -78,7 +78,9 @@ module Devise
options[:resource_name] = scope
options[:scope] = "devise.failure"
options[:default] = [message]
options[:authentication_keys] = scope_class.authentication_keys.join(I18n.translate(:"support.array.words_connector"))
auth_keys = scope_class.authentication_keys
keys = auth_keys.respond_to?(:keys) ? auth_keys.keys : auth_keys
options[:authentication_keys] = keys.join(I18n.translate(:"support.array.words_connector"))
options = i18n_options(options)
I18n.t(:"#{scope}.#{message}", options)

View file

@ -109,6 +109,13 @@ class FailureTest < ActiveSupport::TestCase
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
end
test 'supports authentication_keys as a Hash for the flash message' do
swap Devise, authentication_keys: { email: true, login: true } do
call_failure('warden' => OpenStruct.new(message: :invalid))
assert_equal 'Invalid email, login or password.', @request.flash[:alert]
end
end
test 'uses custom i18n options' do
call_failure('warden' => OpenStruct.new(message: :does_not_exist), app: FailureWithI18nOptions)
assert_equal 'User Steve does not exist', @request.flash[:alert]