Make sure Bundle#ends_at is set before validation

otherwise we risk creating overlapping bundles and not catching it.
This commit is contained in:
Mike Dalessio
2025-11-22 22:19:05 -05:00
parent 31266699cb
commit a29dd89683
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ class Notification::Bundle < ApplicationRecord
)
end
before_create :set_default_window
before_validation :set_default_window, if: :new_record?
validate :validate_no_overlapping
+10
View File
@@ -83,6 +83,16 @@ class Notification::BundleTest < ActiveSupport::TestCase
assert bundle_5.valid?
end
test "overlapping bundles that are created relying on set_default_window are not created" do
@user.notification_bundles.destroy_all
bundle = @user.notification_bundles.create!(starts_at: Time.current)
assert_raises ActiveRecord::RecordInvalid do
@user.notification_bundles.create!(starts_at: bundle.starts_at - 1.second)
end
end
test "deliver_all delivers due bundles" do
notification = @user.notifications.create!(source: events(:logo_published), creator: @user)