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

retry_pipeline_worker_spec.rb « ci « workers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c7600a24280b061da755d3fff32d1994fbf71987 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::RetryPipelineWorker do
  describe '#perform' do
    subject(:perform) { described_class.new.perform(pipeline_id, user_id) }

    let(:pipeline) { create(:ci_pipeline) }

    context 'when pipeline exists' do
      let(:pipeline_id) { pipeline.id }

      context 'when user exists' do
        let(:user) { create(:user) }
        let(:user_id) { user.id }

        before do
          pipeline.project.add_maintainer(user)
        end

        it 'retries the pipeline' do
          expect(::Ci::Pipeline).to receive(:find_by_id).with(pipeline.id).and_return(pipeline)
          expect(pipeline).to receive(:retry_failed).with(having_attributes(id: user_id))

          perform
        end
      end

      context 'when user does not exist' do
        let(:user_id) { 1234 }

        it 'does not retry the pipeline' do
          expect(::Ci::Pipeline).to receive(:find_by_id).with(pipeline_id).and_return(pipeline)
          expect(pipeline).not_to receive(:retry_failed).with(having_attributes(id: user_id))

          perform
        end
      end
    end

    context 'when pipeline does not exist' do
      let(:pipeline_id) { 1234 }
      let(:user_id) { 1234 }

      it 'returns nil' do
        expect(perform).to be_nil
      end
    end
  end
end