aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test
diff options
context:
space:
mode:
authorGannon McGibbon <gannon.mcgibbon@gmail.com>2018-11-01 16:32:01 -0400
committerGannon McGibbon <gannon.mcgibbon@gmail.com>2018-11-22 18:37:53 -0500
commit60339da5bcb76489576321fa12e665f176d8d692 (patch)
tree882f3a076f9211924a9f4020e7d1729e1ab66543 /actionmailer/test
parent548bd509857ca5bba300915aa5ad9bff6e8c0238 (diff)
downloadrails-60339da5bcb76489576321fa12e665f176d8d692.tar.gz
rails-60339da5bcb76489576321fa12e665f176d8d692.tar.bz2
rails-60339da5bcb76489576321fa12e665f176d8d692.zip
Deliver parameterized mail with DeliveryJob
Deliver parameterized mail with `ActionMailer::DeliveryJob` and remove `ActionMailer::Parameterized::DeliveryJob`.
Diffstat (limited to 'actionmailer/test')
-rw-r--r--actionmailer/test/message_delivery_test.rb14
-rw-r--r--actionmailer/test/parameterized_test.rb38
-rw-r--r--actionmailer/test/test_helper_test.rb4
3 files changed, 36 insertions, 20 deletions
diff --git a/actionmailer/test/message_delivery_test.rb b/actionmailer/test/message_delivery_test.rb
index f8dcb3f4ba..8d5c473faf 100644
--- a/actionmailer/test/message_delivery_test.rb
+++ b/actionmailer/test/message_delivery_test.rb
@@ -64,20 +64,20 @@ class MessageDeliveryTest < ActiveSupport::TestCase
end
test "should enqueue the email with :deliver_now delivery method" do
- assert_performed_with(job: ActionMailer::DeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now", 1, 2, 3]) do
+ assert_performed_with(job: ActionMailer::DeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now", nil, 1, 2, 3]) do
@mail.deliver_later
end
end
test "should enqueue the email with :deliver_now! delivery method" do
- assert_performed_with(job: ActionMailer::DeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now!", 1, 2, 3]) do
+ assert_performed_with(job: ActionMailer::DeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now!", nil, 1, 2, 3]) do
@mail.deliver_later!
end
end
test "should enqueue a delivery with a delay" do
travel_to Time.new(2004, 11, 24, 01, 04, 44) do
- assert_performed_with(job: ActionMailer::DeliveryJob, at: Time.current + 10.minutes, args: ["DelayedMailer", "test_message", "deliver_now", 1, 2, 3]) do
+ assert_performed_with(job: ActionMailer::DeliveryJob, at: Time.current + 10.minutes, args: ["DelayedMailer", "test_message", "deliver_now", nil, 1, 2, 3]) do
@mail.deliver_later wait: 10.minutes
end
end
@@ -85,13 +85,13 @@ class MessageDeliveryTest < ActiveSupport::TestCase
test "should enqueue a delivery at a specific time" do
later_time = Time.current + 1.hour
- assert_performed_with(job: ActionMailer::DeliveryJob, at: later_time, args: ["DelayedMailer", "test_message", "deliver_now", 1, 2, 3]) do
+ assert_performed_with(job: ActionMailer::DeliveryJob, at: later_time, args: ["DelayedMailer", "test_message", "deliver_now", nil, 1, 2, 3]) do
@mail.deliver_later wait_until: later_time
end
end
test "should enqueue the job on the correct queue" do
- assert_performed_with(job: ActionMailer::DeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now", 1, 2, 3], queue: "test_queue") do
+ assert_performed_with(job: ActionMailer::DeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now", nil, 1, 2, 3], queue: "test_queue") do
@mail.deliver_later
end
end
@@ -100,7 +100,7 @@ class MessageDeliveryTest < ActiveSupport::TestCase
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
+ assert_performed_with(job: DummyJob, args: ["DelayedMailer", "test_message", "deliver_now", nil, 1, 2, 3]) do
@mail.deliver_later
end
@@ -110,7 +110,7 @@ class MessageDeliveryTest < ActiveSupport::TestCase
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
+ assert_performed_with(job: ActionMailer::DeliveryJob, args: ["DelayedMailer", "test_message", "deliver_now", nil, 1, 2, 3], queue: "another_queue") do
@mail.deliver_later(queue: :another_queue)
end
end
diff --git a/actionmailer/test/parameterized_test.rb b/actionmailer/test/parameterized_test.rb
index d3b34fc3e3..3713dc3e3e 100644
--- a/actionmailer/test/parameterized_test.rb
+++ b/actionmailer/test/parameterized_test.rb
@@ -7,6 +7,9 @@ require "mailers/params_mailer"
class ParameterizedTest < ActiveSupport::TestCase
include ActiveJob::TestHelper
+ class DummyDeliveryJob < ActionMailer::DeliveryJob
+ end
+
setup do
@previous_logger = ActiveJob::Base.logger
ActiveJob::Base.logger = Logger.new(nil)
@@ -35,7 +38,13 @@ class ParameterizedTest < ActiveSupport::TestCase
end
test "enqueue the email with params" do
- assert_performed_with(job: ActionMailer::Parameterized::DeliveryJob, args: ["ParamsMailer", "invitation", "deliver_now", { inviter: "david@basecamp.com", invitee: "jason@basecamp.com" } ]) do
+ args = [
+ "ParamsMailer",
+ "invitation",
+ "deliver_now",
+ { inviter: "david@basecamp.com", invitee: "jason@basecamp.com" },
+ ]
+ assert_performed_with(job: ActionMailer::DeliveryJob, args: args) do
@mail.deliver_later
end
end
@@ -55,15 +64,26 @@ class ParameterizedTest < ActiveSupport::TestCase
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
+ args = [
+ "ParamsMailer",
+ "invitation",
+ "deliver_now",
+ { inviter: "david@basecamp.com", invitee: "jason@basecamp.com" },
+ ]
+
+ with_delivery_job DummyDeliveryJob do
+ assert_performed_with(job: DummyDeliveryJob, args: args) do
+ @mail.deliver_later
+ end
end
-
- ParamsMailer.parameterized_delivery_job = old_delivery_job
end
- class ParameterizedDummyJob < ActionMailer::Parameterized::DeliveryJob; end
+ private
+
+ def with_delivery_job(job)
+ old_delivery_job = ParamsMailer.delivery_job
+ ParamsMailer.delivery_job = job
+ ensure
+ ParamsMailer.delivery_job = old_delivery_job
+ end
end
diff --git a/actionmailer/test/test_helper_test.rb b/actionmailer/test/test_helper_test.rb
index c700db9408..4e21ab0a69 100644
--- a/actionmailer/test/test_helper_test.rb
+++ b/actionmailer/test/test_helper_test.rb
@@ -27,12 +27,8 @@ end
class CustomDeliveryJob < ActionMailer::DeliveryJob
end
-class CustomParameterizedDeliveryJob < ActionMailer::Parameterized::DeliveryJob
-end
-
class CustomDeliveryMailer < TestHelperMailer
self.delivery_job = CustomDeliveryJob
- self.parameterized_delivery_job = CustomParameterizedDeliveryJob
end
class TestHelperMailerTest < ActionMailer::TestCase