diff options
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/CHANGELOG.md | 10 | ||||
-rw-r--r-- | actionmailer/README.rdoc | 6 | ||||
-rw-r--r-- | actionmailer/actionmailer.gemspec | 1 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 21 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/delivery_job.rb | 4 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/message_delivery.rb | 101 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/railtie.rb | 1 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/test_helper.rb | 12 | ||||
-rw-r--r-- | actionmailer/test/abstract_unit.rb | 9 | ||||
-rw-r--r-- | actionmailer/test/assert_select_email_test.rb | 4 | ||||
-rw-r--r-- | actionmailer/test/asset_host_test.rb | 5 | ||||
-rw-r--r-- | actionmailer/test/base_test.rb | 36 | ||||
-rw-r--r-- | actionmailer/test/delivery_methods_test.rb | 24 | ||||
-rw-r--r-- | actionmailer/test/i18n_with_controller_test.rb | 2 | ||||
-rw-r--r-- | actionmailer/test/log_subscriber_test.rb | 2 | ||||
-rw-r--r-- | actionmailer/test/message_delivery_test.rb | 38 | ||||
-rw-r--r-- | actionmailer/test/test_helper_test.rb | 22 | ||||
-rw-r--r-- | actionmailer/test/url_test.rb | 2 |
18 files changed, 195 insertions, 105 deletions
diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md index a4923de045..1ff4db41a3 100644 --- a/actionmailer/CHANGELOG.md +++ b/actionmailer/CHANGELOG.md @@ -1,7 +1,9 @@ -* Added #deliver_later in addition to #deliver, which will enqueue a job to render and - deliver the mail instead of delivering it right at that moment. The job is enqueued - using the new Active Job framework in Rails, and will use whatever queue is configured for Rails. - +* Added #deliver_later, #deliver_now and deprecate #deliver in favour of + #deliver_now. #deliver_later will enqueue a job to render and deliver + the mail instead of delivering it right at that moment. The job is enqueued + using the new Active Job framework in Rails, and will use whatever queue is + configured for Rails. + *DHH/Abdelkader Boudih/Cristian Bica* * Make ActionMailer::Previews methods class methods. Previously they were diff --git a/actionmailer/README.rdoc b/actionmailer/README.rdoc index ceca912ada..3b8e3ed749 100644 --- a/actionmailer/README.rdoc +++ b/actionmailer/README.rdoc @@ -65,12 +65,12 @@ In order to send mails, you simply call the method and then call +deliver+ on th Calling the method returns a Mail Message object: - message = Notifier.welcome("david@loudthinking.com") # => Returns a Mail::Message object - message.deliver # => delivers the email + message = Notifier.welcome("david@loudthinking.com") # => Returns a Mail::Message object + message.deliver_now # => delivers the email Or you can just chain the methods together like: - Notifier.welcome("david@loudthinking.com").deliver # Creates the email and sends it immediately + Notifier.welcome("david@loudthinking.com").deliver_now # Creates the email and sends it immediately == Setting defaults diff --git a/actionmailer/actionmailer.gemspec b/actionmailer/actionmailer.gemspec index bc72c20d87..089e12ebf1 100644 --- a/actionmailer/actionmailer.gemspec +++ b/actionmailer/actionmailer.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |s| s.add_dependency 'actionpack', version s.add_dependency 'actionview', version + s.add_dependency 'activejob', version s.add_dependency 'mail', ['~> 2.5', '>= 2.5.4'] s.add_dependency 'rails-dom-testing', '~> 1.0', '>= 1.0.2' diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 9aae14ec8c..f539fc53c6 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -138,9 +138,20 @@ module ActionMailer # Once a mailer action and template are defined, you can deliver your message or create it and save it # for delivery later: # - # Notifier.welcome(david).deliver # sends the email - # mail = Notifier.welcome(david) # => a Mail::Message object - # mail.deliver # sends the email + # Notifier.welcome(User.first).deliver_now # sends the email + # mail = Notifier.welcome(User.first) # => an ActionMailer::MessageDelivery object + # mail.deliver_now # sends the email + # + # The <tt>ActionMailer::MessageDelivery</tt> class is a wrapper around a <tt>Mail::Message</tt> object. If + # you want direct access to the <tt>Mail::Message</tt> object you can call the <tt>message</tt> method on + # the <tt>ActionMailer::MessageDelivery</tt> object. + # + # Notifier.welcome(User.first).message # => a Mail::Message object + # + # Action Mailer is nicely integrated with Active Job so you can send emails in the background (example: outside + # of the request-response cycle, so the user doesn't have to wait on it): + # + # Notifier.welcome(User.first).deliver_later # enqueue the email sending to Active Job # # You never instantiate your mailer class. Rather, you just call the method you defined on the class itself. # @@ -322,8 +333,8 @@ module ActionMailer # end # # Methods must return a <tt>Mail::Message</tt> object which can be generated by calling the mailer - # method without the additional <tt>deliver</tt>. The location of the mailer previews - # directory can be configured using the <tt>preview_path</tt> option which has a default + # method without the additional <tt>deliver_now</tt> / <tt>deliver_later</tt>. The location of the + # mailer previews directory can be configured using the <tt>preview_path</tt> option which has a default # of <tt>test/mailers/previews</tt>: # # config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews" diff --git a/actionmailer/lib/action_mailer/delivery_job.rb b/actionmailer/lib/action_mailer/delivery_job.rb index b2cfa245fd..622f202695 100644 --- a/actionmailer/lib/action_mailer/delivery_job.rb +++ b/actionmailer/lib/action_mailer/delivery_job.rb @@ -1,10 +1,10 @@ require 'active_job' module ActionMailer - class DeliveryJob < ActiveJob::Base + class DeliveryJob < ActiveJob::Base #:nodoc: queue_as :mailers - def perform(mailer, mail_method, delivery_method, *args) + def perform(mailer, mail_method, delivery_method, *args) #:nodoc# mailer.constantize.public_send(mail_method, *args).send(delivery_method) end end diff --git a/actionmailer/lib/action_mailer/message_delivery.rb b/actionmailer/lib/action_mailer/message_delivery.rb index 80a0517bff..30425d38f9 100644 --- a/actionmailer/lib/action_mailer/message_delivery.rb +++ b/actionmailer/lib/action_mailer/message_delivery.rb @@ -1,45 +1,112 @@ require 'delegate' module ActionMailer + + # The <tt>ActionMailer::MessageDelivery</tt> class is used by + # <tt>ActionMailer::Base</tt> when creating a new mailer. + # <tt>MessageDelivery</tt> is a wrapper (+Delegator+ subclass) around a lazy + # created <tt>Mail::Message</tt>. You can get direct access to the + # <tt>Mail::Message</tt>, deliver the email or schedule the email to be sent + # through Active Job. + # + # Notifier.welcome(User.first) # an ActionMailer::MessageDelivery object + # Notifier.welcome(User.first).deliver_now # sends the email + # Notifier.welcome(User.first).deliver_later # enqueue email delivery as a job through Active Job + # Notifier.welcome(User.first).message # a Mail::Message object class MessageDelivery < Delegator - def initialize(mailer, mail_method, *args) + def initialize(mailer, mail_method, *args) #:nodoc: @mailer = mailer @mail_method = mail_method @args = args end - def __getobj__ + def __getobj__ #:nodoc: @obj ||= @mailer.send(:new, @mail_method, *@args).message end - def __setobj__(obj) + def __setobj__(obj) #:nodoc: @obj = obj end - def message #:nodoc: + # Returns the Mail::Message object + def message __getobj__ end + # Enqueues the email to be delivered through Active Job. When the + # job runs it will send the email using +deliver_now!+. That means + # that the message will be sent bypassing checking +perform_deliveries+ + # and +raise_delivery_errors+, so use with caution. + # + # Notifier.welcome(User.first).deliver_later + # Notifier.welcome(User.first).deliver_later(in: 1.hour) + # Notifier.welcome(User.first).deliver_later(at: 10.hours.from_now) + # + # Options: + # + # * <tt>:in</tt> - Enqueue the email to be delivered with a delay + # * <tt>:at</tt> - Enqueue the email to be delivered at (after) a specific date / time def deliver_later!(options={}) - enqueue_delivery :deliver!, options + enqueue_delivery :deliver_now!, options end + # Enqueues the email to be delivered through Active Job. When the + # job runs it will send the email using +deliver_now+. + # + # Notifier.welcome(User.first).deliver_later + # Notifier.welcome(User.first).deliver_later(in: 1.hour) + # Notifier.welcome(User.first).deliver_later(at: 10.hours.from_now) + # + # Options: + # + # * <tt>:in</tt> - Enqueue the email to be delivered with a delay + # * <tt>:at</tt> - Enqueue the email to be delivered at (after) a specific date / time def deliver_later(options={}) - enqueue_delivery :deliver, options + enqueue_delivery :deliver_now, options + end + + # Delivers an email without checking +perform_deliveries+ and +raise_delivery_errors+, + # so use with caution. + # + # Notifier.welcome(User.first).deliver_now! + # + def deliver_now! + message.deliver! + end + + # Delivers an email: + # + # Notifier.welcome(User.first).deliver_now + # + def deliver_now + message.deliver + end + + def deliver! #:nodoc: + ActiveSupport::Deprecation.warn "#deliver! is deprecated and will be removed in Rails 5. " \ + "Use #deliver_now! to deliver immediately or #deliver_later! to deliver through Active Job." + deliver_now! + end + + def deliver #:nodoc: + ActiveSupport::Deprecation.warn "#deliver is deprecated and will be removed in Rails 5. " \ + "Use #deliver_now to deliver immediately or #deliver_later to deliver through Active Job." + deliver_now end private - def enqueue_delivery(delivery_method, options={}) - args = @mailer.name, @mail_method.to_s, delivery_method.to_s, *@args - enqueue_method = :enqueue - if options[:at] - enqueue_method = :enqueue_at - args.unshift options[:at] - elsif options[:in] - enqueue_method = :enqueue_in - args.unshift options[:in] + + def enqueue_delivery(delivery_method, options={}) + args = @mailer.name, @mail_method.to_s, delivery_method.to_s, *@args + enqueue_method = :enqueue + if options[:at] + enqueue_method = :enqueue_at + args.unshift options[:at] + elsif options[:in] + enqueue_method = :enqueue_in + args.unshift options[:in] + end + ActionMailer::DeliveryJob.send enqueue_method, *args end - ActionMailer::DeliveryJob.send enqueue_method, *args - end end end diff --git a/actionmailer/lib/action_mailer/railtie.rb b/actionmailer/lib/action_mailer/railtie.rb index c62d4b5082..05a3ac6a21 100644 --- a/actionmailer/lib/action_mailer/railtie.rb +++ b/actionmailer/lib/action_mailer/railtie.rb @@ -1,3 +1,4 @@ +require 'active_job/railtie' require "action_mailer" require "rails" require "abstract_controller/railties/routes_helpers" diff --git a/actionmailer/lib/action_mailer/test_helper.rb b/actionmailer/lib/action_mailer/test_helper.rb index 06da0dd27e..6ddacf7b79 100644 --- a/actionmailer/lib/action_mailer/test_helper.rb +++ b/actionmailer/lib/action_mailer/test_helper.rb @@ -6,9 +6,9 @@ module ActionMailer # # def test_emails # assert_emails 0 - # ContactMailer.welcome.deliver + # ContactMailer.welcome.deliver_now # assert_emails 1 - # ContactMailer.welcome.deliver + # ContactMailer.welcome.deliver_now # assert_emails 2 # end # @@ -17,12 +17,12 @@ module ActionMailer # # def test_emails_again # assert_emails 1 do - # ContactMailer.welcome.deliver + # ContactMailer.welcome.deliver_now # end # # assert_emails 2 do - # ContactMailer.welcome.deliver - # ContactMailer.welcome.deliver + # ContactMailer.welcome.deliver_now + # ContactMailer.welcome.deliver_now # end # end def assert_emails(number) @@ -40,7 +40,7 @@ module ActionMailer # # def test_emails # assert_no_emails - # ContactMailer.welcome.deliver + # ContactMailer.welcome.deliver_now # assert_emails 1 # end # diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index c549545674..c4dbbe25f6 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -32,15 +32,6 @@ module Rails end end -def set_delivery_method(method) - @old_delivery_method = ActionMailer::Base.delivery_method - ActionMailer::Base.delivery_method = method -end - -def restore_delivery_method - ActionMailer::Base.delivery_method = @old_delivery_method -end - # Skips the current run on Rubinius using Minitest::Assertions#skip def rubinius_skip(message = '') skip message if RUBY_ENGINE == 'rbx' 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/asset_host_test.rb b/actionmailer/test/asset_host_test.rb index 9ba67c2842..dd3b38544f 100644 --- a/actionmailer/test/asset_host_test.rb +++ b/actionmailer/test/asset_host_test.rb @@ -9,11 +9,8 @@ class AssetHostMailer < ActionMailer::Base end end -class AssetHostTest < ActiveSupport::TestCase +class AssetHostTest < ActionMailer::TestCase def setup - set_delivery_method :test - ActionMailer::Base.perform_deliveries = true - ActionMailer::Base.deliveries.clear AssetHostMailer.configure do |c| c.asset_host = "http://www.example.com" end 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 a097d0e84d..53654871a2 100644 --- a/actionmailer/test/message_delivery_test.rb +++ b/actionmailer/test/message_delivery_test.rb @@ -1,9 +1,8 @@ # encoding: utf-8 -gem 'activejob' -require 'active_job' require 'abstract_unit' +require 'active_job' require 'minitest/mock' -require_relative 'mailers/delayed_mailer' +require 'mailers/delayed_mailer' class MessageDeliveryTest < ActiveSupport::TestCase @@ -37,6 +36,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,30 +55,40 @@ class MessageDeliveryTest < ActiveSupport::TestCase assert_respond_to @mail, :deliver_later! end - test 'should enqueue and run correctly in activejob' do + 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 + + def test_should_enqueue_and_run_correctly_in_activejob @mail.deliver_later! - assert_equal 1 , ActionMailer::Base.deliveries.size + assert_equal 1, ActionMailer::Base.deliveries.size + ensure + ActionMailer::Base.deliveries.clear 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 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 @@ -76,7 +96,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 |