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:
Rosa Gutierrez
2026-01-22 18:32:49 +01:00
parent 0948533da7
commit 7864748be9
7 changed files with 45 additions and 58 deletions
@@ -1,13 +1,11 @@
class Notification::PushTarget::Native < Notification::PushTarget
private
def should_push?
super && devices.any?
end
def perform_push
def process
if devices.any?
native_notification.deliver_later_to(devices)
end
end
private
def devices
@devices ||= notification.identity.devices
end
@@ -50,16 +50,6 @@ class Notification::PushTarget::NativeTest < ActiveSupport::TestCase
end
end
test "does not push when creator is system user" do
stub_push_services
@identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone")
@notification.update!(creator: users(:system))
assert_no_native_push_delivery do
Notification::PushTarget::Native.new(@notification).process
end
end
test "pushes to multiple devices" do
stub_push_services
@identity.devices.delete_all