Skip to content

Commit a56fb0e

Browse files
authored
Merge pull request #1114 from masato-bkn/fix/rails_redundant_active_record_all_when_all_has_arguments
[Fix: #1110] Fix false positive for `Rails/RedundantActiveRecordAllMethod` when `all` has any parameters
2 parents fc9a15a + a731016 commit a56fb0e

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1110](https://github.com/rubocop/rubocop-rails/issues/1110): Fix false positive for `Rails/RedundantActiveRecordAllMethod` when `all` has any parameters. ([@masato-bkn][])

lib/rubocop/cop/rails/redundant_active_record_all_method.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class RedundantActiveRecordAllMethod < Base
127127
].to_set.freeze
128128

129129
def_node_matcher :followed_by_query_method?, <<~PATTERN
130-
(send (send _ :all ...) QUERYING_METHODS ...)
130+
(send (send _ :all) QUERYING_METHODS ...)
131131
PATTERN
132132

133133
def on_send(node)

spec/rubocop/cop/rails/redundant_active_record_all_method_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,26 @@
260260
RUBY
261261
end
262262
end
263+
264+
context 'when `all` has any parameters, it indicates that it is not an Active Record `all`' do
265+
it 'does not register an offense when no method follows `all`' do
266+
expect_no_offenses(<<~RUBY)
267+
page.all(:parameter)
268+
RUBY
269+
end
270+
271+
it 'does not register an offense when method follows `all`' do
272+
expect_no_offenses(<<~RUBY)
273+
page.all(:parameter).do_something
274+
RUBY
275+
end
276+
277+
it 'does not register an offense when method from `ActiveRecord::Querying::QUERYING_METHODS` follows `all`' do
278+
expect_no_offenses(<<~RUBY)
279+
page.all(:parameter).select(some_filter)
280+
RUBY
281+
end
282+
end
263283
end
264284

265285
context 'with no receiver' do

0 commit comments

Comments
 (0)