diff options
Diffstat (limited to 'spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb')
-rw-r--r-- | spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb b/spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb new file mode 100644 index 00000000000..56aecc3ec4e --- /dev/null +++ b/spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb @@ -0,0 +1,108 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' + +require_relative '../../../../rubocop/cop/usage_data/histogram_with_large_table' + +RSpec.describe RuboCop::Cop::UsageData::HistogramWithLargeTable do + let(:high_traffic_models) { %w[Issue Ci::Build] } + let(:msg) { 'Avoid histogram method on' } + + let(:config) do + RuboCop::Config.new('UsageData/HistogramWithLargeTable' => { + 'HighTrafficModels' => high_traffic_models + }) + end + + subject(:cop) { described_class.new(config) } + + context 'with large tables' do + context 'with one-level constants' do + context 'when calling histogram(Issue)' do + it 'registers an offense' do + expect_offense(<<~CODE) + histogram(Issue, :project_id, buckets: 1..100) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} Issue + CODE + end + end + + context 'when calling histogram(::Issue)' do + it 'registers an offense' do + expect_offense(<<~CODE) + histogram(::Issue, :project_id, buckets: 1..100) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} Issue + CODE + end + end + + context 'when calling histogram(Issue.closed)' do + it 'registers an offense' do + expect_offense(<<~CODE) + histogram(Issue.closed, :project_id, buckets: 1..100) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} Issue + CODE + end + end + + context 'when calling histogram(::Issue.closed)' do + it 'registers an offense' do + expect_offense(<<~CODE) + histogram(::Issue.closed, :project_id, buckets: 1..100) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} Issue + CODE + end + end + end + + context 'with two-level constants' do + context 'when calling histogram(::Ci::Build)' do + it 'registers an offense' do + expect_offense(<<~CODE) + histogram(::Ci::Build, buckets: 1..100) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} Ci::Build + CODE + end + end + + context 'when calling histogram(::Ci::Build.active)' do + it 'registers an offense' do + expect_offense(<<~CODE) + histogram(::Ci::Build.active, buckets: 1..100) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} Ci::Build + CODE + end + end + + context 'when calling histogram(Ci::Build)' do + it 'registers an offense' do + expect_offense(<<~CODE) + histogram(Ci::Build, buckets: 1..100) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} Ci::Build + CODE + end + end + + context 'when calling histogram(Ci::Build.active)' do + it 'registers an offense' do + expect_offense(<<~CODE) + histogram(Ci::Build.active, buckets: 1..100) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} Ci::Build + CODE + end + end + end + end + + context 'with non related class' do + it 'does not register an offense' do + expect_no_offenses('histogram(MergeRequest, buckets: 1..100)') + end + end + + context 'with non related method' do + it 'does not register an offense' do + expect_no_offenses('count(Issue, buckets: 1..100)') + end + end +end |