Skip to content

Commit

Permalink
[Fix: #1110] Fix false positive for `Rails/RedundantActiveRecordAllMe…
Browse files Browse the repository at this point in the history
…thod` when `all` has any parameters
  • Loading branch information
masato-bkn committed Sep 12, 2023
1 parent fc9a15a commit a731016
Show file tree
Hide file tree
Showing 3 changed files with 22 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 any parameters. ([@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
20 changes: 20 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,26 @@
RUBY
end
end

context 'when `all` has any parameters, it indicates that it is not an Active Record `all`' do
it 'does not register an offense when no method follows `all`' do
expect_no_offenses(<<~RUBY)
page.all(:parameter)
RUBY
end

it 'does not register an offense when method follows `all`' do
expect_no_offenses(<<~RUBY)
page.all(:parameter).do_something
RUBY
end

it 'does not register an offense when method from `ActiveRecord::Querying::QUERYING_METHODS` follows `all`' do
expect_no_offenses(<<~RUBY)
page.all(:parameter).select(some_filter)
RUBY
end
end
end

context 'with no receiver' do
Expand Down

0 comments on commit a731016

Please sign in to comment.