Skip to content

Commit

Permalink
[Fix: rubocop#1110] Fix false positive for `Rails/RedundantActiveReco…
Browse files Browse the repository at this point in the history
…rdAllMethod` when `all` has arguments
  • Loading branch information
masato-bkn committed Sep 11, 2023
1 parent fc9bf0c commit e4de9a4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1110](https://github.com/rubocop/rubocop-rails/issues/1110): Fix false positive for `Rails/RedundantActiveRecordAllMethod` when `all` has arguments. ([@masato-bkn][])
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class RedundantActiveRecordAllMethod < Base
].to_set.freeze

def_node_matcher :followed_by_query_method?, <<~PATTERN
(send (send _ :all ...) QUERYING_METHODS ...)
(send (send _ :all) QUERYING_METHODS ...)
PATTERN

def on_send(node)
Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/cop/rails/redundant_active_record_all_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,20 @@
RUBY
end
end

context 'when `all` has parameters (=not Active Record method)' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
page.all(:css, 'a#huga_123')
RUBY
end

it 'does not register an offense when a method follows `all`' do
expect_no_offenses(<<~RUBY)
page.all(:css, 'a#huga_123').select(somefilter)
RUBY
end
end
end

context 'with no receiver' do
Expand Down

0 comments on commit e4de9a4

Please sign in to comment.