Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix: #1110] Fix false positive for Rails/RedundantActiveRecordAllMethod when all has any parameters #1114

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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