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/workers/ci/retry_pipeline_worker_spec.rb')
-rw-r--r--spec/workers/ci/retry_pipeline_worker_spec.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/workers/ci/retry_pipeline_worker_spec.rb b/spec/workers/ci/retry_pipeline_worker_spec.rb
new file mode 100644
index 00000000000..c7600a24280
--- /dev/null
+++ b/spec/workers/ci/retry_pipeline_worker_spec.rb
@@ -0,0 +1,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