debian-mirror-gitlab/spec/lib/gitlab/ci/pipeline/chain/create_spec.rb

60 lines
1.3 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Ci::Pipeline::Chain::Create do
2020-04-08 14:13:33 +05:30
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
2018-03-17 18:26:18 +05:30
let(:pipeline) do
2018-05-09 12:01:36 +05:30
build(:ci_empty_pipeline, project: project, ref: 'master')
2018-03-17 18:26:18 +05:30
end
let(:command) do
Gitlab::Ci::Pipeline::Chain::Command.new(
2018-05-09 12:01:36 +05:30
project: project, current_user: user)
2018-03-17 18:26:18 +05:30
end
let(:step) { described_class.new(pipeline, command) }
context 'when pipeline is ready to be saved' do
2018-05-09 12:01:36 +05:30
before do
2018-10-15 14:42:47 +05:30
pipeline.stages.build(name: 'test', position: 0, project: project)
2018-05-09 12:01:36 +05:30
step.perform!
end
2018-03-17 18:26:18 +05:30
it 'saves a pipeline' do
expect(pipeline).to be_persisted
end
it 'does not break the chain' do
expect(step.break?).to be false
end
it 'creates stages' do
expect(pipeline.reload.stages).to be_one
2018-05-09 12:01:36 +05:30
expect(pipeline.stages.first).to be_persisted
2018-03-17 18:26:18 +05:30
end
end
context 'when pipeline has validation errors' do
let(:pipeline) do
build(:ci_pipeline, project: project, ref: nil)
end
2018-05-09 12:01:36 +05:30
before do
step.perform!
end
2018-03-17 18:26:18 +05:30
it 'breaks the chain' do
expect(step.break?).to be true
end
it 'appends validation error' do
expect(pipeline.errors.to_a)
.to include /Failed to persist the pipeline/
end
end
end