-
-
Notifications
You must be signed in to change notification settings - Fork 268
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 removes other validations on the same line #603
Comments
Thanks for reporting, I'm working on a fix. |
@Narnach, @texpert, @pyromaniac I've fixed this in #609, does fix your cases? |
Yay, works like a charm! Thanks, @pirj |
The test cases cover the problems I encountered and even went further by decomposing a presence/uniqueness combined case. Excellent work! |
[Fix #603] Teach RedundantPresenceValidationOnBelongsTo to work with multi-attribute validations
The
Rails/RedundantPresenceValidationOnBelongsTo
cop introduced in #594 deletes entirevalidates
statements with multiple validated attributes, when only one of them is abelongs_to
reference.I've managed to expose the underlying issue in a spec, but I'm not familiar enough (yet) with Rubocop internals to easily come up with a PR that fixes it.
Expected behavior
Applying
Rails/RedundantPresenceValidationOnBelongsTo
to this code:Is expected to only remove the
:user
validation, but leave the:name
validation.Actual behavior
The entire
validates
line is removed, causing the validation on:name
to be lost.Steps to reproduce the problem
I've created a failing spec that exposes the auto-correction bug:
It fails due to the entire validation line getting deleted.
I think the offense should only point to
:user
, resulting in this:RuboCop version
I encountered this in our own app after upgrading to rubocop-rails 2.13.0.
In isolation I can replicate it with the latest rubocop-rails
master
, 1e9c257.The text was updated successfully, but these errors were encountered: