aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer
diff options
context:
space:
mode:
Diffstat (limited to 'actionmailer')
-rw-r--r--actionmailer/lib/action_mailer/message_delivery.rb24
-rw-r--r--actionmailer/test/assert_select_email_test.rb4
-rw-r--r--actionmailer/test/base_test.rb36
-rw-r--r--actionmailer/test/delivery_methods_test.rb24
-rw-r--r--actionmailer/test/i18n_with_controller_test.rb2
-rw-r--r--actionmailer/test/log_subscriber_test.rb2
-rw-r--r--actionmailer/test/message_delivery_test.rb29
-rw-r--r--actionmailer/test/test_helper_test.rb22
-rw-r--r--actionmailer/test/url_test.rb2
9 files changed, 92 insertions, 53 deletions
diff --git a/actionmailer/lib/action_mailer/message_delivery.rb b/actionmailer/lib/action_mailer/message_delivery.rb
index 80a0517bff..8136483725 100644
--- a/actionmailer/lib/action_mailer/message_delivery.rb
+++ b/actionmailer/lib/action_mailer/message_delivery.rb
@@ -21,11 +21,31 @@ module ActionMailer
end
def deliver_later!(options={})
- enqueue_delivery :deliver!, options
+ enqueue_delivery :deliver_now!, options
end
def deliver_later(options={})
- enqueue_delivery :deliver, options
+ enqueue_delivery :deliver_now, options
+ end
+
+ def deliver_now!
+ message.deliver!
+ end
+
+ def deliver_now
+ message.deliver
+ end
+
+ def deliver!
+ ActiveSupport::Deprecation.warn "#deliver! is deprecated and will be removed on Rails 5. " \
+ "Use #deliver_now! to deliver immediately or #deliver_later! to deliver through ActiveJob"
+ deliver_now!
+ end
+
+ def deliver
+ ActiveSupport::Deprecation.warn "#deliver is deprecated and will be removed on Rails 5. " \
+ "Use #deliver_now to deliver immediately or #deliver_later to deliver through ActiveJob"
+ deliver_now
end
private
diff --git a/actionmailer/test/assert_select_email_test.rb b/actionmailer/test/assert_select_email_test.rb
index 57ae3436e1..cae2e20abd 100644
--- a/actionmailer/test/assert_select_email_test.rb
+++ b/actionmailer/test/assert_select_email_test.rb
@@ -26,7 +26,7 @@ class AssertSelectEmailTest < ActionMailer::TestCase
assert_select_email {}
end
- AssertSelectMailer.test("<div><p>foo</p><p>bar</p></div>").deliver
+ AssertSelectMailer.test("<div><p>foo</p><p>bar</p></div>").deliver_now
assert_select_email do
assert_select "div:root" do
assert_select "p:first-child", "foo"
@@ -36,7 +36,7 @@ class AssertSelectEmailTest < ActionMailer::TestCase
end
def test_assert_select_email_multipart
- AssertMultipartSelectMailer.test(html: "<div><p>foo</p><p>bar</p></div>", text: 'foo bar').deliver
+ AssertMultipartSelectMailer.test(html: "<div><p>foo</p><p>bar</p></div>", text: 'foo bar').deliver_now
assert_select_email do
assert_select "div:root" do
assert_select "p:first-child", "foo"
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index fc24639bf4..d00f5aea47 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -466,12 +466,12 @@ class BaseTest < ActiveSupport::TestCase
test "calling deliver on the action should deliver the mail object" do
BaseMailer.expects(:deliver_mail).once
- mail = BaseMailer.welcome.deliver
+ mail = BaseMailer.welcome.deliver_now
assert_equal 'The first email on new API!', mail.subject
end
test "calling deliver on the action should increment the deliveries collection if using the test mailer" do
- BaseMailer.welcome.deliver
+ BaseMailer.welcome.deliver_now
assert_equal(1, BaseMailer.deliveries.length)
end
@@ -484,35 +484,35 @@ class BaseTest < ActiveSupport::TestCase
# Rendering
test "you can specify a different template for implicit render" do
- mail = BaseMailer.implicit_different_template('implicit_multipart').deliver
+ mail = BaseMailer.implicit_different_template('implicit_multipart').deliver_now
assert_equal("HTML Implicit Multipart", mail.html_part.body.decoded)
assert_equal("TEXT Implicit Multipart", mail.text_part.body.decoded)
end
test "should raise if missing template in implicit render" do
assert_raises ActionView::MissingTemplate do
- BaseMailer.implicit_different_template('missing_template').deliver
+ BaseMailer.implicit_different_template('missing_template').deliver_now
end
assert_equal(0, BaseMailer.deliveries.length)
end
test "you can specify a different template for explicit render" do
- mail = BaseMailer.explicit_different_template('explicit_multipart_templates').deliver
+ mail = BaseMailer.explicit_different_template('explicit_multipart_templates').deliver_now
assert_equal("HTML Explicit Multipart Templates", mail.html_part.body.decoded)
assert_equal("TEXT Explicit Multipart Templates", mail.text_part.body.decoded)
end
test "you can specify a different layout" do
- mail = BaseMailer.different_layout('different_layout').deliver
+ mail = BaseMailer.different_layout('different_layout').deliver_now
assert_equal("HTML -- HTML", mail.html_part.body.decoded)
assert_equal("PLAIN -- PLAIN", mail.text_part.body.decoded)
end
test "you can specify the template path for implicit lookup" do
- mail = BaseMailer.welcome_from_another_path('another.path/base_mailer').deliver
+ mail = BaseMailer.welcome_from_another_path('another.path/base_mailer').deliver_now
assert_equal("Welcome from another path", mail.body.encoded)
- mail = BaseMailer.welcome_from_another_path(['unknown/invalid', 'another.path/base_mailer']).deliver
+ mail = BaseMailer.welcome_from_another_path(['unknown/invalid', 'another.path/base_mailer']).deliver_now
assert_equal("Welcome from another path", mail.body.encoded)
end
@@ -542,13 +542,13 @@ class BaseTest < ActiveSupport::TestCase
test 'the view is not rendered when mail was never called' do
mail = BaseMailer.without_mail_call
assert_equal('', mail.body.to_s.strip)
- mail.deliver
+ mail.deliver_now
end
test 'the return value of mailer methods is not relevant' do
mail = BaseMailer.with_nil_as_return_value
assert_equal('Welcome', mail.body.to_s.strip)
- mail.deliver
+ mail.deliver_now
end
# Before and After hooks
@@ -568,7 +568,7 @@ class BaseTest < ActiveSupport::TestCase
ActionMailer::Base.register_observer(MyObserver)
mail = BaseMailer.welcome
MyObserver.expects(:delivered_email).with(mail)
- mail.deliver
+ mail.deliver_now
end
end
@@ -577,7 +577,7 @@ class BaseTest < ActiveSupport::TestCase
ActionMailer::Base.register_observer("BaseTest::MyObserver")
mail = BaseMailer.welcome
MyObserver.expects(:delivered_email).with(mail)
- mail.deliver
+ mail.deliver_now
end
end
@@ -586,7 +586,7 @@ class BaseTest < ActiveSupport::TestCase
ActionMailer::Base.register_observer(:"base_test/my_observer")
mail = BaseMailer.welcome
MyObserver.expects(:delivered_email).with(mail)
- mail.deliver
+ mail.deliver_now
end
end
@@ -596,7 +596,7 @@ class BaseTest < ActiveSupport::TestCase
mail = BaseMailer.welcome
MyObserver.expects(:delivered_email).with(mail)
MySecondObserver.expects(:delivered_email).with(mail)
- mail.deliver
+ mail.deliver_now
end
end
@@ -615,7 +615,7 @@ class BaseTest < ActiveSupport::TestCase
ActionMailer::Base.register_interceptor(MyInterceptor)
mail = BaseMailer.welcome
MyInterceptor.expects(:delivering_email).with(mail)
- mail.deliver
+ mail.deliver_now
end
end
@@ -624,7 +624,7 @@ class BaseTest < ActiveSupport::TestCase
ActionMailer::Base.register_interceptor("BaseTest::MyInterceptor")
mail = BaseMailer.welcome
MyInterceptor.expects(:delivering_email).with(mail)
- mail.deliver
+ mail.deliver_now
end
end
@@ -633,7 +633,7 @@ class BaseTest < ActiveSupport::TestCase
ActionMailer::Base.register_interceptor(:"base_test/my_interceptor")
mail = BaseMailer.welcome
MyInterceptor.expects(:delivering_email).with(mail)
- mail.deliver
+ mail.deliver_now
end
end
@@ -643,7 +643,7 @@ class BaseTest < ActiveSupport::TestCase
mail = BaseMailer.welcome
MyInterceptor.expects(:delivering_email).with(mail)
MySecondInterceptor.expects(:delivering_email).with(mail)
- mail.deliver
+ mail.deliver_now
end
end
diff --git a/actionmailer/test/delivery_methods_test.rb b/actionmailer/test/delivery_methods_test.rb
index a76ac6d295..2e4e019bf7 100644
--- a/actionmailer/test/delivery_methods_test.rb
+++ b/actionmailer/test/delivery_methods_test.rb
@@ -104,21 +104,21 @@ class MailDeliveryTest < ActiveSupport::TestCase
test "ActionMailer should be told when Mail gets delivered" do
DeliveryMailer.expects(:deliver_mail).once
- DeliveryMailer.welcome.deliver
+ DeliveryMailer.welcome.deliver_now
end
test "delivery method can be customized per instance" do
Mail::SMTP.any_instance.expects(:deliver!)
- email = DeliveryMailer.welcome.deliver
+ email = DeliveryMailer.welcome.deliver_now
assert_instance_of Mail::SMTP, email.delivery_method
- email = DeliveryMailer.welcome(delivery_method: :test).deliver
+ email = DeliveryMailer.welcome(delivery_method: :test).deliver_now
assert_instance_of Mail::TestMailer, email.delivery_method
end
test "delivery method can be customized in subclasses not changing the parent" do
DeliveryMailer.delivery_method = :test
assert_equal :smtp, ActionMailer::Base.delivery_method
- email = DeliveryMailer.welcome.deliver
+ email = DeliveryMailer.welcome.deliver_now
assert_instance_of Mail::TestMailer, email.delivery_method
end
@@ -162,14 +162,14 @@ class MailDeliveryTest < ActiveSupport::TestCase
test "non registered delivery methods raises errors" do
DeliveryMailer.delivery_method = :unknown
assert_raise RuntimeError do
- DeliveryMailer.welcome.deliver
+ DeliveryMailer.welcome.deliver_now
end
end
test "undefined delivery methods raises errors" do
DeliveryMailer.delivery_method = nil
assert_raise RuntimeError do
- DeliveryMailer.welcome.deliver
+ DeliveryMailer.welcome.deliver_now
end
end
@@ -178,7 +178,7 @@ class MailDeliveryTest < ActiveSupport::TestCase
begin
DeliveryMailer.perform_deliveries = false
Mail::Message.any_instance.expects(:deliver!).never
- DeliveryMailer.welcome.deliver
+ DeliveryMailer.welcome.deliver_now
ensure
DeliveryMailer.perform_deliveries = old_perform_deliveries
end
@@ -188,7 +188,7 @@ class MailDeliveryTest < ActiveSupport::TestCase
old_perform_deliveries = DeliveryMailer.perform_deliveries
begin
DeliveryMailer.perform_deliveries = false
- DeliveryMailer.welcome.deliver
+ DeliveryMailer.welcome.deliver_now
assert_equal [], DeliveryMailer.deliveries
ensure
DeliveryMailer.perform_deliveries = old_perform_deliveries
@@ -198,14 +198,14 @@ class MailDeliveryTest < ActiveSupport::TestCase
test "raise errors on bogus deliveries" do
DeliveryMailer.delivery_method = BogusDelivery
assert_raise RuntimeError do
- DeliveryMailer.welcome.deliver
+ DeliveryMailer.welcome.deliver_now
end
end
test "does not increment the deliveries collection on error" do
DeliveryMailer.delivery_method = BogusDelivery
assert_raise RuntimeError do
- DeliveryMailer.welcome.deliver
+ DeliveryMailer.welcome.deliver_now
end
assert_equal [], DeliveryMailer.deliveries
end
@@ -216,7 +216,7 @@ class MailDeliveryTest < ActiveSupport::TestCase
DeliveryMailer.delivery_method = BogusDelivery
DeliveryMailer.raise_delivery_errors = false
assert_nothing_raised do
- DeliveryMailer.welcome.deliver
+ DeliveryMailer.welcome.deliver_now
end
ensure
DeliveryMailer.raise_delivery_errors = old_raise_delivery_errors
@@ -228,7 +228,7 @@ class MailDeliveryTest < ActiveSupport::TestCase
begin
DeliveryMailer.delivery_method = BogusDelivery
DeliveryMailer.raise_delivery_errors = false
- DeliveryMailer.welcome.deliver
+ DeliveryMailer.welcome.deliver_now
assert_equal [], DeliveryMailer.deliveries
ensure
DeliveryMailer.raise_delivery_errors = old_raise_delivery_errors
diff --git a/actionmailer/test/i18n_with_controller_test.rb b/actionmailer/test/i18n_with_controller_test.rb
index ee36b89dd6..010e44d045 100644
--- a/actionmailer/test/i18n_with_controller_test.rb
+++ b/actionmailer/test/i18n_with_controller_test.rb
@@ -17,7 +17,7 @@ end
class TestController < ActionController::Base
def send_mail
- email = I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver
+ email = I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver_now
render text: "Mail sent - Subject: #{email.subject}"
end
end
diff --git a/actionmailer/test/log_subscriber_test.rb b/actionmailer/test/log_subscriber_test.rb
index e7a73d6c8e..3871b16840 100644
--- a/actionmailer/test/log_subscriber_test.rb
+++ b/actionmailer/test/log_subscriber_test.rb
@@ -22,7 +22,7 @@ class AMLogSubscriberTest < ActionMailer::TestCase
end
def test_deliver_is_notified
- BaseMailer.welcome.deliver
+ BaseMailer.welcome.deliver_now
wait
assert_equal(1, @logger.logged(:info).size)
diff --git a/actionmailer/test/message_delivery_test.rb b/actionmailer/test/message_delivery_test.rb
index 1c7406b520..49b63d7675 100644
--- a/actionmailer/test/message_delivery_test.rb
+++ b/actionmailer/test/message_delivery_test.rb
@@ -37,6 +37,17 @@ class MessageDeliveryTest < ActiveSupport::TestCase
assert_respond_to @mail, :deliver!
end
+ test '.deliver is deprecated' do
+ assert_deprecated do
+ @mail.deliver
+ end
+ end
+ test '.deliver! is deprecated' do
+ assert_deprecated do
+ @mail.deliver!
+ end
+ end
+
test 'should respond to .deliver_later' do
assert_respond_to @mail, :deliver_later
end
@@ -45,7 +56,15 @@ class MessageDeliveryTest < ActiveSupport::TestCase
assert_respond_to @mail, :deliver_later!
end
- def test_should_enqueue_and_run_correctly_in_activejob
+ test 'should respond to .deliver_now' do
+ assert_respond_to @mail, :deliver_now
+ end
+
+ test 'should respond to .deliver_now!' do
+ assert_respond_to @mail, :deliver_now!
+ end
+
+ test 'should enqueue and run correctly in activejob' do
@mail.deliver_later!
assert_equal 1, ActionMailer::Base.deliveries.size
ensure
@@ -56,21 +75,21 @@ class MessageDeliveryTest < ActiveSupport::TestCase
ret = ActionMailer::DeliveryJob.stub :enqueue, ->(*args){ args } do
@mail.deliver_later
end
- assert_equal ['DelayedMailer', 'test_message', 'deliver', 1, 2, 3], ret
+ assert_equal ['DelayedMailer', 'test_message', 'deliver_now', 1, 2, 3], ret
end
test 'should enqueue the email with :deliver! delivery method' do
ret = ActionMailer::DeliveryJob.stub :enqueue, ->(*args){ args } do
@mail.deliver_later!
end
- assert_equal ['DelayedMailer', 'test_message', 'deliver!', 1, 2, 3], ret
+ assert_equal ['DelayedMailer', 'test_message', 'deliver_now!', 1, 2, 3], ret
end
test 'should enqueue a delivery with a delay' do
ret = ActionMailer::DeliveryJob.stub :enqueue_in, ->(*args){ args } do
@mail.deliver_later in: 600
end
- assert_equal [600, 'DelayedMailer', 'test_message', 'deliver', 1, 2, 3], ret
+ assert_equal [600, 'DelayedMailer', 'test_message', 'deliver_now', 1, 2, 3], ret
end
test 'should enqueue a delivery at a specific time' do
@@ -78,7 +97,7 @@ class MessageDeliveryTest < ActiveSupport::TestCase
ret = ActionMailer::DeliveryJob.stub :enqueue_at, ->(*args){ args } do
@mail.deliver_later at: later_time
end
- assert_equal [later_time, 'DelayedMailer', 'test_message', 'deliver', 1, 2, 3], ret
+ assert_equal [later_time, 'DelayedMailer', 'test_message', 'deliver_now', 1, 2, 3], ret
end
end
diff --git a/actionmailer/test/test_helper_test.rb b/actionmailer/test/test_helper_test.rb
index 1ff08a3b6e..96b75ff2e0 100644
--- a/actionmailer/test/test_helper_test.rb
+++ b/actionmailer/test/test_helper_test.rb
@@ -48,7 +48,7 @@ class TestHelperMailerTest < ActionMailer::TestCase
def test_assert_emails
assert_nothing_raised do
assert_emails 1 do
- TestHelperMailer.test.deliver
+ TestHelperMailer.test.deliver_now
end
end
end
@@ -56,27 +56,27 @@ class TestHelperMailerTest < ActionMailer::TestCase
def test_repeated_assert_emails_calls
assert_nothing_raised do
assert_emails 1 do
- TestHelperMailer.test.deliver
+ TestHelperMailer.test.deliver_now
end
end
assert_nothing_raised do
assert_emails 2 do
- TestHelperMailer.test.deliver
- TestHelperMailer.test.deliver
+ TestHelperMailer.test.deliver_now
+ TestHelperMailer.test.deliver_now
end
end
end
def test_assert_emails_with_no_block
assert_nothing_raised do
- TestHelperMailer.test.deliver
+ TestHelperMailer.test.deliver_now
assert_emails 1
end
assert_nothing_raised do
- TestHelperMailer.test.deliver
- TestHelperMailer.test.deliver
+ TestHelperMailer.test.deliver_now
+ TestHelperMailer.test.deliver_now
assert_emails 3
end
end
@@ -92,7 +92,7 @@ class TestHelperMailerTest < ActionMailer::TestCase
def test_assert_emails_too_few_sent
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_emails 2 do
- TestHelperMailer.test.deliver
+ TestHelperMailer.test.deliver_now
end
end
@@ -102,8 +102,8 @@ class TestHelperMailerTest < ActionMailer::TestCase
def test_assert_emails_too_many_sent
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_emails 1 do
- TestHelperMailer.test.deliver
- TestHelperMailer.test.deliver
+ TestHelperMailer.test.deliver_now
+ TestHelperMailer.test.deliver_now
end
end
@@ -113,7 +113,7 @@ class TestHelperMailerTest < ActionMailer::TestCase
def test_assert_no_emails_failure
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_no_emails do
- TestHelperMailer.test.deliver
+ TestHelperMailer.test.deliver_now
end
end
diff --git a/actionmailer/test/url_test.rb b/actionmailer/test/url_test.rb
index 589944fa69..e79b2ca978 100644
--- a/actionmailer/test/url_test.rb
+++ b/actionmailer/test/url_test.rb
@@ -68,7 +68,7 @@ class ActionMailerUrlTest < ActionMailer::TestCase
created.message_id = '<123@456>'
assert_equal expected.encoded, created.encoded
- assert_nothing_raised { UrlTestMailer.signed_up_with_url(@recipient).deliver }
+ assert_nothing_raised { UrlTestMailer.signed_up_with_url(@recipient).deliver_now }
assert_not_nil ActionMailer::Base.deliveries.first
delivered = ActionMailer::Base.deliveries.first