rubocop / rubocop-rails

A RuboCop extension focused on enforcing Rails best practices and coding conventions.
https://docs.rubocop.org/rubocop-rails
MIT License
821 stars 263 forks source link

Fix false negatives for `Rails/RedundantActiveRecordAllMethod` when using `POSSIBLE_ENUMERABLE_BLOCK_METHODS` in a block #1382

Closed masato-bkn closed 1 month ago

masato-bkn commented 1 month ago

This PR fixes false negatives for Rails/RedundantActiveRecordAllMethod when methods in POSSIBLE_ENUMERABLE_BLOCK_METHODS are used in a block.

Expected Behavior

expect { subject }.to change { User.all.count }
                                    ^^^ Redundant `all` detected.

Actual Behavior

No offenses are registered.

Steps to reproduce the problem

Run bundle ex rubocop --only Rails/RedundantActiveRecordAllMethod on the code below:

expect { subject }.to change { User.all.count }

RuboCop version

1.67.0 (using Parser 3.3.5.0, rubocop-ast 1.32.3, analyzing as Ruby 3.2, running on ruby 3.2.0) [x86_64-darwin21]
  - rubocop-rails 2.27.0

Before submitting the PR make sure the following are checked:

koic commented 1 month ago

Thanks!