Move custom compound status method to commit status

This commit is contained in:
Grzegorz Bizon 2017-05-08 14:26:08 +02:00
parent 64e09a1b35
commit 21f3e9ce26
3 changed files with 31 additions and 3 deletions

View File

@ -103,6 +103,12 @@ class CommitStatus < ActiveRecord::Base
end
end
def self.status
super.tap do |status|
return 'success' if status == 'skipped' && all.failed_but_allowed.any?
end
end
def locking_enabled?
status_changed?
end

View File

@ -37,9 +37,7 @@ module HasStatus
end
def status
all.pluck(status_sql).first.tap do |status|
return 'success' if status == 'skipped' && all.failed_but_allowed.any?
end
all.pluck(status_sql).first
end
def started_at

View File

@ -284,6 +284,30 @@ describe CommitStatus, :models do
end
end
describe '.status' do
context 'when there are multiple statuses present' do
before do
create_status(status: 'running')
create_status(status: 'success')
create_status(allow_failure: true, status: 'failed')
end
it 'returns a correct compound status' do
expect(described_class.all.status).to eq 'running'
end
end
context 'when there are only allowed to fail commit statuses present' do
before do
create_status(allow_failure: true, status: 'failed')
end
it 'returns status that indicates success' do
expect(described_class.all.status).to eq 'success'
end
end
end
describe '#before_sha' do
subject { commit_status.before_sha }