diff options
author | Brian Cardarella <bcardarella@gmail.com> | 2012-06-23 14:36:09 -0400 |
---|---|---|
committer | Brian Cardarella <bcardarella@gmail.com> | 2012-06-23 14:36:09 -0400 |
commit | dc7fd821dca0b2088bde7e0a2a06bfe59e1ba5c6 (patch) | |
tree | bf317b8bc64a1842aa3c5e65b3f829e1f2eaa9f1 /actionmailer/test | |
parent | 3726080ecea8b34edeac37f358e8dd050cbb00cb (diff) | |
download | rails-dc7fd821dca0b2088bde7e0a2a06bfe59e1ba5c6.tar.gz rails-dc7fd821dca0b2088bde7e0a2a06bfe59e1ba5c6.tar.bz2 rails-dc7fd821dca0b2088bde7e0a2a06bfe59e1ba5c6.zip |
Asynchronous ActionMailer
Any ActionMailer class can be set to render and delier messages using
the new Rails Queue.
Some of this work was borrowed (with permission) from Nick Plante's
(zapnap) reqsue_mailer gem.
Diffstat (limited to 'actionmailer/test')
-rw-r--r-- | actionmailer/test/base_test.rb | 14 | ||||
-rw-r--r-- | actionmailer/test/fixtures/async_mailer/welcome.erb | 1 | ||||
-rw-r--r-- | actionmailer/test/mailers/async_mailer.rb | 3 |
3 files changed, 18 insertions, 0 deletions
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index 1b2e39b3f7..fdc784029b 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -7,6 +7,9 @@ require 'active_support/time' require 'mailers/base_mailer' require 'mailers/proc_mailer' require 'mailers/asset_mailer' +require 'mailers/async_mailer' + +require 'rails/queueing' class BaseTest < ActiveSupport::TestCase def teardown @@ -419,6 +422,16 @@ class BaseTest < ActiveSupport::TestCase assert_equal(1, BaseMailer.deliveries.length) end + test "delivering message asynchronously" do + Rails.stubs(:queue).returns(Rails::Queueing::TestQueue.new) + AsyncMailer.delivery_method = :test + AsyncMailer.deliveries.clear + AsyncMailer.welcome.deliver + assert_equal(0, AsyncMailer.deliveries.length) + Rails.queue.drain + assert_equal(1, AsyncMailer.deliveries.length) + end + test "calling deliver, ActionMailer should yield back to mail to let it call :do_delivery on itself" do mail = Mail::Message.new mail.expects(:do_delivery).once @@ -434,6 +447,7 @@ class BaseTest < ActiveSupport::TestCase end test "should raise if missing template in implicit render" do + BaseMailer.deliveries.clear assert_raises ActionView::MissingTemplate do BaseMailer.implicit_different_template('missing_template').deliver end diff --git a/actionmailer/test/fixtures/async_mailer/welcome.erb b/actionmailer/test/fixtures/async_mailer/welcome.erb new file mode 100644 index 0000000000..01f3f00c63 --- /dev/null +++ b/actionmailer/test/fixtures/async_mailer/welcome.erb @@ -0,0 +1 @@ +Welcome
\ No newline at end of file diff --git a/actionmailer/test/mailers/async_mailer.rb b/actionmailer/test/mailers/async_mailer.rb new file mode 100644 index 0000000000..ce601e7343 --- /dev/null +++ b/actionmailer/test/mailers/async_mailer.rb @@ -0,0 +1,3 @@ +class AsyncMailer < BaseMailer + self.async = true +end |