diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-04-13 15:40:12 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-04-13 15:40:12 +0200 |
commit | 102537072bd56bac0e66533b8fa7166938687592 (patch) | |
tree | 41bd8f9c1f853afdd9057e5d3a7c6d750b6b2df8 /app/models | |
parent | 4d72ca39803615850267d034e9dc59540fe657b7 (diff) | |
download | gitlab-ce-102537072bd56bac0e66533b8fa7166938687592.tar.gz |
Fix CiStatus implementation and tests
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/commit_status.rb | 2 | ||||
-rw-r--r-- | app/models/concerns/ci_status.rb | 20 |
2 files changed, 11 insertions, 11 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 882595ca21e..66eb5dcecf9 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -51,8 +51,6 @@ class CommitStatus < ActiveRecord::Base scope :ordered, -> { order(:ref, :stage_idx, :name) } scope :ignored, -> { where(allow_failure: true, status: [:failed, :canceled]) } - AVAILABLE_STATUSES = ['pending', 'running', 'success', 'failed', 'canceled'] - state_machine :status, initial: :pending do event :run do transition pending: :running diff --git a/app/models/concerns/ci_status.rb b/app/models/concerns/ci_status.rb index 4c7089bc36c..67e15b2d55b 100644 --- a/app/models/concerns/ci_status.rb +++ b/app/models/concerns/ci_status.rb @@ -1,15 +1,17 @@ module CiStatus extend ActiveSupport::Concern - module ClassMethods + AVAILABLE_STATUSES = %w(pending running success failed canceled skipped) + + class_methods do def status_sql - builds = all.select('count(id)').to_sql - success = all.success.select('count(id)').to_sql - ignored = all.failed.where(allow_failure: true).select('count(id)').to_sql if all.try(:ignored) + builds = all.select('count(*)').to_sql + success = all.success.select('count(*)').to_sql + ignored = all.ignored.select('count(*)').to_sql if all.try(:ignored) ignored ||= '0' - pending = all.pending.select('count(id)').to_sql - running = all.running.select('count(id)').to_sql - canceled = all.canceled.select('count(id)').to_sql + pending = all.pending.select('count(*)').to_sql + running = all.running.select('count(*)').to_sql + canceled = all.canceled.select('count(*)').to_sql deduce_status = "(CASE WHEN (#{builds})=0 THEN 'skipped' @@ -24,7 +26,7 @@ module CiStatus end def status - pluck(self.status_sql).first + all.pluck(self.status_sql).first end def duration @@ -34,7 +36,7 @@ module CiStatus end included do - validates :status, inclusion: { in: %w(pending running failed success canceled skipped) } + validates :status, inclusion: { in: AVAILABLE_STATUSES } state_machine :status, initial: :pending do state :pending, value: 'pending' |