create_spec.rb 1.27 KB
Newer Older
1 2
# frozen_string_literal: true

3 4 5 6 7 8 9
require 'spec_helper'

describe Gitlab::Ci::Pipeline::Chain::Create do
  set(:project) { create(:project) }
  set(:user) { create(:user) }

  let(:pipeline) do
10
    build(:ci_empty_pipeline, project: project, ref: 'master')
11 12 13
  end

  let(:command) do
14
    Gitlab::Ci::Pipeline::Chain::Command.new(
15
      project: project, current_user: user)
16 17 18 19 20
  end

  let(:step) { described_class.new(pipeline, command) }

  context 'when pipeline is ready to be saved' do
21
    before do
22
      pipeline.stages.build(name: 'test', position: 0, project: project)
23 24 25 26

      step.perform!
    end

27 28 29 30 31 32 33 34 35 36
    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
37
      expect(pipeline.stages.first).to be_persisted
38 39 40 41 42 43 44 45
    end
  end

  context 'when pipeline has validation errors' do
    let(:pipeline) do
      build(:ci_pipeline, project: project, ref: nil)
    end

46 47 48 49
    before do
      step.perform!
    end

50 51 52 53 54 55 56 57 58 59
    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