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

require 'spec_helper'

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

  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