Conversation
| context 'with error detail symbol defined as type option on error' do | ||
| it 'returns a hash with success, errors, and error_details keys' do | ||
| errors = ActiveModel::Errors.new(build_stubbed(:user)) | ||
| errors.add(:email_language, 'Language cannot be blank', type: :blank) |
There was a problem hiding this comment.
I may be misinterpreting, but in trying to refamiliarize myself with the errors API (source, docs), I think this usage isn't actually "standard", and the sort of thing we're trying to enforce with type is probably better articulated by always specifying type as the second argument, and providing a message option instead.
# Instead of...
errors.add(:email_language, 'Language cannot be blank', type: :blank)
# ...do this:
errors.add(:email_language, :blank, message: 'Language cannot be blank')However, at this point, we already have a linter to enforce the former, and it's pretty widespread throughout the application. Supporting it this way gets us to the same net result, but we may also want to consider migrating to the more "standard" option.
|
There's a good chance the build may fail if we've been expecting this form of |
|
There's indeed a lot of test failures now. I wonder if this is also a good opportunity to revive #7454 if we're going to be changing the expected value structure anyways. |
|
Considering #9572 as a replacement for this. |
|
Closing in favor of #9572 |
🛠 Summary of changes
Improves
FormResponse's serialization oferror_detailsto consistently opt for the symbol form of the individual error.The specs already largely asserted for this behavior, but only when calling
errors.addwith a symbol as the second argument (see related #9569).For context,
error_detailswas added in #5048 as a way to support querying for errors within logs irrespective of locale by assigning a locale-independent symbol type. Therefore, including human-readable strings inerror_detailsis counter to the original goal of the property.Extracted from #9564
📜 Testing Plan