From 8d56636ccf079739d7e23ef8d56755e340ecae4e Mon Sep 17 00:00:00 2001 From: Leonardo Tegon Date: Fri, 20 Sep 2019 11:18:37 -0300 Subject: [PATCH] Fix full error message test on Rails 6 Before Rails 6, `#human_attribute_name` was called with an symbol as the first argument (`:name`) which made the switch case execute the `else` branch (calling `attribute.to_s.humanize`). Ref: https://github.com/rails/rails/blob/5-2-stable/activemodel/lib/active_model/errors.rb#L370 On Rails 6, `#human_attribute_name` is always called with a String (`"name"`) which made our switch case to execute the first branch. Since the attribute name was not the most important part of the test - the full error message is what we care about - I decided to change the test in order to make it work on both versions. References: - https://github.com/rails/rails/blob/6-0-stable/activemodel/lib/active_model/errors.rb#L414 - https://github.com/rails/rails/blob/6-0-stable/activemodel/lib/active_model/errors.rb#L448 --- test/form_builder/wrapper_test.rb | 2 +- test/support/models.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/form_builder/wrapper_test.rb b/test/form_builder/wrapper_test.rb index fd2dc8c4..f07e473b 100644 --- a/test/form_builder/wrapper_test.rb +++ b/test/form_builder/wrapper_test.rb @@ -161,7 +161,7 @@ class WrapperTest < ActionView::TestCase test 'custom wrappers can have full error message on attributes' do swap_wrapper :default, custom_wrapper_with_full_error do with_form_for @user, :name - assert_select 'span.error', "Name cannot be blank" + assert_select 'span.error', "Super User Name! cannot be blank" end end diff --git a/test/support/models.rb b/test/support/models.rb index da25b967..9801a7a2 100644 --- a/test/support/models.rb +++ b/test/support/models.rb @@ -204,7 +204,7 @@ class User def self.human_attribute_name(attribute, options = {}) case attribute - when 'name' + when 'name', :name 'Super User Name!' when 'description' 'User Description!'