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/HasManyOrHasOneDependent false positive when passing a scope #541

Closed
francois-ferrandis opened this issue Sep 10, 2021 · 1 comment · Fixed by #542
Closed

Rails/HasManyOrHasOneDependent false positive when passing a scope #541

francois-ferrandis opened this issue Sep 10, 2021 · 1 comment · Fixed by #542
Labels
bug Something isn't working

Comments

@francois-ferrandis
Copy link

Expected behavior

No offfence detected

Actual behavior

Rails/HasManyOrHasOneDependent is detected

Steps to reproduce the problem

Given this model:

class Message < ApplicationRecord
  has_many :comments, -> { order(:created_at) }, dependent: :destroy, inverse_of: :message
end

I get:

app/models/message.rb:2:3: C: Rails/HasManyOrHasOneDependent: Specify a :dependent option.
  has_many :comments, -> { order(:created_at) }, dependent: :destroy, inverse_of: :message
  ^^^^^^^^

RuboCop version

1.20.0 (using Parser 3.0.2.0, rubocop-ast 1.11.0, running on ruby 3.0.2 x86_64-linux)
  - rubocop-rails 2.12.1
@koic koic transferred this issue from rubocop/rubocop Sep 10, 2021
@koic koic added the bug Something isn't working label Sep 10, 2021
koic added a commit to koic/rubocop-rails that referenced this issue Sep 10, 2021
…ndent`

Fixes rubocop#541.

This PR fixes a false positive for `Rails/HasManyOrHasOneDependent`
when using lambda argument and specifying `:dependent` strategy.
koic added a commit to koic/rubocop-rails that referenced this issue Sep 11, 2021
…ndent`

Fixes rubocop#541.

This PR fixes a false positive for `Rails/HasManyOrHasOneDependent`
when using lambda argument and specifying `:dependent` strategy.
@koic koic closed this as completed in #542 Sep 11, 2021
koic added a commit that referenced this issue Sep 11, 2021
…many_or_has_one_dependent

[Fix #541] Fix a false positive for `Rails/HasManyOrHasOneDependent`
@koic
Copy link
Member

koic commented Sep 11, 2021

RuboCop Rails 2.12.2 has been released with a fix for this issue.
https://github.com/rubocop/rubocop-rails/releases/tag/v2.12.2

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants