2020-06-10 08:08:58 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-17 02:08:43 -04:00
|
|
|
require 'fast_spec_helper'
|
2020-06-10 08:08:58 -04:00
|
|
|
require_relative '../../../rubocop/cop/default_scope'
|
|
|
|
|
2021-01-07 13:10:38 -05:00
|
|
|
RSpec.describe RuboCop::Cop::DefaultScope do
|
2020-06-10 08:08:58 -04:00
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
it 'does not flag the use of default_scope with a send receiver' do
|
2021-01-26 13:09:30 -05:00
|
|
|
expect_no_offenses('foo.default_scope')
|
2020-06-10 08:08:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'flags the use of default_scope with a constant receiver' do
|
2021-01-26 13:09:30 -05:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
User.default_scope
|
|
|
|
^^^^^^^^^^^^^^^^^^ Do not use `default_scope`, [...]
|
|
|
|
SOURCE
|
2020-06-10 08:08:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'flags the use of default_scope with a nil receiver' do
|
2021-01-26 13:09:30 -05:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo ; default_scope ; end
|
|
|
|
^^^^^^^^^^^^^ Do not use `default_scope`, [...]
|
|
|
|
SOURCE
|
2020-06-10 08:08:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'flags the use of default_scope when passing arguments' do
|
2021-01-26 13:09:30 -05:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo ; default_scope(:foo) ; end
|
|
|
|
^^^^^^^^^^^^^^^^^^^ Do not use `default_scope`, [...]
|
|
|
|
SOURCE
|
2020-06-10 08:08:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'flags the use of default_scope when passing a block' do
|
2021-01-26 13:09:30 -05:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo ; default_scope { :foo } ; end
|
|
|
|
^^^^^^^^^^^^^ Do not use `default_scope`, [...]
|
|
|
|
SOURCE
|
2020-06-10 08:08:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores the use of default_scope with a local variable receiver' do
|
2021-01-26 13:09:30 -05:00
|
|
|
expect_no_offenses('users = User.all ; users.default_scope')
|
2020-06-10 08:08:58 -04:00
|
|
|
end
|
|
|
|
end
|