Got AM working with Mail yield on delivery_handler and updated tests

This commit is contained in:
José Valim and Mikel Lindsaar
2010-01-25 21:47:03 +11:00
parent 4240369a43
commit ace74974cf
7 changed files with 23 additions and 13 deletions

View File

@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
s.homepage = "http://www.rubyonrails.org"
s.add_dependency('actionpack', '= 3.0.pre')
s.add_dependency('mail', '~> 2.0.5')
s.add_dependency('mail', '~> 2.0.6')
s.files = Dir['CHANGELOG', 'README', 'MIT-LICENSE', 'lib/**/*']
s.has_rdoc = true

View File

@@ -330,14 +330,7 @@ module ActionMailer #:nodoc:
ActiveSupport::Notifications.instrument("action_mailer.deliver") do |payload|
self.set_payload_for_mail(payload, mail)
if mail.perform_deliveries
begin
mail.deliver!
rescue Exception => e
raise e if mail.raise_delivery_errors
end
Mail.deliveries << mail
end
yield # Let Mail do the delivery actions
end
end

View File

@@ -40,8 +40,8 @@ module ActionMailer
end
module ClassMethods
# Provides a list of emails that have been delivered by Mail
delegate :deliveries, :deliveries=, :to => Mail
# Provides a list of emails that have been delivered by Mail::TestMailer
delegate :deliveries, :deliveries=, :to => Mail::TestMailer
# Adds a new delivery method through the given class using the given symbol
# as alias and the default options supplied:

View File

@@ -363,6 +363,13 @@ class BaseTest < ActiveSupport::TestCase
BaseMailer.welcome.deliver
assert_equal(1, BaseMailer.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
BaseMailer.expects(:welcome).returns(mail)
BaseMailer.welcome.deliver
end
protected

View File

@@ -159,12 +159,12 @@ class MailDeliveryTest < ActiveSupport::TestCase
end
end
test "increments the deliveries collection on bogus deliveries if set to ignore" do
test "does not increment the deliveries collection on bogus deliveries" do
DeliveryMailer.delivery_method = BogusDelivery
DeliveryMailer.raise_delivery_errors = false
DeliveryMailer.deliveries.clear
DeliveryMailer.welcome.deliver
assert_equal(1, DeliveryMailer.deliveries.length)
assert_equal(0, DeliveryMailer.deliveries.length)
end
end

View File

@@ -387,6 +387,8 @@ class ActionMailerTest < Test::Unit::TestCase
end
def test_signed_up
TestMailer.delivery_method = :test
Time.stubs(:now => Time.now)
expected = new_mail
@@ -533,6 +535,8 @@ class ActionMailerTest < Test::Unit::TestCase
end
def test_reply_to
TestMailer.delivery_method = :test
expected = new_mail
expected.to = @recipient
@@ -567,6 +571,8 @@ class ActionMailerTest < Test::Unit::TestCase
end
def test_iso_charset
TestMailer.delivery_method = :test
expected = new_mail( "iso-8859-1" )
expected.to = @recipient
expected.subject = encode "testing isø charsets", "iso-8859-1"
@@ -601,6 +607,7 @@ class ActionMailerTest < Test::Unit::TestCase
end
def test_unencoded_subject
TestMailer.delivery_method = :test
expected = new_mail
expected.to = @recipient
expected.subject = "testing unencoded subject"
@@ -1029,6 +1036,7 @@ EOF
end
def test_with_mail_object_deliver
TestMailer.delivery_method = :test
mail = TestMailer.headers_with_nonalpha_chars(@recipient)
assert_nothing_raised { mail.deliver }
assert_equal 1, TestMailer.deliveries.length

View File

@@ -54,6 +54,8 @@ class ActionMailerUrlTest < Test::Unit::TestCase
end
def test_signed_up_with_url
TestMailer.delivery_method = :test
ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
map.welcome 'welcome', :controller=>"foo", :action=>"bar"