debian-mirror-gitlab/spec/rubocop/cop/default_scope_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.3 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
2022-10-11 01:57:18 +05:30
require 'rubocop_spec_helper'
2020-06-23 00:09:42 +05:30
require_relative '../../../rubocop/cop/default_scope'
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::Cop::DefaultScope do
2020-06-23 00:09:42 +05:30
it 'does not flag the use of default_scope with a send receiver' do
2021-03-11 19:13:27 +05:30
expect_no_offenses('foo.default_scope')
2020-06-23 00:09:42 +05:30
end
it 'flags the use of default_scope with a constant receiver' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~SOURCE)
User.default_scope
^^^^^^^^^^^^^^^^^^ Do not use `default_scope`, [...]
SOURCE
2020-06-23 00:09:42 +05:30
end
it 'flags the use of default_scope with a nil receiver' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~SOURCE)
class Foo ; default_scope ; end
^^^^^^^^^^^^^ Do not use `default_scope`, [...]
SOURCE
2020-06-23 00:09:42 +05:30
end
it 'flags the use of default_scope when passing arguments' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~SOURCE)
class Foo ; default_scope(:foo) ; end
^^^^^^^^^^^^^^^^^^^ Do not use `default_scope`, [...]
SOURCE
2020-06-23 00:09:42 +05:30
end
it 'flags the use of default_scope when passing a block' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~SOURCE)
class Foo ; default_scope { :foo } ; end
^^^^^^^^^^^^^ Do not use `default_scope`, [...]
SOURCE
2020-06-23 00:09:42 +05:30
end
it 'ignores the use of default_scope with a local variable receiver' do
2021-03-11 19:13:27 +05:30
expect_no_offenses('users = User.all ; users.default_scope')
2020-06-23 00:09:42 +05:30
end
end