Broadcast notifications that are deleted
To prevent 404s when someone doesn't refresh the page
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user