967f76de99
turbo-rails 2.0.21 changed `capture_turbo_stream_broadcasts` to only return broadcasts produced within the block, matching its documented behavior (see hotwired/turbo-rails#736). Since `broadcast_unread` uses `broadcast_prepend_later_to` (async via job), we need to wrap the call in `perform_enqueued_jobs` so the broadcast actually happens within the assertion block. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
53 lines
1.5 KiB
Ruby
53 lines
1.5 KiB
Ruby
require "test_helper"
|
|
|
|
class NotificationTest < ActiveSupport::TestCase
|
|
test "unread marks notification as unread" do
|
|
notification = notifications(:logo_published_kevin)
|
|
notification.read # Mark as read first
|
|
|
|
assert_changes -> { notification.reload.read? }, from: true, to: false do
|
|
notification.unread
|
|
end
|
|
end
|
|
|
|
test "unread broadcasts to notifications" do
|
|
notification = notifications(:logo_published_kevin)
|
|
notification.read # Mark as read first
|
|
|
|
assert_turbo_stream_broadcasts([ notification.user, :notifications ], count: 1) do
|
|
perform_enqueued_jobs do
|
|
notification.unread
|
|
end
|
|
end
|
|
end
|
|
|
|
test "read marks notification as read" do
|
|
notification = notifications(:logo_published_kevin)
|
|
# Ensure it starts as unread
|
|
notification.update!(read_at: nil)
|
|
|
|
assert_changes -> { notification.reload.read? }, from: false, to: true do
|
|
notification.read
|
|
end
|
|
end
|
|
|
|
test "read broadcasts to notifications" do
|
|
notification = notifications(:logo_published_kevin)
|
|
# Ensure it starts as unread
|
|
notification.update!(read_at: nil)
|
|
|
|
assert_turbo_stream_broadcasts([ notification.user, :notifications ], count: 1) do
|
|
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
|