0948533da7
"Push to target" reads naturally - we push the notification to the target. "Target processes" also makes sense - the target receives and handles the notification in its own way. - Add class method PushTarget.process(notification) that instantiates and calls the instance method - Rename instance method from push to process - Add private push_to helper in Pushable for readable iteration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
65 lines
1.7 KiB
Ruby
65 lines
1.7 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 enqueues Notification::PushJob" do
|
|
assert_enqueued_with(job: Notification::PushJob, args: [ @notification ]) do
|
|
@notification.push_later
|
|
end
|
|
end
|
|
|
|
test "push calls process on all registered targets" do
|
|
target_class = mock("push_target_class")
|
|
target_class.expects(:process).with(@notification)
|
|
|
|
original_targets = Notification.push_targets
|
|
Notification.push_targets = [ target_class ]
|
|
|
|
@notification.push
|
|
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
|