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 incorrectly flags with_options blocks #4747

Closed
rdunlop opened this issue Sep 16, 2017 · 1 comment · Fixed by #4828
Closed

Rails/HasManyOrHasOneDependent incorrectly flags with_options blocks #4747

rdunlop opened this issue Sep 16, 2017 · 1 comment · Fixed by #4828
Labels

Comments

@rdunlop
Copy link
Contributor

rdunlop commented Sep 16, 2017

My code has:

class Registrant < ApplicationRecord
  with_options dependent: :destroy do
    has_one :contact_detail, autosave: true, inverse_of: :registrant
    has_one :standard_skill_routine
  end
end

And the rubocop HasManyOrHasOneDependent flags it:

app/models/registrant.rb:49:5: C: Rails/HasManyOrHasOneDependent: Specify a :dependent option.
    has_one :contact_detail, autosave: true, inverse_of: :registrant
    ^^^^^^^
app/models/registrant.rb:50:5: C: Rails/HasManyOrHasOneDependent: Specify a :dependent option.
    has_one :standard_skill_routine
    ^^^^^^^

This is unexpected, since I am specifying a dependent option for the has_one...just not directly (which is permitted by rails)

http://api.rubyonrails.org/classes/Object.html#method-i-with_options

Expected behavior

Not flag my code for having no dependent: option.

Actual behavior

Flags the code as needing a depndent: option

Steps to reproduce the problem

See above code

RuboCop version

0.50.0

@bbatsov bbatsov added the bug label Sep 16, 2017
@bbatsov
Copy link
Collaborator

bbatsov commented Sep 16, 2017

Yeah, guess we didn't factor this when the cop was developed. Should be relatively easy to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants