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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/counters/legacy_counter_spec.rb')
-rw-r--r--spec/lib/gitlab/counters/legacy_counter_spec.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/lib/gitlab/counters/legacy_counter_spec.rb b/spec/lib/gitlab/counters/legacy_counter_spec.rb
new file mode 100644
index 00000000000..e66b1ce08c4
--- /dev/null
+++ b/spec/lib/gitlab/counters/legacy_counter_spec.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Counters::LegacyCounter do
+ subject(:counter) { described_class.new(counter_record, attribute) }
+
+ let(:counter_record) { create(:project_statistics) }
+ let(:attribute) { :snippets_size }
+ let(:amount) { 123 }
+
+ describe '#increment' do
+ it 'increments the attribute in the counter record' do
+ expect { counter.increment(amount) }.to change { counter_record.reload.method(attribute).call }.by(amount)
+ end
+
+ it 'returns the value after the increment' do
+ counter.increment(100)
+
+ expect(counter.increment(amount)).to eq(100 + amount)
+ end
+
+ it 'executes after counter_record after commit callback' do
+ expect(counter_record).to receive(:execute_after_commit_callbacks).and_call_original
+
+ counter.increment(amount)
+ end
+ end
+
+ describe '#reset!' do
+ before do
+ allow(counter_record).to receive(:update!)
+ end
+
+ it 'resets the record to 0' do
+ expect(counter_record).to receive(:update!).with(attribute => 0)
+
+ counter.reset!
+ end
+ end
+end