Validate parameters when active is false

This commit is contained in:
Shinya Maeda 2017-05-26 18:00:42 +09:00
parent 602d09ffe8
commit 5d8ee3ed1c

View file

@ -10,9 +10,9 @@ module Ci
has_one :last_pipeline, -> { order(id: :desc) }, class_name: 'Ci::Pipeline' has_one :last_pipeline, -> { order(id: :desc) }, class_name: 'Ci::Pipeline'
has_many :pipelines has_many :pipelines
validates :cron, unless: :importing_or_inactive?, cron: true, presence: { unless: :importing_or_inactive? } validates :cron, unless: :importing?, cron: true, presence: { unless: :importing? }
validates :cron_timezone, cron_timezone: true, presence: { unless: :importing_or_inactive? } validates :cron_timezone, cron_timezone: true, presence: { unless: :importing? }
validates :ref, presence: { unless: :importing_or_inactive? } validates :ref, presence: { unless: :importing? }
validates :description, presence: true validates :description, presence: true
before_save :set_next_run_at before_save :set_next_run_at
@ -32,10 +32,6 @@ module Ci
update_attribute(:active, false) update_attribute(:active, false)
end end
def importing_or_inactive?
importing? || inactive?
end
def runnable_by_owner? def runnable_by_owner?
Ability.allowed?(owner, :create_pipeline, project) Ability.allowed?(owner, :create_pipeline, project)
end end