Broadcast notifications that are deleted

To prevent 404s when someone doesn't refresh the page
This commit is contained in:
Jorge Manrubia
2025-09-10 09:50:22 +02:00
parent 4cb090a23d
commit 58c525e5a6
2 changed files with 10 additions and 0 deletions
+1
View File
@@ -10,6 +10,7 @@ class Notification < ApplicationRecord
scope :ordered, -> { order(read_at: :desc, created_at: :desc) }
after_create_commit :broadcast_unread
after_destroy_commit :broadcast_read
after_create :bundle
delegate :notifiable_target, to: :source
+9
View File
@@ -38,4 +38,13 @@ class NotificationTest < ActiveSupport::TestCase
notification.read
end
end
test "deleting notification broadcasts its removal" do
notification = notifications(:logo_published_kevin)
notification.update!(read_at: nil)
assert_turbo_stream_broadcasts([ notification.user, :notifications ], count: 1) do
notification.destroy
end
end
end