Skip to content

Commit 8d56636

Browse files
committed
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
1 parent 13d0341 commit 8d56636

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

test/form_builder/wrapper_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class WrapperTest < ActionView::TestCase
161161
test 'custom wrappers can have full error message on attributes' do
162162
swap_wrapper :default, custom_wrapper_with_full_error do
163163
with_form_for @user, :name
164-
assert_select 'span.error', "Name cannot be blank"
164+
assert_select 'span.error', "Super User Name! cannot be blank"
165165
end
166166
end
167167

test/support/models.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def has_attribute?(attribute)
204204

205205
def self.human_attribute_name(attribute, options = {})
206206
case attribute
207-
when 'name'
207+
when 'name', :name
208208
'Super User Name!'
209209
when 'description'
210210
'User Description!'

0 commit comments

Comments
 (0)