From 4093ebdda537b7ffe6c9eda514868d980d6b204c Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Mon, 16 Dec 2024 16:21:18 -0600 Subject: [PATCH] Inherit Notification from parent class --- CHANGELOG.md | 1 + app/models/concerns/noticed/notification_methods.rb | 2 +- test/dummy/app/notifiers/application_notifier.rb | 4 ++++ test/notifier_test.rb | 4 ++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9831d168..eee750d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### Unreleased +* Inherit Notification from parent class Notification. * Support callbacks in bulk delivery methods. ### 2.4.3 diff --git a/app/models/concerns/noticed/notification_methods.rb b/app/models/concerns/noticed/notification_methods.rb index e5233698..3b5f28b5 100644 --- a/app/models/concerns/noticed/notification_methods.rb +++ b/app/models/concerns/noticed/notification_methods.rb @@ -6,7 +6,7 @@ module NotificationMethods # Generate a Notification class each time a Notifier is defined def inherited(notifier) super - notifier.const_set :Notification, Class.new(Noticed::Notification) + notifier.const_set :Notification, Class.new(const_defined?(:Notification) ? const_get(:Notification) : Noticed::Notification) end def notification_methods(&block) diff --git a/test/dummy/app/notifiers/application_notifier.rb b/test/dummy/app/notifiers/application_notifier.rb index 90c8fd4e..93fd3d51 100644 --- a/test/dummy/app/notifiers/application_notifier.rb +++ b/test/dummy/app/notifiers/application_notifier.rb @@ -1,2 +1,6 @@ class ApplicationNotifier < Noticed::Event + notification_methods do + def inherited_method + end + end end diff --git a/test/notifier_test.rb b/test/notifier_test.rb index 635a2c3b..cd16486c 100644 --- a/test/notifier_test.rb +++ b/test/notifier_test.rb @@ -232,4 +232,8 @@ class RecipientsLambdaEphemeral < Noticed::Ephemeral end end end + + test "inherits notification_methods from application notifier" do + assert SimpleNotifier::Notification.new.respond_to?(:inherited_method) + end end