-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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 Cop & ActiveResource relations #6266
Comments
Does this mean that a module for ActiveRecord is no longer linted? module Foo
extend ActiveSupport::Concern
included do
has_many :bazs # 0.59.1 emits warning for this line
end
end
class Bar < ApplicationRecord
include Foo
end |
@yskkin Thanks for the feedback. I think that it is better to check also when using mix-in. The following is a quotation.
What do you think about it? |
I opened a PR #6318 that implements the above idea. |
Follow up of rubocop#6266 (comment). This PR fixes a false negative for `Rails/HasManyOrHasOneDependent` when using the following mix-in case. ```ruby module Foo extend ActiveSupport::Concern included do has_many :bazs # 0.59.1 emits offense for this line end end class Bar < ApplicationRecord include Foo end ``` In rubocop#6298, only subclasses of `AactiveRecord::Base` or `ApplicationRecord` were scoped. But in that approach false negatives occur in the above case. This PR changes the approach to solve the issue rubocop#6266 by skipping it in case of subclass of `ActiveResource::Base`. Also, this PR integrates a series of change log entry which has not yet been released for the fixing of rubocop#6266.
Follow up of #6266 (comment). This PR fixes a false negative for `Rails/HasManyOrHasOneDependent` when using the following mix-in case. ```ruby module Foo extend ActiveSupport::Concern included do has_many :bazs # 0.59.1 emits offense for this line end end class Bar < ApplicationRecord include Foo end ``` In #6298, only subclasses of `AactiveRecord::Base` or `ApplicationRecord` were scoped. But in that approach false negatives occur in the above case. This PR changes the approach to solve the issue #6266 by skipping it in case of subclass of `ActiveResource::Base`. Also, this PR integrates a series of change log entry which has not yet been released for the fixing of #6266.
Follow up of rubocop/rubocop#6266 (comment). This PR fixes a false negative for `Rails/HasManyOrHasOneDependent` when using the following mix-in case. ```ruby module Foo extend ActiveSupport::Concern included do has_many :bazs # 0.59.1 emits offense for this line end end class Bar < ApplicationRecord include Foo end ``` In #6298, only subclasses of `AactiveRecord::Base` or `ApplicationRecord` were scoped. But in that approach false negatives occur in the above case. This PR changes the approach to solve the issue #6266 by skipping it in case of subclass of `ActiveResource::Base`. Also, this PR integrates a series of change log entry which has not yet been released for the fixing of #6266.
Rails/HasManyOrHasOneDependent Cop wants me to define a :dependent option for a has_many relation for a class that extends from a ActiveResource model. Though, for a ActiveResource relation :dependent is not a valid option.
Expected behavior
The Rails/HasManyOrHasOneDependent error should not be triggered for ActiveResource models.
Actual behavior
Rails/HasManyOrHasOneDependent is detected
Steps to reproduce the problem
Include ActiveResource in your project:
Create a ActiveResource class for talking to a REST API:
Running Rubocop gives the following:
but If you add the :dependent option, ActiveResource will throw an exception on runtime:
RuboCop version
0.59.0 (using Parser 2.5.1.2, running on ruby 2.5.1 x86_64-darwin17)
The text was updated successfully, but these errors were encountered: