Skip to content
Browse files

Version bump to 2.1.0

Now passes a block to the delivery handler, which can just call yield if it want's Mail to just do it's normal delivery method

Moved Mail.deliveries into Mail::TestMailer.deliveries. Now only gets mail appended to it if you are sending with the :test delivery_method (only for testing)
  • Loading branch information...
1 parent 70743d2 commit 687abaceaa36efea6d95acdb41a70e65e8a252f1 System Administrator committed Jan 25, 2010
View
6 CHANGELOG.rdoc
@@ -1,3 +1,9 @@
+== Mon Jan 25 10:36:33 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
+
+* Now passes a block to the delivery handler, which can just call yield if it want's Mail to just do it's normal delivery method
+* Moved Mail.deliveries into Mail::TestMailer.deliveries. Now only gets mail appended to it if you are sending with the :test delivery_method (only for testing)
+* Version bump to 2.1.0
+
== Mon Jan 25 01:44:13 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
* Change :deliver! to deliver a mail object, bypassing the :perform_deliveries and :raise_delivery_errors flags, also does not append the mail object to Mail.deliveries, thus the ! (dangerous). The intended use for :deliver! is for people wanting to have their own delivery_handler (like ActionMailer uses) to track and handle delivery failures.
View
2 Rakefile
@@ -12,7 +12,7 @@ require 'bundler'
spec = Gem::Specification.new do |s|
s.name = "mail"
- s.version = "2.0.5"
+ s.version = "2.1.0"
s.author = "Mike Lindsaar"
s.email = "raasdnil@gmail.com"
s.homepage = "http://github.com/mikel/mail"
View
19 lib/mail/mail.rb
@@ -169,25 +169,6 @@ def Mail.all(*args, &block)
def Mail.read(filename)
Mail.new(File.read(filename))
end
-
- # Provides a store of all the emails sent
- def Mail.deliveries
- @@deliveries ||= []
- end
-
- # Allows you to over write the default deliveries store from an array to some
- # other object. If you just want to clear the store, call Mail.deliveries.clear.
- #
- # If you place another object here, please make sure it responds to:
- #
- # * << (message)
- # * clear
- # * length
- # * size
- # * and other common Array methods
- def Mail.deliveries=(val)
- @@deliveries = val
- end
protected
View
22 lib/mail/message.rb
@@ -136,7 +136,7 @@ def initialize(*args, &block)
# * Actually calling :deliver! (with the bang) on the mail object to
# get it to deliver itself.
#
- # A simple implementation of a delivery_handler would be
+ # A simplest implementation of a delivery_handler would be
#
# class MyObject
#
@@ -148,12 +148,7 @@ def initialize(*args, &block)
# attr_accessor :mail
#
# def deliver_mail(mail)
- # begin
- # mail.deliver! if mail.perform_deliveries
- # Mail.deliveries << mail
- # rescue e => Exception
- # raise e if mail.raise_delivery_errors
- # end
+ # yield
# end
# end
#
@@ -163,8 +158,8 @@ def initialize(*args, &block)
# obj.mail.deliver
#
# Would cause Mail to call obj.deliver_mail passing itself as a parameter,
- # which then would call #deliver! on the mail object which then goes ahead
- # and delivers itself.
+ # which then can just yield and let Mail do it's own private do_delivery
+ # method.
attr_accessor :delivery_handler
# If set to false, mail will go through the motions of doing a delivery,
@@ -218,7 +213,7 @@ def inform_observers
# mail.deliver
def deliver
if delivery_handler
- delivery_handler.deliver_mail(self)
+ delivery_handler.deliver_mail(self) { do_delivery }
else
do_delivery
inform_observers
@@ -227,9 +222,9 @@ def deliver
end
# This method bypasses checking perform_deliveries and raise_delivery_errors,
- # it also does not append the mail object to the Mail.deliveries array, so use
- # with caution. It still however fires callbacks to the observers if they
- # are defined.
+ # so use with caution.
+ #
+ # It still however fires callbacks to the observers if they are defined.
#
# Returns self
def deliver!
@@ -1767,7 +1762,6 @@ def do_delivery
begin
if perform_deliveries
delivery_method.deliver!(self)
- Mail.deliveries << self
end
rescue Exception => e # Net::SMTP errors or sendmail pipe errors
raise e if raise_delivery_errors
View
21 lib/mail/network/delivery_methods/test_mailer.rb
@@ -6,13 +6,34 @@ module Mail
# if you want to make a custom mailer for Mail
class TestMailer
+ # Provides a store of all the emails sent with the TestMailer so you can check them.
+ def TestMailer.deliveries
+ @@deliveries ||= []
+ end
+
+ # Allows you to over write the default deliveries store from an array to some
+ # other object. If you just want to clear the store,
+ # call TestMailer.deliveries.clear.
+ #
+ # If you place another object here, please make sure it responds to:
+ #
+ # * << (message)
+ # * clear
+ # * length
+ # * size
+ # * and other common Array methods
+ def TestMailer.deliveries=(val)
+ @@deliveries = val
+ end
+
def initialize(values)
@settings = {}
end
attr_accessor :settings
def deliver!(mail)
+ Mail::TestMailer.deliveries << mail
end
end
View
4 lib/mail/version.rb
@@ -2,8 +2,8 @@
module Mail
module VERSION
MAJOR = 2
- MINOR = 0
- TINY = 5
+ MINOR = 1
+ TINY = 0
STRING = [MAJOR, MINOR, TINY].join('.')
end
View
18 spec/mail/network/delivery_methods/test_mailer_spec.rb
@@ -1,7 +1,7 @@
# encoding: utf-8
require File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', '..', 'spec_helper')
-describe "TestMailer" do
+describe "Mail::TestMailer" do
before(:each) do
# Reset all defaults back to original state
Mail.defaults do
@@ -12,18 +12,18 @@
:password => nil,
:authentication => nil,
:enable_starttls_auto => true }
+ Mail::TestMailer.deliveries.clear
end
- Mail.deliveries.clear
end
it "should have no deliveries when first initiated" do
Mail.defaults do
delivery_method :test
end
- Mail.deliveries.should be_empty
+ Mail::TestMailer.deliveries.should be_empty
end
- it "should deliver an email to the Mail.deliveries array" do
+ it "should deliver an email to the Mail::TestMailer.deliveries array" do
Mail.defaults do
delivery_method :test
end
@@ -34,8 +34,8 @@
body 'hello'
end
mail.deliver
- Mail.deliveries.length.should == 1
- Mail.deliveries.first.should == mail
+ Mail::TestMailer.deliveries.length.should == 1
+ Mail::TestMailer.deliveries.first.should == mail
end
it "should clear the deliveries when told to" do
@@ -49,9 +49,9 @@
body 'hello'
end
mail.deliver
- Mail.deliveries.length.should == 1
- Mail.deliveries.clear
- Mail.deliveries.should be_empty
+ Mail::TestMailer.deliveries.length.should == 1
+ Mail::TestMailer.deliveries.clear
+ Mail::TestMailer.deliveries.should be_empty
end
end
View
32 spec/mail/network_spec.rb
@@ -5,12 +5,6 @@ class MyDelivery; def initialize(settings); end; end
class MyRetriever; def initialize(settings); end; end
-class MyDeliveryHandler
- def deliver_mail(mail)
- mail.deliver!
- end
-end
-
describe "Mail" do
before(:each) do
@@ -223,6 +217,18 @@ class MyObserver
def self.delivered_email(message); end
end
+ class MyDeliveryHandler
+ def deliver_mail(mail)
+ mail.deliver!
+ end
+ end
+
+ class MyYieldingDeliveryHandler
+ def deliver_mail(mail)
+ yield
+ end
+ end
+
before(:each) do
@message = Mail.new do
from 'mikel@test.lindsaar.net'
@@ -235,7 +241,7 @@ def self.delivered_email(message); end
describe "adding to Mail.deliveries" do
it "should add itself to the deliveries collection on mail on delivery" do
- doing { @message.deliver }.should change(Mail.deliveries, :size).by(1)
+ doing { @message.deliver }.should change(Mail::TestMailer.deliveries, :size).by(1)
end
end
@@ -257,12 +263,12 @@ def self.delivered_email(message); end
it "should add to the deliveries array if perform_deliveries is true" do
@message.perform_deliveries = true
- doing { @message.deliver }.should change(Mail.deliveries, :size).by(1)
+ doing { @message.deliver }.should change(Mail::TestMailer.deliveries, :size).by(1)
end
it "should not add to the deliveries array if perform_deliveries is false" do
@message.perform_deliveries = false
- doing { @message.deliver }.should_not change(Mail.deliveries, :size)
+ doing { @message.deliver }.should_not change(Mail::TestMailer.deliveries, :size)
end
end
@@ -336,7 +342,13 @@ def self.delivered_email(message); end
it "mail should not modify the Mail.deliveries object if using a delivery_handler" do
@message.delivery_handler = MyDeliveryHandler.new
- doing { @message.deliver }.should_not change(Mail, :deliveries)
+ doing { @message.deliver }.should_not change(Mail::TestMailer, :deliveries)
+ end
+
+ it "should be able to just yield and let mail do it's thing" do
+ @message.delivery_handler = MyYieldingDeliveryHandler.new
+ @message.should_receive(:do_delivery).exactly(:once)
+ @message.deliver
end
end

0 comments on commit 687abac

Please sign in to comment.
Something went wrong with that request. Please try again.