Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix the method name with the class name for validation errors #17754

Merged
merged 1 commit into from
Aug 3, 2018

Conversation

bdunne
Copy link
Member

@bdunne bdunne commented Jul 24, 2018

instance.errors.full_messages will now produce something like:
["SomeClass: The attribute can't be blank"]

Full disclosure... I have no idea what else this will effect (especially in the UI) ¯\_(ツ)_/¯

@d-m-u
Copy link
Contributor

d-m-u commented Jul 24, 2018

screen shot 2018-07-24 at 12 18 09 pm
Looks great, thank you.

@jrafanie
Copy link
Member

LGTM, even the test failures show who this affects and they all seem like legitimate things to change in the tests.

@Fryguy
Copy link
Member

Fryguy commented Jul 24, 2018

cc @mzazrivec

@bdunne bdunne force-pushed the better_validation_errors branch from e385a95 to c70bf90 Compare July 24, 2018 17:41
@@ -23,4 +23,8 @@ class ApplicationRecord < ActiveRecord::Base
def self.display_name(number = 1)
n_(model_name.singular.titleize, model_name.plural.titleize, number)
end

def self.human_attribute_name(attribute, *args)
"#{name}: #{super}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should be display_name ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. @jrafanie and I talked about it briefly and we're leaning toward no, but ¯\_(ツ)_/¯

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, that seems to be masking the real model name failing validation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

display_name would get you a nice looking model name, but at the same time the nice looking model name would be translated into current locale (shrug).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, 👎 to using display_name, I don't think this should be translated.

@@ -0,0 +1,13 @@
describe ApplicationRecord do
context ".human_attribute_name puts the class name in the validation error" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well reword this to not upset the puts checker 😆

instance.errors.full_messages will now produce something like:
["SomeClass: The method can't be blank"]
@bdunne bdunne force-pushed the better_validation_errors branch from c70bf90 to 8e53499 Compare July 24, 2018 21:03
@miq-bot
Copy link
Member

miq-bot commented Jul 24, 2018

Checked commit bdunne@8e53499 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
10 files checked, 0 offenses detected
Everything looks fine. ⭐

Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I lean towards not localizing these alerts.

:shipit:

@jrafanie
Copy link
Member

jrafanie commented Aug 3, 2018

Full disclosure... I have no idea what else this will effect (especially in the UI) ¯_(ツ)_/¯

There's only one way to find out. We get burned by indirect validation failures often enough that we should just fix anything that this change affects.

@jrafanie jrafanie merged commit 382ef25 into ManageIQ:master Aug 3, 2018
@jrafanie jrafanie added this to the Sprint 92 Ending Aug 13, 2018 milestone Aug 3, 2018
@jrafanie jrafanie self-assigned this Aug 3, 2018
@jrafanie jrafanie added the core label Aug 3, 2018
@bdunne bdunne deleted the better_validation_errors branch August 3, 2018 20:23
agrare added a commit to agrare/manageiq-api that referenced this pull request Aug 6, 2018
ManageIQ/manageiq#17754 added a prefixed model
name in a number of exceptions which is causing a few specs to fail
which were matching on the raised exception.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants