Commit 22d8460b authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add some validations to persisted stage model

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