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 fc9a15a commit aa29805
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 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
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 parameters (=not `all` is not Active Record method)' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
page.all(some_argument)
RUBY
end

it 'does not register an offense when method follows `all`' do
expect_no_offenses(<<~RUBY)
page.all(some_argument).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(some_argument).select(some_filter)
RUBY
end
end
end

context 'with no receiver' do
Expand Down

0 comments on commit aa29805

Please sign in to comment.