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

Rails/RedundantPresenceValidationOnBelongsTo should not match strict validations #608

Closed
gaffneyc opened this issue Dec 30, 2021 · 3 comments · Fixed by #610
Closed

Rails/RedundantPresenceValidationOnBelongsTo should not match strict validations #608

gaffneyc opened this issue Dec 30, 2021 · 3 comments · Fixed by #610

Comments

@gaffneyc
Copy link

gaffneyc commented Dec 30, 2021

Expected behavior

Strict changes validations to raise a ActiveModel::StrictValidationFailed instead of populating errors. Since this changes the default behavior the presence validation is not redundant.

belongs_to :project
validates :project, presence: true, strict: true

Actual behavior

user.rb:3:23: C: [Correctable] Rails/RedundantPresenceValidationOnBelongsTo: Remove explicit presence validation for project.
  validates :project, presence: true, strict: true

Steps to reproduce the problem

With user.rb as

class User < ActiveRecord::Base
  belongs_to :project
  validates :project, presence: true, strict: true
end
rubocop user.rb

RuboCop version

1.24.0 (using Parser 3.0.3.2, rubocop-ast 1.15.1, running on ruby 3.0.3 x86_64-linux)
  - rubocop-performance 1.13.0
  - rubocop-rails 2.13.0
@pirj
Copy link
Member

pirj commented Dec 30, 2021

Thanks for reporting!

pirj added a commit to pirj/rubocop-rails that referenced this issue Dec 31, 2021
@pirj
Copy link
Member

pirj commented Dec 31, 2021

Hey @gaffneyc, I've sent a fix in #610, does it fix your case?

pirj added a commit to pirj/rubocop-rails that referenced this issue Dec 31, 2021
@gaffneyc
Copy link
Author

I skimmed the commit and it looks like it should be a fix. I'm not able to test it locally at the moment.

pirj added a commit to pirj/rubocop-rails that referenced this issue Dec 31, 2021
pirj added a commit to pirj/rubocop-rails that referenced this issue Jan 1, 2022
@koic koic closed this as completed in #610 Jan 4, 2022
koic added a commit that referenced this issue Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants