-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
Rails/RedundantPresenceValidationOnBelongsTo should be marked as unsafe for auto-correct #615
Comments
I'm not convinced that As for the error message itself, "can't be blank" vs "must exist", I agree. It affects the error message shown to the end users, and changing it blindly may be problematic in some cases. E.g. when Would you like to send a PR to change the cop's |
@pirj will do so shortly |
…feAutoCorrect: false
…feAutoCorrect: false
…feAutoCorrect: false
[Fix #615] Change Rails/RedundantPresenceValidationOnBelongsTo to SafeAutoCorrect: false
Is your feature request related to a problem? Please describe.
RedundantPresenceValidationOnBelongsTo
is currently marked as safe for auto-correction. This is incorrect, as removing the validation changes the error message that is generated when the association is missing.The default error message when using
validates :foo, presence: true
is "foo can't be blank".The default error message for a required
belongs_to :foo
without the presence validation is "foo must exist".This can break tests/behavior that rely on the error message.
Describe the solution you'd like
RedundantPresenceValidationOnBelongsTo should be marked as unsafe for auto-correct.
Describe alternatives you've considered
Additional context
Here's an example spec failure, using ThoughtBot's shoulda_matchers, after the auto-correction was applied:
The text was updated successfully, but these errors were encountered: