Commit d28f5e77 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Implement pipeline status factory with extended status

parent b86d8afe
module Gitlab
module Ci
module Status
module Pipeline
class Factory
EXTENDED_STATUSES = [Pipeline::SuccessWithWarnings]
def initialize(pipeline)
@pipeline = pipeline
@status = pipeline.status || :created
end
def fabricate!
if extended_status
extended_status.new(core_status)
else
core_status
end
end
private
def core_status
Gitlab::Ci::Status
.const_get(@status.capitalize)
.new(@pipeline)
.extend(Status::Pipeline::Common)
end
def extended_status
@extended ||= EXTENDED_STATUSES.find do |status|
status.matches?(@pipeline)
end
end
end
end
end
end
end
require 'spec_helper'
describe Gitlab::Ci::Status::Pipeline::Factory do
subject do
described_class.new(pipeline)
end
context 'when pipeline has a core status' do
HasStatus::AVAILABLE_STATUSES.each do |core_status|
context "when core status is #{core_status}" do
let(:pipeline) do
create(:ci_pipeline, status: core_status)
end
it "fabricates a core status #{core_status}" do
expect(subject.fabricate!)
.to be_a Gitlab::Ci::Status.const_get(core_status.capitalize)
end
end
end
end
context 'when pipeline has warnings' do
let(:pipeline) do
create(:ci_pipeline, status: :success)
end
before do
create(:ci_build, :allowed_to_fail, :failed, pipeline: pipeline)
end
it 'fabricates extended "success with warnings" status' do
expect(subject.fabricate!)
.to be_a Gitlab::Ci::Status::Pipeline::SuccessWithWarnings
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment