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

This commit is contained in:
Lin Jen-Shin 2016-10-03 19:35:53 +08:00
parent 752a4cce51
commit afc0ae5cbe
2 changed files with 21 additions and 24 deletions

View file

@ -22,8 +22,8 @@ module HasStatus
canceled = scope.canceled.select('count(*)').to_sql canceled = scope.canceled.select('count(*)').to_sql
"(CASE "(CASE
WHEN (#{builds})=(#{created}) THEN 'created'
WHEN (#{builds})=(#{success}) THEN 'success' WHEN (#{builds})=(#{success}) THEN 'success'
WHEN (#{builds})=(#{created}) THEN 'created'
WHEN (#{builds})=(#{success})+(#{skipped}) THEN 'skipped' WHEN (#{builds})=(#{success})+(#{skipped}) THEN 'skipped'
WHEN (#{builds})=(#{success})+(#{skipped})+(#{canceled}) THEN 'canceled' WHEN (#{builds})=(#{success})+(#{skipped})+(#{canceled}) THEN 'canceled'
WHEN (#{builds})=(#{created})+(#{skipped})+(#{pending}) THEN 'pending' WHEN (#{builds})=(#{created})+(#{skipped})+(#{pending}) THEN 'pending'

View file

@ -1,26 +1,17 @@
require 'spec_helper' require 'spec_helper'
describe HasStatus do describe HasStatus do
before do
@object = Object.new
@object.extend(HasStatus::ClassMethods)
end
describe '.status' do describe '.status' do
before do subject { CommitStatus.status }
allow(@object).to receive(:all).and_return(CommitStatus.where(id: statuses))
end
subject { @object.status }
shared_examples 'build status summary' do shared_examples 'build status summary' do
context 'all successful' 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' } it { is_expected.to eq 'success' }
end end
context 'at least one failed' do context 'at least one failed' do
let(:statuses) do let!(:statuses) do
[create(type, status: :success), create(type, status: :failed)] [create(type, status: :success), create(type, status: :failed)]
end end
@ -28,7 +19,7 @@ describe HasStatus do
end end
context 'at least one running' do context 'at least one running' do
let(:statuses) do let!(:statuses) do
[create(type, status: :success), create(type, status: :running)] [create(type, status: :success), create(type, status: :running)]
end end
@ -36,7 +27,7 @@ describe HasStatus do
end end
context 'at least one pending' do context 'at least one pending' do
let(:statuses) do let!(:statuses) do
[create(type, status: :success), create(type, status: :pending)] [create(type, status: :success), create(type, status: :pending)]
end end
@ -44,7 +35,7 @@ describe HasStatus do
end end
context 'success and failed but allowed to fail' do context 'success and failed but allowed to fail' do
let(:statuses) do let!(:statuses) do
[create(type, status: :success), [create(type, status: :success),
create(type, status: :failed, allow_failure: true)] create(type, status: :failed, allow_failure: true)]
end end
@ -53,12 +44,15 @@ describe HasStatus do
end end
context 'one failed but allowed to fail' do 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' } it { is_expected.to eq 'success' }
end end
context 'success and canceled' do context 'success and canceled' do
let(:statuses) do let!(:statuses) do
[create(type, status: :success), create(type, status: :canceled)] [create(type, status: :success), create(type, status: :canceled)]
end end
@ -66,7 +60,7 @@ describe HasStatus do
end end
context 'one failed and one canceled' do context 'one failed and one canceled' do
let(:statuses) do let!(:statuses) do
[create(type, status: :failed), create(type, status: :canceled)] [create(type, status: :failed), create(type, status: :canceled)]
end end
@ -74,7 +68,7 @@ describe HasStatus do
end end
context 'one failed but allowed to fail and one canceled' do 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: :failed, allow_failure: true),
create(type, status: :canceled)] create(type, status: :canceled)]
end end
@ -83,7 +77,7 @@ describe HasStatus do
end end
context 'one running one canceled' do context 'one running one canceled' do
let(:statuses) do let!(:statuses) do
[create(type, status: :running), create(type, status: :canceled)] [create(type, status: :running), create(type, status: :canceled)]
end end
@ -91,14 +85,15 @@ describe HasStatus do
end end
context 'all canceled' do context 'all canceled' do
let(:statuses) do let!(:statuses) do
[create(type, status: :canceled), create(type, status: :canceled)] [create(type, status: :canceled), create(type, status: :canceled)]
end end
it { is_expected.to eq 'canceled' } it { is_expected.to eq 'canceled' }
end end
context 'success and canceled but allowed to fail' do context 'success and canceled but allowed to fail' do
let(:statuses) do let!(:statuses) do
[create(type, status: :success), [create(type, status: :success),
create(type, status: :canceled, allow_failure: true)] create(type, status: :canceled, allow_failure: true)]
end end
@ -107,7 +102,7 @@ describe HasStatus do
end end
context 'one finished and second running but allowed to fail' do context 'one finished and second running but allowed to fail' do
let(:statuses) do let!(:statuses) do
[create(type, status: :success), [create(type, status: :success),
create(type, status: :running, allow_failure: true)] create(type, status: :running, allow_failure: true)]
end end
@ -118,11 +113,13 @@ describe HasStatus do
context 'ci build statuses' do context 'ci build statuses' do
let(:type) { :ci_build } let(:type) { :ci_build }
it_behaves_like 'build status summary' it_behaves_like 'build status summary'
end end
context 'generic commit statuses' do context 'generic commit statuses' do
let(:type) { :generic_commit_status } let(:type) { :generic_commit_status }
it_behaves_like 'build status summary' it_behaves_like 'build status summary'
end end
end end