-
-
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/HasManyOrHasOneDependent false positive when has_one
called on a class instance
#687
Labels
bug
Something isn't working
Comments
jcsanti
added a commit
to jcsanti/rubocop-rails
that referenced
this issue
Jun 25, 2022
Ensure the cop does not ignore `has_many`, `has_one` or even `with_options` when called on an explicit receiver. An example where this can happen is a decorator implemented using a module that prepends itself to the target class: ```RUBY class Person < ApplicationRecord; end module PersonDecorator extend ActiveSupport::Concern def self.prepended(base) base.has_one :foo, dependent: nil end Person.prepend self end ```
jcsanti
added a commit
to jcsanti/rubocop-rails
that referenced
this issue
Jun 25, 2022
Ensure the cop does not ignore `has_many`, `has_one` or even `with_options` when called on an explicit receiver. An example where this can happen is a decorator implemented using a module that prepends itself to the target class: ```RUBY class Person < ApplicationRecord; end module PersonDecorator extend ActiveSupport::Concern def self.prepended(base) base.has_one :foo, dependent: nil end Person.prepend self end ```
jcsanti
added a commit
to jcsanti/rubocop-rails
that referenced
this issue
Jun 26, 2022
Ensure the cop does not ignore `has_many`, `has_one` or even `with_options` when called on an explicit receiver. An example where this can happen is a decorator implemented using a module that prepends itself to the target class: ```RUBY class Person < ApplicationRecord; end module PersonDecorator extend ActiveSupport::Concern def self.prepended(base) base.has_one :foo, dependent: nil end Person.prepend self end ```
jcsanti
added a commit
to jcsanti/rubocop-rails
that referenced
this issue
Jun 26, 2022
Ensure the cop does not ignore `has_many`, `has_one` or even `with_options` when called on an explicit receiver. An example where this can happen is a decorator implemented using a module that prepends itself to the target class: ```RUBY class Person < ApplicationRecord; end module PersonDecorator extend ActiveSupport::Concern def self.prepended(base) base.has_one :foo, dependent: nil end Person.prepend self end ```
@jcsanti would you like to open a PR with your changes? |
Thank you @fatkodima 🎉 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When defining a decorator of a model we sometimes call
has_one
orhas_many
on thebase
class we are decorating:The
Rails/HasManyOrHasOneDependent
cop still triggers, which seems like a false positive:Expected behavior
The cop should detect that
dependent: :destroy
is already defined.Actual behavior
The cop fails suggesting
dependent: :destroy
is not present.Steps to reproduce the problem
Call
has_one
orhas_many
on a class instance rather than as part of a class definition.RuboCop version
The text was updated successfully, but these errors were encountered: