Commit 93c72e0f authored by Kamil Trzcinski's avatar Kamil Trzcinski

Add Ci::Status::Factory

parent c4e46c57
module Gitlab
module Ci
module Status
class Factory
attr_reader :subject
def initialize(subject)
@subject = subject
end
def fabricate!
if extended_status
extended_status.new(core_status)
else
core_status
end
end
private
def subject_status
@subject_status ||= subject.status
end
def core_status
Gitlab::Ci::Status
.const_get(subject_status.capitalize)
.new(subject)
end
def extended_status
@extended ||= extended_statuses.find do |status|
status.matches?(subject)
end
end
def extended_statuses
[]
end
end
end
end
end
......@@ -2,35 +2,15 @@ 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
class Factory < Status::Factory
private
def core_status
Gitlab::Ci::Status
.const_get(@status.capitalize)
.new(@pipeline)
.extend(Status::Pipeline::Common)
def extended_statuses
[Pipeline::SuccessWithWarnings]
end
def extended_status
@extended ||= EXTENDED_STATUSES.find do |status|
status.matches?(@pipeline)
end
def core_status
super.extend(Status::Pipeline::Common)
end
end
end
......
......@@ -2,35 +2,11 @@ module Gitlab
module Ci
module Status
module Stage
class Factory
EXTENDED_STATUSES = []
def initialize(stage)
@stage = stage
@status = stage.status || :created
end
def fabricate!
if extended_status
extended_status.new(core_status)
else
core_status
end
end
class Factory < Status::Factory
private
def core_status
Gitlab::Ci::Status
.const_get(@status.capitalize)
.new(@stage)
.extend(Status::Stage::Common)
end
def extended_status
@extended ||= EXTENDED_STATUSES.find do |status|
status.matches?(@stage)
end
super.extend(Status::Stage::Common)
end
end
end
......
require 'spec_helper'
describe Gitlab::Ci::Status::Factory do
let(:object) { double(status: :created) }
subject do
described_class.new(object)
end
let(:status) do
subject.fabricate!
end
context 'when object has a core status' do
HasStatus::AVAILABLE_STATUSES.each do |core_status|
context "when core status is #{core_status}" do
let(:object) { double(status: core_status) }
it "fabricates a core status #{core_status}" do
expect(status).to be_a(
Gitlab::Ci::Status.const_get(core_status.capitalize))
end
end
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