summaryrefslogtreecommitdiff
path: root/spec/workers/cleanup_container_repository_worker_spec.rb
blob: 5bee72940101abc4c021184165e0a10cec46559e (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
# frozen_string_literal: true

require 'spec_helper'

describe CleanupContainerRepositoryWorker, :clean_gitlab_redis_shared_state do
  let(:repository) { create(:container_repository) }
  let(:project) { repository.project }
  let(:user) { project.owner }
  let(:params) { { key: 'value' } }

  subject { described_class.new }

  describe '#perform' do
    let(:service) { instance_double(Projects::ContainerRepository::CleanupTagsService) }

    before do
      allow(Projects::ContainerRepository::CleanupTagsService).to receive(:new)
        .with(project, user, params).and_return(service)
    end

    it 'executes the destroy service' do
      expect(service).to receive(:execute)

      subject.perform(user.id, repository.id, params)
    end

    it 'does not raise error when user could not be found' do
      expect do
        subject.perform(-1, repository.id, params)
      end.not_to raise_error
    end

    it 'does not raise error when repository could not be found' do
      expect do
        subject.perform(user.id, -1, params)
      end.not_to raise_error
    end

    context 'when executed twice in short period' do
      it 'executes service only for the first time' do
        expect(service).to receive(:execute).once

        2.times { subject.perform(user.id, repository.id, params) }
      end
    end
  end
end