diff --git a/app/models/communication/website/agenda/event/with_kinds.rb b/app/models/communication/website/agenda/event/with_kinds.rb index f4aa1408fb..8a01cadf81 100644 --- a/app/models/communication/website/agenda/event/with_kinds.rb +++ b/app/models/communication/website/agenda/event/with_kinds.rb @@ -120,6 +120,8 @@ def no_child_after? end def in_parent_dates? + return if from_day.nil? || to_day.nil? + if from_day < parent.from_day || to_day > parent.to_day errors.add(:parent_id, :outside_parent_dates) end diff --git a/test/models/communication/website/agenda/event_test.rb b/test/models/communication/website/agenda/event_test.rb index 84b8b5e6d5..dab64f41a8 100644 --- a/test/models/communication/website/agenda/event_test.rb +++ b/test/models/communication/website/agenda/event_test.rb @@ -81,6 +81,21 @@ class Communication::Website::Agenda::EventTest < ActiveSupport::TestCase assert_nothing_raised { event_l10n.cal } end + test "child event with a missing start date is invalid, not a crash" do + parent = new_event( + from_day: Date.tomorrow, + to_day: Date.tomorrow + 2.days + ) + parent.save! + + child = new_event( + from_day: nil, + parent: parent + ) + assert_nothing_raised { child.valid? } + assert_not(child.valid?) + end + protected def new_event(**options)