diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/rubocop/cop/usage_data/large_table_spec.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/rubocop/cop/usage_data/large_table_spec.rb')
-rw-r--r-- | spec/rubocop/cop/usage_data/large_table_spec.rb | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/spec/rubocop/cop/usage_data/large_table_spec.rb b/spec/rubocop/cop/usage_data/large_table_spec.rb new file mode 100644 index 00000000000..de6fb9c17e2 --- /dev/null +++ b/spec/rubocop/cop/usage_data/large_table_spec.rb @@ -0,0 +1,90 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' + +require 'rubocop' +require 'rubocop/rspec/support' + +require_relative '../../../../rubocop/cop/usage_data/large_table' + +RSpec.describe RuboCop::Cop::UsageData::LargeTable, type: :rubocop do + include CopHelper + + let(:large_tables) { %i[Rails Time] } + let(:count_methods) { %i[count distinct_count] } + let(:allowed_methods) { %i[minimum maximum] } + + let(:config) do + RuboCop::Config.new('UsageData/LargeTable' => { + 'NonRelatedClasses' => large_tables, + 'CountMethods' => count_methods, + 'AllowedMethods' => allowed_methods + }) + end + + subject(:cop) { described_class.new(config) } + + context 'when in usage_data files' do + before do + allow(cop).to receive(:usage_data_files?).and_return(true) + end + + context 'with large tables' do + context 'when calling Issue.count' do + it 'register an offence' do + inspect_source('Issue.count') + + expect(cop.offenses.size).to eq(1) + end + end + + context 'when calling Issue.active.count' do + it 'register an offence' do + inspect_source('Issue.active.count') + + expect(cop.offenses.size).to eq(1) + end + end + + context 'when calling count(Issue)' do + it 'does not register an offence' do + inspect_source('count(Issue)') + + expect(cop.offenses).to be_empty + end + end + + context 'when calling count(Ci::Build.active)' do + it 'does not register an offence' do + inspect_source('count(Ci::Build.active)') + + expect(cop.offenses).to be_empty + end + end + + context 'when calling Ci::Build.active.count' do + it 'register an offence' do + inspect_source('Ci::Build.active.count') + + expect(cop.offenses.size).to eq(1) + end + end + + context 'when using allowed methods' do + it 'does not register an offence' do + inspect_source('Issue.minimum') + + expect(cop.offenses).to be_empty + end + end + end + + context 'with non related class' do + it 'does not register an offence' do + inspect_source('Rails.count') + + expect(cop.offenses).to be_empty + end + end + end +end |