aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer
diff options
context:
space:
mode:
authorLuke Pearce <30228+kule@users.noreply.github.com>2018-10-05 16:53:28 +0100
committerLuke Pearce <30228+kule@users.noreply.github.com>2018-10-05 17:02:40 +0100
commitc90c6c1344e62d5705f92efc323016a83a1e7351 (patch)
tree9c268caf151cee8ba4154c94d85fa542bb70ddd0 /actionmailer
parent0d4b2e4da6532b07d6321eb158a62ef3924917da (diff)
downloadrails-c90c6c1344e62d5705f92efc323016a83a1e7351.tar.gz
rails-c90c6c1344e62d5705f92efc323016a83a1e7351.tar.bz2
rails-c90c6c1344e62d5705f92efc323016a83a1e7351.zip
Parameterized mailers can configure delivery job
Setting parameterized_delivery_job on a mailer class will cause Parameterized::MessageDelivery to use the specified job instead of ActionMailer::Parameterized::DeliveryJob: class MyMailer < ApplicationMailer self.parameterized_delivery_job = MyCustomDeliveryJob ... end
Diffstat (limited to 'actionmailer')
-rw-r--r--actionmailer/CHANGELOG.md11
-rw-r--r--actionmailer/lib/action_mailer/base.rb1
-rw-r--r--actionmailer/lib/action_mailer/parameterized.rb3
-rw-r--r--actionmailer/test/parameterized_test.rb13
4 files changed, 27 insertions, 1 deletions
diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md
index 1aa7485d3e..db6fc7ee9c 100644
--- a/actionmailer/CHANGELOG.md
+++ b/actionmailer/CHANGELOG.md
@@ -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*
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 02e5ac2a3e..509d859ac3 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -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",
diff --git a/actionmailer/lib/action_mailer/parameterized.rb b/actionmailer/lib/action_mailer/parameterized.rb
index 5e768e7106..0fe417affe 100644
--- a/actionmailer/lib/action_mailer/parameterized.rb
+++ b/actionmailer/lib/action_mailer/parameterized.rb
@@ -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
diff --git a/actionmailer/test/parameterized_test.rb b/actionmailer/test/parameterized_test.rb
index ec6c5e9e67..d3b34fc3e3 100644
--- a/actionmailer/test/parameterized_test.rb
+++ b/actionmailer/test/parameterized_test.rb
@@ -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