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

Rails/FindEach cop works with where.not. #2798

Merged
merged 1 commit into from
Feb 7, 2016
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### New features

* [#2798](https://github.com/bbatsov/rubocop/pull/2798): `Rails/FindEach` cop works with `where.not`. ([@pocke][])

### Bug fixes

* Fix auto-correction of `not` with parentheses in `Style/Not`. ([@lumeet][])
Expand Down Expand Up @@ -1943,3 +1947,4 @@
[@madwort]: https://github.com/madwort
[@annih]: https://github.com/annih
[@mmcguinn]: https://github.com/mmcguinn
[@pocke]: https://github.com/pocke
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/find_each.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Rails
class FindEach < Cop
MSG = 'Use `find_each` instead of `each`.'.freeze

SCOPE_METHODS = [:all, :where].freeze
SCOPE_METHODS = [:all, :where, :not].freeze

def on_send(node)
receiver, second_method, _selector = *node
Expand Down
1 change: 1 addition & 0 deletions spec/rubocop/cop/rails/find_each_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

it_behaves_like('register_offense', 'where(name: name)')
it_behaves_like('register_offense', 'all')
it_behaves_like('register_offense', 'where.not(name: name)')

it 'does not register an offense when using find_by' do
inspect_source(cop, 'User.all.find_each { |u| u.x }')
Expand Down