BigW Consortium Gitlab

Commit 22d8460b by Grzegorz Bizon

Add some validations to persisted stage model

parent a17c90b2
module Ci
class Stage < ActiveRecord::Base
extend Ci::Model
include Importable
include HasStatus
enumerated_status!
......@@ -10,5 +11,9 @@ module Ci
has_many :statuses, class_name: 'CommitStatus', foreign_key: :commit_id
has_many :builds, foreign_key: :commit_id
validates :project, presence: true, unless: :importing?
validates :pipeline, presence: true, unless: :importing?
validates :name, presence: true, unless: :importing?
end
end
......@@ -12,6 +12,10 @@ module HasStatus
failed: 4, canceled: 5, skipped: 6, manual: 7 }
class_methods do
def enumerated_status!
enum status: HasStatus::STATUSES_ENUM
end
def status_sql
scope_relevant = respond_to?(:exclude_ignored) ? exclude_ignored : all
scope_warnings = respond_to?(:failed_but_allowed) ? failed_but_allowed : none
......@@ -56,14 +60,6 @@ module HasStatus
def all_state_names
state_machines.values.flat_map(&:states).flat_map { |s| s.map(&:name) }
end
private
def enumerated_status!
@status_strategy = :enumerator
enum status: HasStatus::STATUSES_ENUM
end
end
included do
......
......@@ -19,6 +19,8 @@ FactoryGirl.define do
factory :ci_stage_entity, class: Ci::Stage do
project factory: :empty_project
pipeline factory: :ci_empty_pipeline
name 'test'
status 'pending'
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