Use a new stage_id reference to a persisted stage

This commit is contained in:
Grzegorz Bizon 2017-07-20 12:56:27 +02:00
parent 9c10683b01
commit c7a7ef044c
2 changed files with 5 additions and 6 deletions

View File

@ -43,9 +43,7 @@ class CommitStatus < ActiveRecord::Base
# `ci_builds.stage` attribute and migrate `ci_builds.stage_id` reference in
# one of upcoming releases.
#
def stage_entity
Ci::Stage.find_by(pipeline: pipeline, name: stage)
end
belongs_to :stage_entity, foreign_key: :stage_id, class_name: 'Ci::Stage'
state_machine :status do
event :enqueue do

View File

@ -409,9 +409,10 @@ describe CommitStatus, :models do
end
describe '#stage_entity' do
let!(:stage) do
create(:ci_stage_entity, pipeline: commit_status.pipeline,
name: commit_status.stage)
let(:stage) { create(:ci_stage_entity) }
let(:commit_status) do
create(:commit_status, stage_id: stage.id)
end
it 'has a correct association with persisted stage' do