BigW Consortium Gitlab

Commit 0605cdd7 by Grzegorz Bizon

Implement proper associations with a persisted stage

parent c7a7ef04
......@@ -9,8 +9,8 @@ module Ci
belongs_to :project
belongs_to :pipeline
has_many :statuses, class_name: 'CommitStatus', foreign_key: :commit_id
has_many :builds, foreign_key: :commit_id
has_many :commit_statuses, foreign_key: :stage_id
has_many :builds, foreign_key: :stage_id
validates :project, presence: true, unless: :importing?
validates :pipeline, presence: true, unless: :importing?
......
require 'spec_helper'
describe Ci::Stage, :models do
describe 'associations' do
let(:stage) { create(:ci_stage_entity) }
before do
create(:ci_build, stage_id: stage.id)
create(:commit_status, stage_id: stage.id)
end
describe '#commit_statuses' do
it 'returns all commit statuses' do
expect(stage.commit_statuses.count).to be 2
end
end
describe '#builds' do
it 'returns only builds' do
expect(stage.builds).to be_one
end
end
end
describe '#status' do
context 'when stage is pending' do
let(:stage) { create(:ci_stage_entity, status: 'pending') }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment