diff --git a/lib/devise/failure_app.rb b/lib/devise/failure_app.rb index 7cedf646..783d2d6e 100644 --- a/lib/devise/failure_app.rb +++ b/lib/devise/failure_app.rb @@ -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) diff --git a/test/failure_app_test.rb b/test/failure_app_test.rb index 8fb8588a..a5952f5f 100644 --- a/test/failure_app_test.rb +++ b/test/failure_app_test.rb @@ -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]