Skip to content

Commit 7e62ce2

Browse files
authored
Merge pull request rubocop#530 from koic/fix_a_false_positive_for_rails_has_many_or_has_one_dependent
[Fix rubocop#528] Fix a false positive for `Rails/HasManyOrHasOneDependent`
2 parents 3e86c7b + 68372fb commit 7e62ce2

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
* [#520](https://github.com/rubocop/rubocop-rails/pull/520): Support auto-correction for `Rails/ScopeArgs`. ([@koic][])
99
* [#524](https://github.com/rubocop/rubocop-rails/pull/524): Add new `Rails/RedundantTravelBack` cop. ([@koic][])
1010

11+
### Bug fixes
12+
13+
* [#528](https://github.com/rubocop/rubocop-rails/issues/528): Fix a false positive for `Rails/HasManyOrHasOneDependent` when specifying `:dependent` strategy with double splat. ([@koic][])
14+
1115
## Changes
1216

1317
* [#260](https://github.com/rubocop/rubocop-rails/issues/260): Change target of `Rails/ContentTag` from `content_tag` method to `tag` method. ([@tabuchi0919][])

lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ def contain_valid_options_in_with_options_block?(node)
114114
end
115115

116116
def valid_options?(options)
117+
options = options.first.children.first.pairs if options.first.kwsplat_type?
118+
117119
return true unless options
118120
return true if options.any? do |o|
119121
dependent_option?(o) || present_option?(o)

spec/rubocop/cop/rails/has_many_or_has_one_dependent_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ class Person < ApplicationRecord
2828
RUBY
2929
end
3030

31+
it 'does not register an offense when specifying `:dependent` strategy with double splat' do
32+
expect_no_offenses(<<~RUBY)
33+
class Person < ApplicationRecord
34+
has_one :foo, **{dependent: :destroy}
35+
end
36+
RUBY
37+
end
38+
3139
it 'does not register an offense when specifying default `dependent: nil` strategy' do
3240
expect_no_offenses(<<~RUBY)
3341
class Person < ApplicationRecord

0 commit comments

Comments
 (0)