summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-05-08 14:26:08 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-06-20 15:32:29 +0200
commit21f3e9ce2617b8869583bdae60cc619bcd0a29bd (patch)
tree8aecc2f70d260a37da98a8baea2fb4912a10443b
parent64e09a1b35cc1897df7e46e73989c6e7013f6196 (diff)
downloadgitlab-ce-21f3e9ce2617b8869583bdae60cc619bcd0a29bd.tar.gz
Move custom compound status method to commit status
-rw-r--r--app/models/commit_status.rb6
-rw-r--r--app/models/concerns/has_status.rb4
-rw-r--r--spec/models/commit_status_spec.rb24
3 files changed, 31 insertions, 3 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb
index 07cec63b939..500d05fd840 100644
--- a/app/models/commit_status.rb
+++ b/app/models/commit_status.rb
@@ -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
diff --git a/app/models/concerns/has_status.rb b/app/models/concerns/has_status.rb
index 692bd1f9317..3c9c6584e02 100644
--- a/app/models/concerns/has_status.rb
+++ b/app/models/concerns/has_status.rb
@@ -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
diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb
index 9262ce08987..2ee9620228c 100644
--- a/spec/models/commit_status_spec.rb
+++ b/spec/models/commit_status_spec.rb
@@ -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 }