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 ...@@ -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'
......
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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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
......
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