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

49 lines
1.3 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
2020-07-28 23:09:34 +05:30
require 'fast_spec_helper'
2020-06-23 00:09:42 +05:30
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/default_scope'
2020-07-28 23:09:34 +05:30
RSpec.describe RuboCop::Cop::DefaultScope, type: :rubocop do
2020-06-23 00:09:42 +05:30
include CopHelper
subject(:cop) { described_class.new }
it 'does not flag the use of default_scope with a send receiver' do
inspect_source('foo.default_scope')
expect(cop.offenses.size).to eq(0)
end
it 'flags the use of default_scope with a constant receiver' do
inspect_source('User.default_scope')
expect(cop.offenses.size).to eq(1)
end
it 'flags the use of default_scope with a nil receiver' do
inspect_source('class Foo ; default_scope ; end')
expect(cop.offenses.size).to eq(1)
end
it 'flags the use of default_scope when passing arguments' do
inspect_source('class Foo ; default_scope(:foo) ; end')
expect(cop.offenses.size).to eq(1)
end
it 'flags the use of default_scope when passing a block' do
inspect_source('class Foo ; default_scope { :foo } ; end')
expect(cop.offenses.size).to eq(1)
end
it 'ignores the use of default_scope with a local variable receiver' do
inspect_source('users = User.all ; users.default_scope')
expect(cop.offenses.size).to eq(0)
end
end