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
This commit is contained in:
parent
13d0341bdf
commit
8d56636ccf
|
@ -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
|
||||
|
||||
|
|
|
@ -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!'
|
||||
|
|
Loading…
Reference in New Issue