Permalink
Browse files

Merge pull request #29457 from halogenandtoast/mm-configure_delivery_job

Allow mailers to configure their delivery job
  • Loading branch information...
guilleiguaran committed Jun 15, 2017
2 parents d9496c1 + d9bbde0 commit 95ae033e7f6747fa7a65c74c66922c8d9fe66808
View
@@ -1 +1,11 @@
* Allow ActionMailer classes to configure their delivery job
class MyMailer < ApplicationMailer
self.delivery_job = MyCustomDeliveryJob
...
end
*Matthew Mongeau*
Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/actionmailer/CHANGELOG.md) for previous changes.
@@ -459,6 +459,7 @@ def _protected_ivars # :nodoc:
helper ActionMailer::MailHelper
class_attribute :delivery_job, default: ::ActionMailer::DeliveryJob
class_attribute :default_params, default: {
mime_version: "1.0",
charset: "UTF-8",
@@ -118,7 +118,8 @@ def enqueue_delivery(delivery_method, options = {})
"method*, or 3. use a custom Active Job instead of #deliver_later."
else
args = @mailer_class.name, @action.to_s, delivery_method.to_s, *@args
::ActionMailer::DeliveryJob.set(options).perform_later(*args)
job = @mailer_class.delivery_job
job.set(options).perform_later(*args)
end
end
end
@@ -95,6 +95,19 @@ def test_should_enqueue_and_run_correctly_in_activejob
end
end
test "should enqueue the job with the correct delivery job" do
old_delivery_job = DelayedMailer.delivery_job
DelayedMailer.delivery_job = DummyJob
assert_performed_with(job: DummyJob, args: ["DelayedMailer", "test_message", "deliver_now", 1, 2, 3]) do
@mail.deliver_later
end
DelayedMailer.delivery_job = old_delivery_job
end
class DummyJob < ActionMailer::DeliveryJob; end
test "can override the queue when enqueuing mail" do
assert_performed_with(job: ActionMailer::DeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now", 1, 2, 3], queue: "another_queue") do
@mail.deliver_later(queue: :another_queue)

0 comments on commit 95ae033

Please sign in to comment.