diff --git a/app/models/notification.rb b/app/models/notification.rb index 3f5a00aac..0fa2350ee 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -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 diff --git a/test/models/notification_test.rb b/test/models/notification_test.rb index 7e28aca7d..cb230070a 100644 --- a/test/models/notification_test.rb +++ b/test/models/notification_test.rb @@ -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