Skip to content

Commit

Permalink
Merge branch 'alikrugl-recipient-type-should-be-set-to-base-class'
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Jan 24, 2024
2 parents f529df0 + a622724 commit de372f0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/noticed/deliverable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/app/models/admin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Admin < User
end
1 change: 1 addition & 0 deletions test/dummy/db/migrate/20231215202921_create_users.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ one:

two:
email: [email protected]

admin:
type: Admin
email: [email protected]
10 changes: 10 additions & 0 deletions test/notifier_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit de372f0

Please sign in to comment.