Commit afc0ae5c authored by Lin Jen-Shin's avatar Lin Jen-Shin

Fix tests. Check 'success' first (default status)

parent 752a4cce
......@@ -22,8 +22,8 @@ module HasStatus
canceled = scope.canceled.select('count(*)').to_sql
"(CASE
WHEN (#{builds})=(#{created}) THEN 'created'
WHEN (#{builds})=(#{success}) THEN 'success'
WHEN (#{builds})=(#{created}) THEN 'created'
WHEN (#{builds})=(#{success})+(#{skipped}) THEN 'skipped'
WHEN (#{builds})=(#{success})+(#{skipped})+(#{canceled}) THEN 'canceled'
WHEN (#{builds})=(#{created})+(#{skipped})+(#{pending}) THEN 'pending'
......
require 'spec_helper'
describe HasStatus do
before do
@object = Object.new
@object.extend(HasStatus::ClassMethods)
end
describe '.status' do
before do
allow(@object).to receive(:all).and_return(CommitStatus.where(id: statuses))
end
subject { @object.status }
subject { CommitStatus.status }
shared_examples 'build status summary' do
context 'all successful' do
let(:statuses) { Array.new(2) { create(type, status: :success) } }
let!(:statuses) { Array.new(2) { create(type, status: :success) } }
it { is_expected.to eq 'success' }
end
context 'at least one failed' do
let(:statuses) do
let!(:statuses) do
[create(type, status: :success), create(type, status: :failed)]
end
......@@ -28,7 +19,7 @@ describe HasStatus do
end
context 'at least one running' do
let(:statuses) do
let!(:statuses) do
[create(type, status: :success), create(type, status: :running)]
end
......@@ -36,7 +27,7 @@ describe HasStatus do
end
context 'at least one pending' do
let(:statuses) do
let!(:statuses) do
[create(type, status: :success), create(type, status: :pending)]
end
......@@ -44,7 +35,7 @@ describe HasStatus do
end
context 'success and failed but allowed to fail' do
let(:statuses) do
let!(:statuses) do
[create(type, status: :success),
create(type, status: :failed, allow_failure: true)]
end
......@@ -53,12 +44,15 @@ describe HasStatus do
end
context 'one failed but allowed to fail' do
let(:statuses) { [create(type, status: :failed, allow_failure: true)] }
let!(:statuses) do
[create(type, status: :failed, allow_failure: true)]
end
it { is_expected.to eq 'success' }
end
context 'success and canceled' do
let(:statuses) do
let!(:statuses) do
[create(type, status: :success), create(type, status: :canceled)]
end
......@@ -66,7 +60,7 @@ describe HasStatus do
end
context 'one failed and one canceled' do
let(:statuses) do
let!(:statuses) do
[create(type, status: :failed), create(type, status: :canceled)]
end
......@@ -74,7 +68,7 @@ describe HasStatus do
end
context 'one failed but allowed to fail and one canceled' do
let(:statuses) do
let!(:statuses) do
[create(type, status: :failed, allow_failure: true),
create(type, status: :canceled)]
end
......@@ -83,7 +77,7 @@ describe HasStatus do
end
context 'one running one canceled' do
let(:statuses) do
let!(:statuses) do
[create(type, status: :running), create(type, status: :canceled)]
end
......@@ -91,14 +85,15 @@ describe HasStatus do
end
context 'all canceled' do
let(:statuses) 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
let!(:statuses) do
[create(type, status: :success),
create(type, status: :canceled, allow_failure: true)]
end
......@@ -107,7 +102,7 @@ describe HasStatus do
end
context 'one finished and second running but allowed to fail' do
let(:statuses) do
let!(:statuses) do
[create(type, status: :success),
create(type, status: :running, allow_failure: true)]
end
......@@ -118,11 +113,13 @@ describe HasStatus do
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
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