summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb
blob: d4f6110b3dfc918c626b57a2c6b414270babacbe (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::UsageDataCounters::RedisCounter, :clean_gitlab_redis_shared_state do
  let(:redis_key) { 'foobar' }

  subject { Class.new.extend(described_class) }

  before do
    stub_application_setting(usage_ping_enabled: setting_value)
  end

  describe '.increment' do
    context 'when usage_ping is disabled' do
      let(:setting_value) { false }

      it 'counter is not increased' do
        expect do
          subject.increment(redis_key)
        end.not_to change { subject.total_count(redis_key) }
      end
    end

    context 'when usage_ping is enabled' do
      let(:setting_value) { true }

      it 'counter is increased' do
        expect do
          subject.increment(redis_key)
        end.to change { subject.total_count(redis_key) }.by(1)
      end
    end
  end

  describe '.increment_by' do
    context 'when usage_ping is disabled' do
      let(:setting_value) { false }

      it 'counter is not increased' do
        expect do
          subject.increment_by(redis_key, 3)
        end.not_to change { subject.total_count(redis_key) }
      end
    end

    context 'when usage_ping is enabled' do
      let(:setting_value) { true }

      it 'counter is increased' do
        expect do
          subject.increment_by(redis_key, 3)
        end.to change { subject.total_count(redis_key) }.by(3)
      end
    end
  end
end