diff --git a/README.md b/README.md index 950097b2..a343a0ea 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ For deeper specifics on setting up the `:action_cable`, `:email`, and `:discord` #### Delivery Method Configuration -Each delivery method can be configured with a block that yields a `config` object. +Each delivery method can be configured with a block that yields a `config` object. Procs/Lambdas will be evaluated when needed and symbols can be used to call a method. @@ -324,8 +324,8 @@ module IosNotifier end end end -``` - +``` + #### Shared Delivery Method Options Each of these options are available for every delivery method (individual or bulk). The value passed may be a lambda, a symbol that represents a callable method, a symbol value, or a string value. diff --git a/app/models/concerns/noticed/deliverable.rb b/app/models/concerns/noticed/deliverable.rb index 05621c07..ba684c61 100644 --- a/app/models/concerns/noticed/deliverable.rb +++ b/app/models/concerns/noticed/deliverable.rb @@ -91,7 +91,7 @@ def deliver(recipients = nil, options = {}) def recipient_attributes_for(recipient) { type: "#{self.class.name}::Notification", - recipient_type: recipient.class.name, + recipient_type: recipient.class.base_class.name, recipient_id: recipient.id } end diff --git a/test/dummy/app/models/admin.rb b/test/dummy/app/models/admin.rb new file mode 100644 index 00000000..2850a1a0 --- /dev/null +++ b/test/dummy/app/models/admin.rb @@ -0,0 +1,2 @@ +class Admin < User +end diff --git a/test/dummy/db/migrate/20231215202921_create_users.rb b/test/dummy/db/migrate/20231215202921_create_users.rb index 1098860c..90848dd2 100644 --- a/test/dummy/db/migrate/20231215202921_create_users.rb +++ b/test/dummy/db/migrate/20231215202921_create_users.rb @@ -1,6 +1,7 @@ class CreateUsers < ActiveRecord::Migration[7.1] def change create_table :users do |t| + t.string :type t.string :email t.timestamps diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index d4ce6af7..747a13d6 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -41,6 +41,7 @@ end create_table "users", force: :cascade do |t| + t.string "type" t.string "email" t.datetime "created_at", null: false t.datetime "updated_at", null: false diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 584e4641..256fd71d 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -3,3 +3,7 @@ one: two: email: two@example.org + +admin: + type: Admin + email: admin@example.org diff --git a/test/notifier_test.rb b/test/notifier_test.rb index 30f409ac..84e3e498 100644 --- a/test/notifier_test.rb +++ b/test/notifier_test.rb @@ -56,6 +56,16 @@ class NotifierTest < ActiveSupport::TestCase end end + test "deliver to STI recipient writes base class" do + admin = Admin.first + assert_difference "Noticed::Notification.count" do + ReceiptNotifier.deliver(admin) + end + notification = Noticed::Notification.last + assert_equal "User", notification.recipient_type + assert_equal admin, notification.recipient + end + test "creates jobs for deliveries" do # Delivering a notification creates records assert_enqueued_jobs 1, only: Noticed::EventJob do