Skip to content

Commit

Permalink
Merge pull request #1114 from masato-bkn/fix/rails_redundant_active_r…
Browse files Browse the repository at this point in the history
…ecord_all_when_all_has_arguments

[Fix: #1110] Fix false positive for `Rails/RedundantActiveRecordAllMethod` when `all` has any parameters
  • Loading branch information
koic authored Sep 12, 2023
2 parents fc9a15a + a731016 commit a56fb0e
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 a56fb0e

Please sign in to comment.