Add Ci::Status::Factory
This commit is contained in:
parent
c4e46c5740
commit
93c72e0f71
4 changed files with 76 additions and 51 deletions
43
lib/gitlab/ci/status/factory.rb
Normal file
43
lib/gitlab/ci/status/factory.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
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
|
||||
|
|
26
spec/lib/gitlab/ci/status/factory_spec.rb
Normal file
26
spec/lib/gitlab/ci/status/factory_spec.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
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
|
Loading…
Reference in a new issue