2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-07 07:14:45 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Ci::Status::Factory do
|
2016-12-08 08:40:21 -05:00
|
|
|
let(:user) { create(:user) }
|
2017-01-12 07:04:51 -05:00
|
|
|
let(:fabricated_status) { factory.fabricate! }
|
2017-01-12 06:45:00 -05:00
|
|
|
let(:factory) { described_class.new(resource, user) }
|
2016-12-07 07:14:45 -05:00
|
|
|
|
|
|
|
context 'when object has a core status' do
|
2017-01-12 07:04:51 -05:00
|
|
|
HasStatus::AVAILABLE_STATUSES.each do |simple_status|
|
|
|
|
context "when simple core status is #{simple_status}" do
|
|
|
|
let(:resource) { double('resource', status: simple_status) }
|
2016-12-07 07:14:45 -05:00
|
|
|
|
2017-01-12 07:04:51 -05:00
|
|
|
let(:expected_status) do
|
2019-10-15 23:06:12 -04:00
|
|
|
Gitlab::Ci::Status.const_get(simple_status.capitalize, false)
|
2017-01-12 07:04:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fabricates a core status #{simple_status}" do
|
|
|
|
expect(fabricated_status).to be_a expected_status
|
|
|
|
end
|
|
|
|
|
|
|
|
it "matches a valid core status for #{simple_status}" do
|
|
|
|
expect(factory.core_status).to be_a expected_status
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not match any extended statuses for #{simple_status}" do
|
|
|
|
expect(factory.extended_statuses).to be_empty
|
2016-12-07 07:14:45 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-01-12 06:45:00 -05:00
|
|
|
|
|
|
|
context 'when resource supports multiple extended statuses' do
|
|
|
|
let(:resource) { double('resource', status: :success) }
|
|
|
|
|
|
|
|
let(:first_extended_status) do
|
|
|
|
Class.new(SimpleDelegator) do
|
|
|
|
def first_method
|
|
|
|
'first return value'
|
|
|
|
end
|
|
|
|
|
|
|
|
def second_method
|
|
|
|
'second return value'
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.matches?(*)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:second_extended_status) do
|
|
|
|
Class.new(SimpleDelegator) do
|
|
|
|
def first_method
|
|
|
|
'decorated return value'
|
|
|
|
end
|
|
|
|
|
|
|
|
def third_method
|
|
|
|
'third return value'
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.matches?(*)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'compound decorator factory' do
|
|
|
|
it 'fabricates compound decorator' do
|
2017-01-12 07:04:51 -05:00
|
|
|
expect(fabricated_status.first_method).to eq 'decorated return value'
|
|
|
|
expect(fabricated_status.second_method).to eq 'second return value'
|
|
|
|
expect(fabricated_status.third_method).to eq 'third return value'
|
2017-01-12 06:45:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'delegates to core status' do
|
2017-01-12 07:04:51 -05:00
|
|
|
expect(fabricated_status.text).to eq 'passed'
|
2017-01-12 06:45:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'latest matches status becomes a status name' do
|
2017-01-12 07:04:51 -05:00
|
|
|
expect(fabricated_status.class).to eq second_extended_status
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'matches correct core status' do
|
|
|
|
expect(factory.core_status).to be_a Gitlab::Ci::Status::Success
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'matches correct extended statuses' do
|
|
|
|
expect(factory.extended_statuses)
|
|
|
|
.to eq [first_extended_status, second_extended_status]
|
2017-01-12 06:45:00 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when exclusive statuses are matches' do
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:extended_statuses)
|
|
|
|
.and_return([[first_extended_status, second_extended_status]])
|
|
|
|
end
|
|
|
|
|
2017-01-12 07:04:51 -05:00
|
|
|
it 'does not fabricate compound decorator' do
|
|
|
|
expect(fabricated_status.first_method).to eq 'first return value'
|
|
|
|
expect(fabricated_status.second_method).to eq 'second return value'
|
|
|
|
expect(fabricated_status).not_to respond_to(:third_method)
|
2017-01-12 06:45:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'delegates to core status' do
|
2017-01-12 07:04:51 -05:00
|
|
|
expect(fabricated_status.text).to eq 'passed'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'matches correct core status' do
|
|
|
|
expect(factory.core_status).to be_a Gitlab::Ci::Status::Success
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'matches correct extended statuses' do
|
|
|
|
expect(factory.extended_statuses).to eq [first_extended_status]
|
2017-01-12 06:45:00 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when exclusive statuses are not matched' do
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:extended_statuses)
|
|
|
|
.and_return([[first_extended_status], [second_extended_status]])
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'compound decorator factory'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when using simplified status grouping' do
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:extended_statuses)
|
|
|
|
.and_return([first_extended_status, second_extended_status])
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'compound decorator factory'
|
|
|
|
end
|
|
|
|
end
|
2016-12-07 07:14:45 -05:00
|
|
|
end
|