Commit f0d59b95 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Validate presence of a stage index in the model

parent 43dd213b
......@@ -13,9 +13,12 @@ module Ci
has_many :statuses, class_name: 'CommitStatus', foreign_key: :stage_id
has_many :builds, foreign_key: :stage_id
validates :project, presence: true, unless: :importing?
validates :pipeline, presence: true, unless: :importing?
validates :name, presence: true, unless: :importing?
with_options unless: :importing? do
validates :project, presence: true
validates :pipeline, presence: true
validates :name, presence: true
validates :index, presence: true
end
after_initialize do |stage|
self.status = DEFAULT_STATUS if self.status.nil?
......
......@@ -42,6 +42,7 @@ module Ci
def create_stage
Ci::Stage.create!(name: @build.stage,
index: @build.stage_idx,
pipeline: @build.pipeline,
project: @build.project)
end
......
......@@ -19,6 +19,7 @@ module Gitlab
def attributes
{ name: @attributes.fetch(:name),
index: @attributes.fetch(:index),
pipeline: @pipeline,
project: @pipeline.project }
end
......
......@@ -21,6 +21,7 @@ FactoryBot.define do
pipeline factory: :ci_empty_pipeline
name 'test'
index 1
status 'pending'
end
end
......@@ -24,7 +24,8 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
describe '#attributes' do
it 'returns hash attributes of a stage' do
expect(subject.attributes).to be_a Hash
expect(subject.attributes).to include(:name, :project)
expect(subject.attributes)
.to include(:name, :index, :pipeline, :project)
end
end
......
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