Welcome to mirror list, hosted at ThFree Co, Russian Federation.

histogram_with_large_table_spec.rb « usage_data « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 56aecc3ec4ebc202f1c594db54a6dde79f6c0bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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