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

[Fix #528] Fix a false positive for Rails/HasManyOrHasOneDependent #530

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
* [#520](https://github.com/rubocop/rubocop-rails/pull/520): Support auto-correction for `Rails/ScopeArgs`. ([@koic][])
* [#524](https://github.com/rubocop/rubocop-rails/pull/524): Add new `Rails/RedundantTravelBack` cop. ([@koic][])

### Bug fixes

* [#528](https://github.com/rubocop/rubocop-rails/issues/528): Fix a false positive for `Rails/HasManyOrHasOneDependent` when specifying `:dependent` strategy with double splat. ([@koic][])

## Changes

* [#260](https://github.com/rubocop/rubocop-rails/issues/260): Change target of `Rails/ContentTag` from `content_tag` method to `tag` method. ([@tabuchi0919][])
Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def contain_valid_options_in_with_options_block?(node)
end

def valid_options?(options)
options = options.first.children.first.pairs if options.first.kwsplat_type?

return true unless options
return true if options.any? do |o|
dependent_option?(o) || present_option?(o)
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/rails/has_many_or_has_one_dependent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ class Person < ApplicationRecord
RUBY
end

it 'does not register an offense when specifying `:dependent` strategy with double splat' do
expect_no_offenses(<<~RUBY)
class Person < ApplicationRecord
has_one :foo, **{dependent: :destroy}
end
RUBY
end

it 'does not register an offense when specifying default `dependent: nil` strategy' do
expect_no_offenses(<<~RUBY)
class Person < ApplicationRecord
Expand Down