From c32482486dc1db30ae34ef2da81096aaa4b31639 Mon Sep 17 00:00:00 2001 From: Leonardo Tegon Date: Wed, 2 Jan 2019 10:56:35 -0200 Subject: [PATCH] Only call `#humanize` when the message is `:invalid` --- lib/devise/failure_app.rb | 5 ++++- test/failure_app_test.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/devise/failure_app.rb b/lib/devise/failure_app.rb index e71e73c1c..db48d2723 100644 --- a/lib/devise/failure_app.rb +++ b/lib/devise/failure_app.rb @@ -106,8 +106,11 @@ def i18n_message(default = nil) keys = (auth_keys.respond_to?(:keys) ? auth_keys.keys : auth_keys).map { |key| scope_class.human_attribute_name(key).downcase } options[:authentication_keys] = keys.join(I18n.translate(:"support.array.words_connector")) options = i18n_options(options) + translated_message = I18n.t(:"#{scope}.#{message}", options) - I18n.t(:"#{scope}.#{message}", options).humanize + # only call `#humanize` when the message is `:invalid` to ensure the original format + # of other messages - like `:does_not_exist` - is kept. + message == :invalid ? translated_message.humanize : translated_message else message.to_s end diff --git a/test/failure_app_test.rb b/test/failure_app_test.rb index ee9502952..b55bb2ee6 100644 --- a/test/failure_app_test.rb +++ b/test/failure_app_test.rb @@ -176,7 +176,7 @@ def call_failure(env_params={}) 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] + assert_equal 'User Steve does not exist', @request.flash[:alert] end test 'uses the proxy failure message as string' do