blob: 753e09731bf2ea26a98df0c233f3ce2284639d83 (
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
allow(::ServicePing::ServicePingSettings).to receive(:enabled?).and_return(service_ping_enabled)
end
describe '.increment' do
context 'when usage_ping is disabled' do
let(:service_ping_enabled) { 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(:service_ping_enabled) { 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(:service_ping_enabled) { 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(:service_ping_enabled) { 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
|