Use usual method to retrieve CI/CD stage statuses

This commit is contained in:
Grzegorz Bizon 2017-08-16 13:30:49 +02:00
parent 32d0983a4e
commit 1066d8ba77
4 changed files with 6 additions and 6 deletions

View File

@ -10,7 +10,7 @@ module Ci
belongs_to :project
belongs_to :pipeline
has_many :commit_statuses, foreign_key: :stage_id
has_many :statuses, class_name: 'CommitStatus', foreign_key: :stage_id
has_many :builds, foreign_key: :stage_id
validates :project, presence: true, unless: :importing?
@ -50,7 +50,7 @@ module Ci
def update_status
retry_optimistic_lock(self) do
case commit_statuses.latest.status
case statuses.latest.status
when 'pending' then enqueue
when 'running' then run
when 'success' then succeed

View File

@ -17,7 +17,7 @@ FactoryGirl.define do
end
factory :ci_stage_entity, class: Ci::Stage do
project factory: :empty_project
project factory: :project
pipeline factory: :ci_empty_pipeline
name 'test'

View File

@ -119,7 +119,7 @@ pipeline_variables:
stages:
- project
- pipeline
- commit_statuses
- statuses
- builds
statuses:
- project

View File

@ -9,9 +9,9 @@ describe Ci::Stage, :models do
create(:commit_status, stage_id: stage.id)
end
describe '#commit_statuses' do
describe '#statuses' do
it 'returns all commit statuses' do
expect(stage.commit_statuses.count).to be 2
expect(stage.statuses.count).to be 2
end
end