Make sure Bundle#ends_at is set before validation
otherwise we risk creating overlapping bundles and not catching it.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user