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.rb37
1 files changed, 25 insertions, 12 deletions
diff --git a/spec/lib/gitlab/counters/legacy_counter_spec.rb b/spec/lib/gitlab/counters/legacy_counter_spec.rb
index e66b1ce08c4..9b0ffafff67 100644
--- a/spec/lib/gitlab/counters/legacy_counter_spec.rb
+++ b/spec/lib/gitlab/counters/legacy_counter_spec.rb
@@ -5,37 +5,50 @@ require 'spec_helper'
RSpec.describe Gitlab::Counters::LegacyCounter do
subject(:counter) { described_class.new(counter_record, attribute) }
- let(:counter_record) { create(:project_statistics) }
+ let_it_be(:counter_record, reload: true) { create(:project_statistics) }
+
let(:attribute) { :snippets_size }
- let(:amount) { 123 }
+
+ let(:increment) { Gitlab::Counters::Increment.new(amount: 123) }
+ let(:other_increment) { Gitlab::Counters::Increment.new(amount: 100) }
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)
+ expect { counter.increment(increment) }
+ .to change { counter_record.reload.method(attribute).call }.by(increment.amount)
end
it 'returns the value after the increment' do
- counter.increment(100)
+ counter.increment(other_increment)
- expect(counter.increment(amount)).to eq(100 + amount)
+ expect(counter.increment(increment)).to eq(other_increment.amount + increment.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)
+ counter.increment(increment)
end
end
- describe '#reset!' do
- before do
- allow(counter_record).to receive(:update!)
+ describe '#bulk_increment' do
+ let(:increments) { [Gitlab::Counters::Increment.new(amount: 123), Gitlab::Counters::Increment.new(amount: 456)] }
+
+ it 'increments the attribute in the counter record' do
+ expect { counter.bulk_increment(increments) }
+ .to change { counter_record.reload.method(attribute).call }.by(increments.sum(&:amount))
+ end
+
+ it 'returns the value after the increment' do
+ counter.increment(other_increment)
+
+ expect(counter.bulk_increment(increments)).to eq(other_increment.amount + increments.sum(&:amount))
end
- it 'resets the record to 0' do
- expect(counter_record).to receive(:update!).with(attribute => 0)
+ it 'executes after counter_record after commit callback' do
+ expect(counter_record).to receive(:execute_after_commit_callbacks).and_call_original
- counter.reset!
+ counter.bulk_increment(increments)
end
end
end