diff --git a/app/models/foreman_tasks/triggering.rb b/app/models/foreman_tasks/triggering.rb index 6009e5384..d506cf95d 100644 --- a/app/models/foreman_tasks/triggering.rb +++ b/app/models/foreman_tasks/triggering.rb @@ -38,6 +38,7 @@ class Triggering < ApplicationRecord :if => proc { |t| t.recurring? && t.input_type == :monthly } } validate :can_start_recurring, :if => :recurring? validate :can_start_future, :if => :future? + validate :start_at_is_not_past def self.new_from_params(params = {}) new(params.except(:mode, :start_at, :start_before)).tap do |triggering| @@ -121,5 +122,9 @@ def can_start_future parse_start_at! errors.add(:start_before_raw, _('The task could not be started')) if !start_before.nil? && start_before < start_at end + + def start_at_is_not_past + errors.add(:start_at, _('is in the past')) if !start_at.nil? && Time.zone.parse(start_at_raw) < Time.zone.now + end end end diff --git a/test/unit/triggering_test.rb b/test/unit/triggering_test.rb index 6e511b4b1..6d867d6f7 100644 --- a/test/unit/triggering_test.rb +++ b/test/unit/triggering_test.rb @@ -10,7 +10,7 @@ class TriggeringTest < ActiveSupport::TestCase triggering = FactoryBot.build(:triggering, :future) assert_predicate(triggering, :valid?) triggering.start_before = triggering.start_at - 120 - assert_not_predicate(triggering, :valid?) + assert_not_predicate(triggering, :valid?).returns(false) end it 'is invalid when recurring logic is invalid' do