diff options
Diffstat (limited to 'app/models/ci/trigger_schedule.rb')
-rw-r--r-- | app/models/ci/trigger_schedule.rb | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/app/models/ci/trigger_schedule.rb b/app/models/ci/trigger_schedule.rb index 72716eb416b..c9a16643f32 100644 --- a/app/models/ci/trigger_schedule.rb +++ b/app/models/ci/trigger_schedule.rb @@ -6,20 +6,19 @@ module Ci acts_as_paranoid belongs_to :project - belongs_to :trigger, inverse_of: :trigger_schedule - - delegate :ref, to: :trigger, allow_nil: true + belongs_to :trigger validates :trigger, presence: { unless: :importing? } - validates :cron, cron: true, presence: { unless: :importing? } - validates :cron_timezone, cron_timezone: true, presence: { unless: :importing? } - validates :ref, presence: { unless: :importing? } + validates :cron, unless: :importing_or_inactive?, cron: true, presence: { unless: :importing_or_inactive? } + validates :cron_timezone, cron_timezone: true, presence: { unless: :importing_or_inactive? } + validates :ref, presence: { unless: :importing_or_inactive? } - before_create :set_project before_save :set_next_run_at - def set_project - self.project = trigger.project + scope :active, -> { where(active: true) } + + def importing_or_inactive? + importing? || !active? end def set_next_run_at |