Skip to content

Commit

Permalink
Add scope methods to Rails/FindEach cop
Browse files Browse the repository at this point in the history
This PR imports rubocop/rubocop#6161.
  • Loading branch information
koic committed Aug 10, 2018
1 parent 12c35a7 commit 3229e7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/rubocop/cop/rails/find_each.rb
Expand Up @@ -15,7 +15,10 @@ module Rails
class FindEach < Cop
MSG = 'Use `find_each` instead of `each`.'.freeze

SCOPE_METHODS = %i[all where not].freeze
SCOPE_METHODS = %i[
all eager_load includes joins left_joins left_outer_joins not preload
references unscoped where
].freeze
IGNORED_METHODS = %i[order limit select].freeze

def on_send(node)
Expand Down
10 changes: 9 additions & 1 deletion spec/rubocop/cop/rails/find_each_spec.rb
Expand Up @@ -30,8 +30,16 @@
end
end

it_behaves_like('register_offense', 'where(name: name)')
it_behaves_like('register_offense', 'all')
it_behaves_like('register_offense', 'eager_load(:association_name)')
it_behaves_like('register_offense', 'includes(:association_name)')
it_behaves_like('register_offense', 'joins(:association_name)')
it_behaves_like('register_offense', 'left_joins(:association_name)')
it_behaves_like('register_offense', 'left_outer_joins(:association_name)')
it_behaves_like('register_offense', 'preload(:association_name)')
it_behaves_like('register_offense', 'references(:association_name)')
it_behaves_like('register_offense', 'unscoped')
it_behaves_like('register_offense', 'where(name: name)')
it_behaves_like('register_offense', 'where.not(name: name)')

it 'does not register an offense when using find_by' do
Expand Down

0 comments on commit 3229e7c

Please sign in to comment.