mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #34097 from kule/master
Parameterized mailers can configure delivery job
This commit is contained in:
commit
251b9d4bd6
4 changed files with 27 additions and 1 deletions
|
@ -1,3 +1,14 @@
|
|||
* Allow ActionMailer classes to configure the parameterized delivery job
|
||||
Example:
|
||||
```
|
||||
class MyMailer < ApplicationMailer
|
||||
self.parameterized_delivery_job = MyCustomDeliveryJob
|
||||
...
|
||||
end
|
||||
```
|
||||
|
||||
*Luke Pearce*
|
||||
|
||||
* `ActionDispatch::IntegrationTest` includes `ActionMailer::TestHelper` module by default.
|
||||
|
||||
*Ricardo Díaz*
|
||||
|
|
|
@ -462,6 +462,7 @@ module ActionMailer
|
|||
helper ActionMailer::MailHelper
|
||||
|
||||
class_attribute :delivery_job, default: ::ActionMailer::DeliveryJob
|
||||
class_attribute :parameterized_delivery_job, default: ::ActionMailer::Parameterized::DeliveryJob
|
||||
class_attribute :default_params, default: {
|
||||
mime_version: "1.0",
|
||||
charset: "UTF-8",
|
||||
|
|
|
@ -140,7 +140,8 @@ module ActionMailer
|
|||
super
|
||||
else
|
||||
args = @mailer_class.name, @action.to_s, delivery_method.to_s, @params, *@args
|
||||
ActionMailer::Parameterized::DeliveryJob.set(options).perform_later(*args)
|
||||
job = @mailer_class.parameterized_delivery_job
|
||||
job.set(options).perform_later(*args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -53,4 +53,17 @@ class ParameterizedTest < ActiveSupport::TestCase
|
|||
invitation = mailer.method(:anything)
|
||||
end
|
||||
end
|
||||
|
||||
test "should enqueue a parameterized request with the correct delivery job" do
|
||||
old_delivery_job = ParamsMailer.parameterized_delivery_job
|
||||
ParamsMailer.parameterized_delivery_job = ParameterizedDummyJob
|
||||
|
||||
assert_performed_with(job: ParameterizedDummyJob, args: ["ParamsMailer", "invitation", "deliver_now", { inviter: "david@basecamp.com", invitee: "jason@basecamp.com" } ]) do
|
||||
@mail.deliver_later
|
||||
end
|
||||
|
||||
ParamsMailer.parameterized_delivery_job = old_delivery_job
|
||||
end
|
||||
|
||||
class ParameterizedDummyJob < ActionMailer::Parameterized::DeliveryJob; end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue