2016-02-18 04:52:57 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2016-08-24 22:55:32 -04:00
|
|
|
describe HasStatus do
|
2016-04-12 04:23:31 -04:00
|
|
|
describe '.status' do
|
2016-10-03 07:35:53 -04:00
|
|
|
subject { CommitStatus.status }
|
2016-08-24 22:55:32 -04:00
|
|
|
|
2016-02-20 10:35:29 -05:00
|
|
|
shared_examples 'build status summary' do
|
|
|
|
context 'all successful' do
|
2016-10-03 07:35:53 -04:00
|
|
|
let!(:statuses) { Array.new(2) { create(type, status: :success) } }
|
2016-02-20 10:35:29 -05:00
|
|
|
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
|
2016-10-03 07:35:53 -04:00
|
|
|
let!(:statuses) do
|
2016-02-20 10:35:29 -05:00
|
|
|
[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
|
2016-10-03 07:35:53 -04:00
|
|
|
let!(:statuses) do
|
2016-02-20 10:35:29 -05:00
|
|
|
[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
|
2016-10-03 07:35:53 -04:00
|
|
|
let!(:statuses) do
|
2016-02-20 10:35:29 -05:00
|
|
|
[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
|
2016-10-03 07:35:53 -04:00
|
|
|
let!(:statuses) do
|
2016-02-20 10:35:29 -05:00
|
|
|
[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
|
2016-10-03 07:35:53 -04:00
|
|
|
let!(:statuses) do
|
|
|
|
[create(type, status: :failed, allow_failure: true)]
|
|
|
|
end
|
|
|
|
|
2016-12-05 11:52:50 -05:00
|
|
|
it { is_expected.to eq 'skipped' }
|
2016-02-20 10:35:29 -05:00
|
|
|
end
|
|
|
|
|
2016-03-17 10:54:56 -04:00
|
|
|
context 'success and canceled' do
|
2016-10-03 07:35:53 -04:00
|
|
|
let!(:statuses) do
|
2016-03-17 10:54:56 -04:00
|
|
|
[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
|
2016-10-03 07:35:53 -04:00
|
|
|
let!(:statuses) do
|
2016-04-18 03:44:22 -04:00
|
|
|
[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
|
2016-10-03 07:35:53 -04:00
|
|
|
let!(:statuses) do
|
2016-04-18 03:44:22 -04:00
|
|
|
[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
|
2016-10-03 07:35:53 -04:00
|
|
|
let!(:statuses) do
|
2016-04-18 03:44:22 -04:00
|
|
|
[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
|
2016-10-03 07:35:53 -04:00
|
|
|
let!(:statuses) do
|
2016-03-17 10:54:56 -04:00
|
|
|
[create(type, status: :canceled), create(type, status: :canceled)]
|
|
|
|
end
|
2016-10-03 07:35:53 -04:00
|
|
|
|
2016-03-17 10:54:56 -04:00
|
|
|
it { is_expected.to eq 'canceled' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'success and canceled but allowed to fail' do
|
2016-10-03 07:35:53 -04:00
|
|
|
let!(:statuses) do
|
2016-03-17 10:54:56 -04:00
|
|
|
[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
|
2016-10-03 07:35:53 -04:00
|
|
|
let!(:statuses) do
|
2016-02-20 10:35:29 -05:00
|
|
|
[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 }
|
2016-10-03 07:35:53 -04:00
|
|
|
|
2016-02-20 10:35:29 -05:00
|
|
|
it_behaves_like 'build status summary'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'generic commit statuses' do
|
|
|
|
let(:type) { :generic_commit_status }
|
2016-10-03 07:35:53 -04:00
|
|
|
|
2016-02-20 10:35:29 -05:00
|
|
|
it_behaves_like 'build status summary'
|
|
|
|
end
|
2016-02-18 04:52:57 -05:00
|
|
|
end
|
2016-11-18 12:02:49 -05:00
|
|
|
|
|
|
|
context 'for scope with one status' do
|
2016-11-21 09:39:58 -05:00
|
|
|
shared_examples 'having a job' do |status|
|
|
|
|
%i[ci_build generic_commit_status].each do |type|
|
|
|
|
context "when it's #{status} #{type} job" do
|
|
|
|
let!(:job) { create(type, status) }
|
2016-11-18 12:02:49 -05:00
|
|
|
|
2016-11-21 09:39:58 -05:00
|
|
|
describe ".#{status}" do
|
|
|
|
it 'contains the job' do
|
|
|
|
expect(CommitStatus.public_send(status).all).
|
|
|
|
to contain_exactly(job)
|
|
|
|
end
|
2016-11-21 04:59:57 -05:00
|
|
|
end
|
2016-11-18 12:02:49 -05:00
|
|
|
|
2016-11-21 09:39:58 -05:00
|
|
|
describe '.relevant' do
|
|
|
|
if status == :created
|
|
|
|
it 'contains nothing' do
|
|
|
|
expect(CommitStatus.relevant.all).to be_empty
|
|
|
|
end
|
|
|
|
else
|
|
|
|
it 'contains the job' do
|
|
|
|
expect(CommitStatus.relevant.all).to contain_exactly(job)
|
|
|
|
end
|
2016-11-18 12:02:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
%i[created running pending success
|
|
|
|
failed canceled skipped].each do |status|
|
2016-11-21 09:39:58 -05:00
|
|
|
it_behaves_like 'having a job', status
|
2016-11-18 12:02:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for scope with more statuses' do
|
2016-11-21 09:39:58 -05:00
|
|
|
shared_examples 'containing the job' do |status|
|
|
|
|
%i[ci_build generic_commit_status].each do |type|
|
|
|
|
context "when it's #{status} #{type} job" do
|
|
|
|
let!(:job) { create(type, status) }
|
2016-11-18 12:02:49 -05:00
|
|
|
|
2016-11-21 09:39:58 -05:00
|
|
|
it 'contains the job' do
|
|
|
|
is_expected.to contain_exactly(job)
|
|
|
|
end
|
2016-11-21 04:59:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-21 09:39:58 -05:00
|
|
|
shared_examples 'not containing the job' do |status|
|
|
|
|
%i[ci_build generic_commit_status].each do |type|
|
|
|
|
context "when it's #{status} #{type} job" do
|
|
|
|
let!(:job) { create(type, status) }
|
2016-11-21 04:59:57 -05:00
|
|
|
|
2016-11-21 09:39:58 -05:00
|
|
|
it 'contains nothing' do
|
|
|
|
is_expected.to be_empty
|
|
|
|
end
|
2016-11-18 12:02:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.running_or_pending' do
|
|
|
|
subject { CommitStatus.running_or_pending }
|
|
|
|
|
2016-11-21 04:59:57 -05:00
|
|
|
%i[running pending].each do |status|
|
2016-11-21 09:39:58 -05:00
|
|
|
it_behaves_like 'containing the job', status
|
2016-11-18 12:02:49 -05:00
|
|
|
end
|
2016-11-21 04:59:57 -05:00
|
|
|
|
2016-11-21 09:39:58 -05:00
|
|
|
%i[created failed success].each do |status|
|
|
|
|
it_behaves_like 'not containing the job', status
|
|
|
|
end
|
2016-11-18 12:02:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '.finished' do
|
|
|
|
subject { CommitStatus.finished }
|
|
|
|
|
2016-11-21 04:59:57 -05:00
|
|
|
%i[success failed canceled].each do |status|
|
2016-11-21 09:39:58 -05:00
|
|
|
it_behaves_like 'containing the job', status
|
2016-11-18 12:02:49 -05:00
|
|
|
end
|
2016-11-21 04:59:57 -05:00
|
|
|
|
2016-11-21 09:39:58 -05:00
|
|
|
%i[created running pending].each do |status|
|
|
|
|
it_behaves_like 'not containing the job', status
|
|
|
|
end
|
2016-11-18 12:02:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '.cancelable' do
|
|
|
|
subject { CommitStatus.cancelable }
|
|
|
|
|
2016-11-21 04:59:57 -05:00
|
|
|
%i[running pending created].each do |status|
|
2016-11-21 09:39:58 -05:00
|
|
|
it_behaves_like 'containing the job', status
|
2016-11-18 12:02:49 -05:00
|
|
|
end
|
2016-11-21 04:59:57 -05:00
|
|
|
|
2016-11-21 09:39:58 -05:00
|
|
|
%i[failed success skipped canceled].each do |status|
|
|
|
|
it_behaves_like 'not containing the job', status
|
|
|
|
end
|
2016-11-18 12:02:49 -05:00
|
|
|
end
|
|
|
|
end
|
2016-02-18 04:52:57 -05:00
|
|
|
end
|