Simplify PushTarget by removing template method pattern
Each target now implements process directly with its own logic, rather than using processable?/perform_push hooks. The pushable? check is done once in Notification#push before iterating targets. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -37,20 +37,6 @@ class Notification::PushTarget::WebTest < ActiveSupport::TestCase
|
||||
Notification::PushTarget::Web.new(@notification).process
|
||||
end
|
||||
|
||||
test "does not push for cancelled accounts" do
|
||||
@user.account.cancel(initiated_by: @user)
|
||||
@web_push_pool.expects(:queue).never
|
||||
|
||||
Notification::PushTarget::Web.new(@notification).process
|
||||
end
|
||||
|
||||
test "does not push when creator is system user" do
|
||||
@notification.update!(creator: users(:system))
|
||||
@web_push_pool.expects(:queue).never
|
||||
|
||||
Notification::PushTarget::Web.new(@notification).process
|
||||
end
|
||||
|
||||
test "payload includes card title for card events" do
|
||||
@web_push_pool.expects(:queue).once.with do |payload, _|
|
||||
payload[:title] == @notification.card.title
|
||||
|
||||
@@ -46,19 +46,43 @@ class Notification::PushableTest < ActiveSupport::TestCase
|
||||
Notification.push_targets = original_targets
|
||||
end
|
||||
|
||||
test "pushable? returns true for normal notifications" do
|
||||
assert @notification.pushable?
|
||||
test "push processes targets for normal notifications" 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 "pushable? returns false when creator is system user" do
|
||||
test "push skips targets when creator is system user" do
|
||||
@notification.update!(creator: users(:system))
|
||||
|
||||
assert_not @notification.pushable?
|
||||
target_class = mock("push_target_class")
|
||||
target_class.expects(:process).never
|
||||
|
||||
original_targets = Notification.push_targets
|
||||
Notification.push_targets = [ target_class ]
|
||||
|
||||
@notification.push
|
||||
ensure
|
||||
Notification.push_targets = original_targets
|
||||
end
|
||||
|
||||
test "pushable? returns false for cancelled accounts" do
|
||||
test "push skips targets for cancelled accounts" do
|
||||
@user.account.cancel(initiated_by: @user)
|
||||
|
||||
assert_not @notification.pushable?
|
||||
target_class = mock("push_target_class")
|
||||
target_class.expects(:process).never
|
||||
|
||||
original_targets = Notification.push_targets
|
||||
Notification.push_targets = [ target_class ]
|
||||
|
||||
@notification.push
|
||||
ensure
|
||||
Notification.push_targets = original_targets
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user