2016-02-18 04:52:57 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2016-04-16 15:46:26 -04:00
|
|
|
describe Statuseable do
|
2016-04-12 04:23:31 -04:00
|
|
|
before do
|
|
|
|
@object = Object.new
|
2016-04-16 15:46:26 -04:00
|
|
|
@object.extend(Statuseable::ClassMethods)
|
2016-04-12 04:23:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '.status' do
|
|
|
|
before do
|
2016-04-13 09:40:12 -04:00
|
|
|
allow(@object).to receive(:all).and_return(CommitStatus.where(id: statuses))
|
2016-04-12 04:23:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { @object.status }
|
2016-02-19 13:58:43 -05:00
|
|
|
|
2016-02-20 10:35:29 -05:00
|
|
|
shared_examples 'build status summary' do
|
|
|
|
context 'all successful' do
|
|
|
|
let(:statuses) { Array.new(2) { create(type, status: :success) } }
|
|
|
|
it { is_expected.to eq 'success' }
|
|
|
|
end
|
2016-02-18 04:52:57 -05:00
|
|
|
|
2016-02-20 10:35:29 -05:00
|
|
|
context 'at least one failed' do
|
|
|
|
let(:statuses) do
|
|
|
|
[create(type, status: :success), create(type, status: :failed)]
|
2016-02-19 13:58:43 -05:00
|
|
|
end
|
2016-02-18 05:47:35 -05:00
|
|
|
|
2016-02-20 10:35:29 -05:00
|
|
|
it { is_expected.to eq 'failed' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'at least one running' do
|
|
|
|
let(:statuses) do
|
|
|
|
[create(type, status: :success), create(type, status: :running)]
|
2016-02-19 13:58:43 -05:00
|
|
|
end
|
2016-02-18 05:47:35 -05:00
|
|
|
|
2016-02-20 10:35:29 -05:00
|
|
|
it { is_expected.to eq 'running' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'at least one pending' do
|
|
|
|
let(:statuses) do
|
|
|
|
[create(type, status: :success), create(type, status: :pending)]
|
2016-02-19 13:58:43 -05:00
|
|
|
end
|
2016-02-18 05:47:35 -05:00
|
|
|
|
2016-02-20 10:35:29 -05:00
|
|
|
it { is_expected.to eq 'running' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'success and failed but allowed to fail' do
|
|
|
|
let(:statuses) do
|
|
|
|
[create(type, status: :success),
|
|
|
|
create(type, status: :failed, allow_failure: true)]
|
2016-02-19 13:58:43 -05:00
|
|
|
end
|
2016-02-18 05:47:35 -05:00
|
|
|
|
2016-02-20 10:35:29 -05:00
|
|
|
it { is_expected.to eq 'success' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'one failed but allowed to fail' do
|
|
|
|
let(:statuses) { [create(type, status: :failed, allow_failure: true)] }
|
|
|
|
it { is_expected.to eq 'success' }
|
|
|
|
end
|
|
|
|
|
2016-03-17 10:54:56 -04:00
|
|
|
context 'success and canceled' do
|
|
|
|
let(:statuses) do
|
|
|
|
[create(type, status: :success), create(type, status: :canceled)]
|
|
|
|
end
|
2016-04-18 03:44:22 -04:00
|
|
|
|
|
|
|
it { is_expected.to eq 'canceled' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'one failed and one canceled' do
|
|
|
|
let(:statuses) do
|
|
|
|
[create(type, status: :failed), create(type, status: :canceled)]
|
|
|
|
end
|
|
|
|
|
2016-03-17 10:54:56 -04:00
|
|
|
it { is_expected.to eq 'failed' }
|
2016-04-18 03:44:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'one failed but allowed to fail and one canceled' do
|
|
|
|
let(:statuses) do
|
|
|
|
[create(type, status: :failed, allow_failure: true),
|
|
|
|
create(type, status: :canceled)]
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq 'canceled' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'one running one canceled' do
|
|
|
|
let(:statuses) do
|
|
|
|
[create(type, status: :running), create(type, status: :canceled)]
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq 'running' }
|
2016-03-17 10:54:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'all canceled' do
|
|
|
|
let(:statuses) do
|
|
|
|
[create(type, status: :canceled), create(type, status: :canceled)]
|
|
|
|
end
|
|
|
|
it { is_expected.to eq 'canceled' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'success and canceled but allowed to fail' do
|
|
|
|
let(:statuses) do
|
|
|
|
[create(type, status: :success),
|
|
|
|
create(type, status: :canceled, allow_failure: true)]
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq 'success' }
|
|
|
|
end
|
|
|
|
|
2016-02-20 10:35:29 -05:00
|
|
|
context 'one finished and second running but allowed to fail' do
|
|
|
|
let(:statuses) do
|
|
|
|
[create(type, status: :success),
|
|
|
|
create(type, status: :running, allow_failure: true)]
|
2016-02-19 13:58:43 -05:00
|
|
|
end
|
2016-02-20 10:35:29 -05:00
|
|
|
|
|
|
|
it { is_expected.to eq 'running' }
|
2016-02-19 13:58:43 -05:00
|
|
|
end
|
2016-02-18 05:47:35 -05:00
|
|
|
end
|
2016-02-20 10:35:29 -05:00
|
|
|
|
|
|
|
context 'ci build statuses' do
|
|
|
|
let(:type) { :ci_build }
|
|
|
|
it_behaves_like 'build status summary'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'generic commit statuses' do
|
|
|
|
let(:type) { :generic_commit_status }
|
|
|
|
it_behaves_like 'build status summary'
|
|
|
|
end
|
2016-02-18 04:52:57 -05:00
|
|
|
end
|
|
|
|
end
|