diff options
Diffstat (limited to 'spec/workers/counters/cleanup_refresh_worker_spec.rb')
-rw-r--r-- | spec/workers/counters/cleanup_refresh_worker_spec.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/workers/counters/cleanup_refresh_worker_spec.rb b/spec/workers/counters/cleanup_refresh_worker_spec.rb new file mode 100644 index 00000000000..a56c98f72a0 --- /dev/null +++ b/spec/workers/counters/cleanup_refresh_worker_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Counters::CleanupRefreshWorker do + let(:model) { create(:project_statistics) } + + describe '#perform', :redis do + let(:attribute) { :build_artifacts_size } + let(:worker) { described_class.new } + + subject { worker.perform(model.class.name, model.id, attribute) } + + it 'calls cleanup_refresh on the counter' do + expect_next_instance_of(Gitlab::Counters::BufferedCounter, model, attribute) do |counter| + expect(counter).to receive(:cleanup_refresh) + end + + subject + end + + context 'when model class does not exist' do + subject { worker.perform('NonExistentModel', 1, attribute) } + + it 'does nothing' do + expect(Gitlab::Counters::BufferedCounter).not_to receive(:new) + + subject + end + end + + context 'when record does not exist' do + subject { worker.perform(model.class.name, non_existing_record_id, attribute) } + + it 'does nothing' do + expect(Gitlab::Counters::BufferedCounter).not_to receive(:new) + + subject + end + end + end +end |