Commit 8dbd1e7d authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add concrete success warning status to stage factory

parent 8b30dd98
......@@ -39,5 +39,13 @@ module Ci
def builds
@builds ||= pipeline.builds.where(stage: name)
end
def success?
status.to_s == 'success'
end
def has_warnings?
statuses.latest.failed_but_allowed.any?
end
end
end
......@@ -4,7 +4,7 @@ module Gitlab
module Pipeline
class Factory < Status::Factory
def self.extended_statuses
[Pipeline::SuccessWarning]
[Status::SuccessWarning]
end
def self.common_helpers
......
module Gitlab
module Ci
module Status
module Pipeline
class SuccessWarning < Status::SuccessWarning
def self.matches?(pipeline, user)
pipeline.success? && pipeline.has_warnings?
end
end
end
end
end
end
......@@ -3,6 +3,10 @@ module Gitlab
module Status
module Stage
class Factory < Status::Factory
def self.extended_statuses
[Status::SuccessWarning]
end
def self.common_helpers
Status::Stage::Common
end
......
......@@ -2,9 +2,7 @@ module Gitlab
module Ci
module Status
##
# Abstract extended status used when pipeline/stage/build passed
# conditionally.
#
# Extended status used when pipeline or stage passed conditionally.
# This means that failed jobs that are allowed to fail were present.
#
class SuccessWarning < SimpleDelegator
......@@ -27,7 +25,7 @@ module Gitlab
end
def self.matches?(subject, user)
raise NotImplementedError
subject.success? && subject.has_warnings?
end
end
end
......
......@@ -49,11 +49,12 @@ describe Gitlab::Ci::Status::Pipeline::Factory do
it 'fabricates extended "success with warnings" status' do
expect(status)
.to be_a Gitlab::Ci::Status::Pipeline::SuccessWarning
.to be_a Gitlab::Ci::Status::SuccessWarning
end
it 'extends core status with common pipeline methods' do
it 'extends core status with common pipeline method' do
expect(status).to have_details
expect(status.details_path).to include "pipelines/#{pipeline.id}"
end
end
end
......@@ -42,5 +42,27 @@ describe Gitlab::Ci::Status::Stage::Factory do
end
end
end
end
context 'when stage has warnings' do
let(:stage) do
build(:ci_stage, name: 'test', status: :success, pipeline: pipeline)
end
before do
create(:ci_build, :allowed_to_fail, :failed,
stage: 'test', pipeline: stage.pipeline)
end
it 'fabricates extended "success with warnings" status' do
expect(status)
.to be_a Gitlab::Ci::Status::SuccessWarning
end
it 'extends core status with common stage method' do
expect(status).to have_details
expect(status.details_path).to include "pipelines/#{pipeline.id}##{stage.name}"
end
end
end
require 'spec_helper'
describe Gitlab::Ci::Status::Pipeline::SuccessWarning do
describe Gitlab::Ci::Status::SuccessWarning do
subject do
described_class.new(double('status'))
end
......@@ -22,46 +22,52 @@ describe Gitlab::Ci::Status::Pipeline::SuccessWarning do
end
describe '.matches?' do
context 'when pipeline is successful' do
let(:pipeline) do
create(:ci_pipeline, status: :success)
let(:matchable) { double('matchable') }
context 'when matchable subject is successful' do
before do
allow(matchable).to receive(:success?).and_return(true)
end
context 'when pipeline has warnings' do
context 'when matchable subject has warnings' do
before do
allow(pipeline).to receive(:has_warnings?).and_return(true)
allow(matchable).to receive(:has_warnings?).and_return(true)
end
it 'is a correct match' do
expect(described_class.matches?(pipeline, double)).to eq true
expect(described_class.matches?(matchable, double)).to eq true
end
end
context 'when pipeline does not have warnings' do
context 'when matchable subject does not have warnings' do
before do
allow(matchable).to receive(:has_warnings?).and_return(false)
end
it 'does not match' do
expect(described_class.matches?(pipeline, double)).to eq false
expect(described_class.matches?(matchable, double)).to eq false
end
end
end
context 'when pipeline is not successful' do
let(:pipeline) do
create(:ci_pipeline, status: :skipped)
context 'when matchable subject is not successful' do
before do
allow(matchable).to receive(:success?).and_return(false)
end
context 'when pipeline has warnings' do
context 'when matchable subject has warnings' do
before do
allow(pipeline).to receive(:has_warnings?).and_return(true)
allow(matchable).to receive(:has_warnings?).and_return(true)
end
it 'does not match' do
expect(described_class.matches?(pipeline, double)).to eq false
expect(described_class.matches?(matchable, double)).to eq false
end
end
context 'when pipeline does not have warnings' do
context 'when matchable subject does not have warnings' do
it 'does not match' do
expect(described_class.matches?(pipeline, double)).to eq false
expect(described_class.matches?(matchable, double)).to eq false
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