Files
fizzy/test/models/notification/pushable_test.rb
T
Rosa Gutierrez b5205ce6b2 Rename Push to PushTarget for better readability
PushTarget#push reads more naturally than Push#push. The push target
is the thing that pushes notifications to a specific destination.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-25 19:31:13 +01:00

59 lines
1.5 KiB
Ruby

require "test_helper"
class Notification::PushableTest < ActiveSupport::TestCase
setup do
@user = users(:david)
@notification = @user.notifications.create!(
source: events(:logo_published),
creator: users(:jason)
)
end
test "push_later calls push_later on all registered targets" do
target = mock("push_target")
target.expects(:push_later).with(@notification)
original_targets = Notification.push_targets
Notification.push_targets = [ target ]
@notification.push_later
ensure
Notification.push_targets = original_targets
end
test "push_later is called after notification is created" do
Notification.any_instance.expects(:push_later)
@user.notifications.create!(
source: events(:logo_published),
creator: users(:jason)
)
end
test "register_push_target accepts symbols" do
original_targets = Notification.push_targets.dup
Notification.register_push_target(:web)
assert_includes Notification.push_targets, Notification::PushTarget::Web
ensure
Notification.push_targets = original_targets
end
test "pushable? returns true for normal notifications" do
assert @notification.pushable?
end
test "pushable? returns false when creator is system user" do
@notification.update!(creator: users(:system))
assert_not @notification.pushable?
end
test "pushable? returns false for cancelled accounts" do
@user.account.cancel(initiated_by: @user)
assert_not @notification.pushable?
end
end