summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-04 15:50:03 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-04 15:50:03 +0200
commit22d8460b5d9926d7608d23aeb58e20d9035efa92 (patch)
treeb0c54448933f7a737765cb1d1d467ba768e043c2
parenta17c90b2a7331a7427813684b04095b55c4b3cc1 (diff)
downloadgitlab-ce-22d8460b5d9926d7608d23aeb58e20d9035efa92.tar.gz
Add some validations to persisted stage model
-rw-r--r--app/models/ci/stage.rb5
-rw-r--r--app/models/concerns/has_status.rb12
-rw-r--r--spec/factories/ci/stages.rb2
3 files changed, 11 insertions, 8 deletions
diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb
index 0c7f8c7f485..da1c3753924 100644
--- a/app/models/ci/stage.rb
+++ b/app/models/ci/stage.rb
@@ -1,6 +1,7 @@
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
diff --git a/app/models/concerns/has_status.rb b/app/models/concerns/has_status.rb
index 235196cae13..8ea5a007f76 100644
--- a/app/models/concerns/has_status.rb
+++ b/app/models/concerns/has_status.rb
@@ -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
diff --git a/spec/factories/ci/stages.rb b/spec/factories/ci/stages.rb
index ee8ac85c92e..bace932cf99 100644
--- a/spec/factories/ci/stages.rb
+++ b/spec/factories/ci/stages.rb
@@ -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