diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/rubocop/cop/default_scope_spec.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/rubocop/cop/default_scope_spec.rb')
-rw-r--r-- | spec/rubocop/cop/default_scope_spec.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/rubocop/cop/default_scope_spec.rb b/spec/rubocop/cop/default_scope_spec.rb new file mode 100644 index 00000000000..9520915f900 --- /dev/null +++ b/spec/rubocop/cop/default_scope_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'rubocop' +require 'rubocop/rspec/support' +require_relative '../../../rubocop/cop/default_scope' + +describe RuboCop::Cop::DefaultScope do + 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 |