Skip to content

Commit

Permalink
Only call #humanize when the message is :invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
tegon committed Jan 2, 2019
1 parent cca5a7b commit c324824
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/devise/failure_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/failure_app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c324824

Please sign in to comment.