Skip to content
Browse files

Add new class delivery method API.

  • Loading branch information...
1 parent 7409b73 commit f30d73bab4c676b187276797ac2a6dc89132c43f José Valim and Mikel Lindsaar committed Jan 24, 2010
View
18 actionmailer/lib/action_mailer/base.rb
@@ -253,6 +253,8 @@ module ActionMailer #:nodoc:
# and appear last in the mime encoded message. You can also pick a different order from inside a method with
# +implicit_parts_order+.
class Base < AbstractController::Base
+ abstract!
+
include Quoting
include AbstractController::Logger
@@ -264,8 +266,8 @@ class Base < AbstractController::Base
helper ActionMailer::MailHelper
- include ActionMailer::DeprecatedApi
extend ActionMailer::DeliveryMethods
+ include ActionMailer::DeprecatedApi
add_delivery_method :smtp, Mail::SMTP,
:address => "localhost",
@@ -370,6 +372,20 @@ def set_payload_for_mail(payload, mail) #:nodoc:
payload[:date] = mail.date
payload[:mail] = mail.encoded
end
+
+ def respond_to?(method, *args)
+ super || action_methods.include?(method.to_s)
+ end
+
+ protected
+
+ def method_missing(method, *args)
+ if action_methods.include?(method.to_s)
+ new(method, *args).message
+ else
+ super
+ end
+ end
end
attr_internal :message
View
25 actionmailer/lib/action_mailer/deprecated_api.rb
@@ -1,8 +1,8 @@
module ActionMailer
- # TODO Remove this module all together in Rails 3.1. Ensure that super
- # hooks in ActionMailer::Base are removed as well.
- #
- # Moved here to allow us to add the new Mail API
+ # Part of this API is deprecated and is going to be removed in Rails 3.1 (just check
+ # the methods which give you a warning).
+ # All the rest will be deprecated after 3.1 release instead, this allows a smoother
+ # migration path.
module DeprecatedApi #:nodoc:
extend ActiveSupport::Concern
@@ -83,8 +83,8 @@ module ClassMethods
# MyMailer.deliver(email)
def deliver(mail, show_warning=true)
if show_warning
- ActiveSupport::Deprecation.warn "ActionMailer::Base.deliver is deprecated, just call " <<
- "deliver in the instance instead", caller
+ ActiveSupport::Deprecation.warn "#{self}.deliver is deprecated, call " <<
+ "deliver in the mailer instance instead", caller[0,2]
end
raise "no mail object available for delivery!" unless mail
@@ -100,9 +100,14 @@ def respond_to?(method_symbol, include_private = false) #:nodoc:
def method_missing(method_symbol, *parameters) #:nodoc:
if match = matches_dynamic_method?(method_symbol)
case match[1]
- when 'create' then new(match[2], *parameters).message
- when 'deliver' then new(match[2], *parameters).deliver!
- when 'new' then nil
+ when 'create'
+ ActiveSupport::Deprecation.warn "#{self}.create_#{match[2]} is deprecated, " <<
+ "use #{self}.#{match[2]} instead", caller[0,2]
+ new(match[2], *parameters).message
+ when 'deliver'
+ ActiveSupport::Deprecation.warn "#{self}.deliver_#{match[2]} is deprecated, " <<
+ "use #{self}.#{match[2]}.deliver instead", caller[0,2]
+ new(match[2], *parameters).deliver
else super
end
else
@@ -167,7 +172,6 @@ def part(params)
# Add an attachment to a multipart message. This is simply a part with the
# content-disposition set to "attachment".
def attachment(params, &block)
- ActiveSupport::Deprecation.warn "attachment is deprecated, please use the attachments API instead", caller[0,2]
params = { :content_type => params } if String === params
params[:content] ||= params.delete(:data) || params.delete(:body)
@@ -259,6 +263,7 @@ def create_mail #:nodoc:
end
end
+ wrap_delivery_behavior!
m.content_transfer_encoding = '8bit' unless m.body.only_us_ascii?
@_message
View
12 actionmailer/test/asset_host_test.rb
@@ -1,8 +1,8 @@
require 'abstract_unit'
class AssetHostMailer < ActionMailer::Base
- def email_with_asset(recipient)
- recipients recipient
+ def email_with_asset
+ recipients 'test@localhost'
subject "testing email containing asset path while asset_host is set"
from "tester@example.com"
end
@@ -13,8 +13,6 @@ def setup
set_delivery_method :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries.clear
-
- @recipient = 'test@localhost'
end
def teardown
@@ -23,7 +21,7 @@ def teardown
def test_asset_host_as_string
ActionController::Base.asset_host = "http://www.example.com"
- mail = AssetHostMailer.deliver_email_with_asset(@recipient)
+ mail = AssetHostMailer.email_with_asset
assert_equal "<img alt=\"Somelogo\" src=\"http://www.example.com/images/somelogo.png\" />", mail.body.to_s.strip
end
@@ -35,7 +33,7 @@ def test_asset_host_as_one_arguement_proc
"http://assets.example.com"
end
}
- mail = AssetHostMailer.deliver_email_with_asset(@recipient)
+ mail = AssetHostMailer.email_with_asset
assert_equal "<img alt=\"Somelogo\" src=\"http://images.example.com/images/somelogo.png\" />", mail.body.to_s.strip
end
@@ -48,7 +46,7 @@ def test_asset_host_as_two_arguement_proc
end
}
mail = nil
- assert_nothing_raised { mail = AssetHostMailer.deliver_email_with_asset(@recipient) }
+ assert_nothing_raised { mail = AssetHostMailer.email_with_asset }
assert_equal "<img alt=\"Somelogo\" src=\"http://www.example.com/images/somelogo.png\" />", mail.body.to_s.strip
end
end
View
135 actionmailer/test/base_test.rb
@@ -3,49 +3,13 @@
# class Notifier < ActionMailer::Base
# delivers_from 'notifications@example.com'
-#
-# def welcome(user)
-# @user = user # available to the view
-# mail(:subject => 'Welcome!', :to => user.email_address)
-# # auto renders both welcome.text.erb and welcome.html.erb
-# end
-#
-# def goodbye(user)
-# headers["X-SPAM"] = 'Not-SPAM'
-# mail(:subject => 'Goodbye', :to => user.email_address) do |format|
-# format.html { render "shared_template "}
-# format.text # goodbye.text.erb
-# end
-# end
-#
-# def surprise(user, gift)
-# attachments[gift.name] = File.read(gift.path)
-# mail(:subject => 'Surprise!', :to => user.email_address) do |format|
-# format.html(:charset => "ascii") # surprise.html.erb
-# format.text(:transfer_encoding => "base64") # surprise.text.erb
-# end
-# end
-#
-# def special_surprise(user, gift)
-# attachments[gift.name] = { :content_type => "application/x-gzip", :content => File.read(gift.path) }
-# mail(:to => 'special@example.com') # subject not required
-# # auto renders both special_surprise.text.erb and special_surprise.html.erb
-# end
-# end
-#
-# mail = Notifier.welcome(user) # => returns a Mail object
-# mail.deliver
-#
-# Notifier.welcome(user).deliver # => creates and sends the Mail in one step
class BaseTest < ActiveSupport::TestCase
DEFAULT_HEADERS = {
:to => 'mikel@test.lindsaar.net',
:from => 'jose@test.plataformatec.com',
:subject => 'The first email on new API!'
}
- # TODO Think on the simple case where I want to send an e-mail
- # with attachment and small text (without need to add a template).
class BaseMailer < ActionMailer::Base
self.mailer_name = "base_mailer"
@@ -60,7 +24,7 @@ def attachment_with_content(hash = {})
end
def attachment_with_hash
- attachments['invoice.jpg'] = { :content => "you smiling", :mime_type => "image/x-jpg",
+ attachments['invoice.jpg'] = { :data => "you smiling", :mime_type => "image/x-jpg",
:transfer_encoding => "base64" }
mail(DEFAULT_HEADERS)
end
@@ -93,26 +57,26 @@ def explicit_multipart_with_any(hash = {})
end
test "method call to mail does not raise error" do
- assert_nothing_raised { BaseMailer.deliver_welcome }
+ assert_nothing_raised { BaseMailer.welcome.deliver }
end
# Basic mail usage without block
test "mail() should set the headers of the mail message" do
- email = BaseMailer.deliver_welcome
+ email = BaseMailer.welcome.deliver
assert_equal(email.to, ['mikel@test.lindsaar.net'])
assert_equal(email.from, ['jose@test.plataformatec.com'])
assert_equal(email.subject, 'The first email on new API!')
end
test "mail() with bcc, cc, content_type, charset, mime_version, reply_to and date" do
@time = Time.now
- email = BaseMailer.deliver_welcome(:bcc => 'bcc@test.lindsaar.net',
- :cc => 'cc@test.lindsaar.net',
- :content_type => 'multipart/mixed',
- :charset => 'iso-8559-1',
- :mime_version => '2.0',
- :reply_to => 'reply-to@test.lindsaar.net',
- :date => @time)
+ email = BaseMailer.welcome(:bcc => 'bcc@test.lindsaar.net',
+ :cc => 'cc@test.lindsaar.net',
+ :content_type => 'multipart/mixed',
+ :charset => 'iso-8559-1',
+ :mime_version => '2.0',
+ :reply_to => 'reply-to@test.lindsaar.net',
+ :date => @time).deliver
assert_equal(email.bcc, ['bcc@test.lindsaar.net'])
assert_equal(email.cc, ['cc@test.lindsaar.net'])
assert_equal(email.content_type, 'multipart/mixed')
@@ -123,50 +87,50 @@ def explicit_multipart_with_any(hash = {})
end
test "mail() renders the template using the method being processed" do
- email = BaseMailer.deliver_welcome
+ email = BaseMailer.welcome.deliver
assert_equal("Welcome", email.body.encoded)
end
test "can pass in :body to the mail method hash" do
- email = BaseMailer.deliver_welcome(:body => "Hello there")
+ email = BaseMailer.welcome(:body => "Hello there").deliver
assert_equal("text/plain", email.mime_type)
assert_equal("Hello there", email.body.encoded)
end
# Custom headers
test "custom headers" do
- email = BaseMailer.deliver_welcome
+ email = BaseMailer.welcome.deliver
assert_equal("Not SPAM", email['X-SPAM'].decoded)
end
# Attachments
test "attachment with content" do
- email = BaseMailer.deliver_attachment_with_content
+ email = BaseMailer.attachment_with_content.deliver
assert_equal(1, email.attachments.length)
assert_equal('invoice.pdf', email.attachments[0].filename)
assert_equal('This is test File content', email.attachments['invoice.pdf'].decoded)
end
test "attachment gets content type from filename" do
- email = BaseMailer.deliver_attachment_with_content
+ email = BaseMailer.attachment_with_content.deliver
assert_equal('invoice.pdf', email.attachments[0].filename)
end
test "attachment with hash" do
- email = BaseMailer.deliver_attachment_with_hash
+ email = BaseMailer.attachment_with_hash.deliver
assert_equal(1, email.attachments.length)
assert_equal('invoice.jpg', email.attachments[0].filename)
assert_equal("\312\213\254\232)b", email.attachments['invoice.jpg'].decoded)
end
test "sets mime type to multipart/mixed when attachment is included" do
- email = BaseMailer.deliver_attachment_with_content
+ email = BaseMailer.attachment_with_content.deliver
assert_equal(1, email.attachments.length)
assert_equal("multipart/mixed", email.mime_type)
end
test "adds the rendered template as part" do
- email = BaseMailer.deliver_attachment_with_content
+ email = BaseMailer.attachment_with_content.deliver
assert_equal(2, email.parts.length)
assert_equal("multipart/mixed", email.mime_type)
assert_equal("text/html", email.parts[0].mime_type)
@@ -176,7 +140,7 @@ def explicit_multipart_with_any(hash = {})
end
test "adds the given :body as part" do
- email = BaseMailer.deliver_attachment_with_content(:body => "I'm the eggman")
+ email = BaseMailer.attachment_with_content(:body => "I'm the eggman").deliver
assert_equal(2, email.parts.length)
assert_equal("multipart/mixed", email.mime_type)
assert_equal("text/plain", email.parts[0].mime_type)
@@ -188,46 +152,46 @@ def explicit_multipart_with_any(hash = {})
# Defaults values
test "uses default charset from class" do
swap BaseMailer, :default_charset => "US-ASCII" do
- email = BaseMailer.deliver_welcome
+ email = BaseMailer.welcome.deliver
assert_equal("US-ASCII", email.charset)
- email = BaseMailer.deliver_welcome(:charset => "iso-8559-1")
+ email = BaseMailer.welcome(:charset => "iso-8559-1").deliver
assert_equal("iso-8559-1", email.charset)
end
end
test "uses default content type from class" do
swap BaseMailer, :default_content_type => "text/html" do
- email = BaseMailer.deliver_welcome
+ email = BaseMailer.welcome.deliver
assert_equal("text/html", email.mime_type)
- email = BaseMailer.deliver_welcome(:content_type => "text/plain")
+ email = BaseMailer.welcome(:content_type => "text/plain").deliver
assert_equal("text/plain", email.mime_type)
end
end
test "uses default mime version from class" do
swap BaseMailer, :default_mime_version => "2.0" do
- email = BaseMailer.deliver_welcome
+ email = BaseMailer.welcome.deliver
assert_equal("2.0", email.mime_version)
- email = BaseMailer.deliver_welcome(:mime_version => "1.0")
+ email = BaseMailer.welcome(:mime_version => "1.0").deliver
assert_equal("1.0", email.mime_version)
end
end
test "subject gets default from I18n" do
- email = BaseMailer.deliver_welcome(:subject => nil)
+ email = BaseMailer.welcome(:subject => nil).deliver
assert_equal "Welcome", email.subject
I18n.backend.store_translations('en', :actionmailer => {:base_mailer => {:welcome => {:subject => "New Subject!"}}})
- email = BaseMailer.deliver_welcome(:subject => nil)
+ email = BaseMailer.welcome(:subject => nil).deliver
assert_equal "New Subject!", email.subject
end
# Implicit multipart
test "implicit multipart" do
- email = BaseMailer.deliver_implicit_multipart
+ email = BaseMailer.implicit_multipart.deliver
assert_equal(2, email.parts.size)
assert_equal("multipart/alternate", email.mime_type)
assert_equal("text/plain", email.parts[0].mime_type)
@@ -239,18 +203,18 @@ def explicit_multipart_with_any(hash = {})
test "implicit multipart with sort order" do
order = ["text/html", "text/plain"]
swap BaseMailer, :default_implicit_parts_order => order do
- email = BaseMailer.deliver_implicit_multipart
+ email = BaseMailer.implicit_multipart.deliver
assert_equal("text/html", email.parts[0].mime_type)
assert_equal("text/plain", email.parts[1].mime_type)
- email = BaseMailer.deliver_implicit_multipart(:parts_order => order.reverse)
+ email = BaseMailer.implicit_multipart(:parts_order => order.reverse).deliver
assert_equal("text/plain", email.parts[0].mime_type)
assert_equal("text/html", email.parts[1].mime_type)
end
end
test "implicit multipart with attachments creates nested parts" do
- email = BaseMailer.deliver_implicit_multipart(:attachments => true)
+ email = BaseMailer.implicit_multipart(:attachments => true).deliver
assert_equal("application/pdf", email.parts[0].mime_type)
assert_equal("multipart/alternate", email.parts[1].mime_type)
assert_equal("text/plain", email.parts[1].parts[0].mime_type)
@@ -262,7 +226,7 @@ def explicit_multipart_with_any(hash = {})
test "implicit multipart with attachments and sort order" do
order = ["text/html", "text/plain"]
swap BaseMailer, :default_implicit_parts_order => order do
- email = BaseMailer.deliver_implicit_multipart(:attachments => true)
+ email = BaseMailer.implicit_multipart(:attachments => true).deliver
assert_equal("application/pdf", email.parts[0].mime_type)
assert_equal("multipart/alternate", email.parts[1].mime_type)
assert_equal("text/plain", email.parts[1].parts[1].mime_type)
@@ -272,7 +236,7 @@ def explicit_multipart_with_any(hash = {})
# Explicit multipart
test "explicit multipart" do
- email = BaseMailer.deliver_explicit_multipart
+ email = BaseMailer.explicit_multipart.deliver
assert_equal(2, email.parts.size)
assert_equal("multipart/alternate", email.mime_type)
assert_equal("text/plain", email.parts[0].mime_type)
@@ -284,18 +248,18 @@ def explicit_multipart_with_any(hash = {})
test "explicit multipart does not sort order" do
order = ["text/html", "text/plain"]
swap BaseMailer, :default_implicit_parts_order => order do
- email = BaseMailer.deliver_explicit_multipart
+ email = BaseMailer.explicit_multipart.deliver
assert_equal("text/plain", email.parts[0].mime_type)
assert_equal("text/html", email.parts[1].mime_type)
- email = BaseMailer.deliver_explicit_multipart(:parts_order => order.reverse)
+ email = BaseMailer.explicit_multipart(:parts_order => order.reverse).deliver
assert_equal("text/plain", email.parts[0].mime_type)
assert_equal("text/html", email.parts[1].mime_type)
end
end
test "explicit multipart with attachments creates nested parts" do
- email = BaseMailer.deliver_explicit_multipart(:attachments => true)
+ email = BaseMailer.explicit_multipart(:attachments => true).deliver
assert_equal("application/pdf", email.parts[0].mime_type)
assert_equal("multipart/alternate", email.parts[1].mime_type)
assert_equal("text/plain", email.parts[1].parts[0].mime_type)
@@ -305,7 +269,7 @@ def explicit_multipart_with_any(hash = {})
end
test "explicit multipart with templates" do
- email = BaseMailer.deliver_explicit_multipart_templates
+ email = BaseMailer.explicit_multipart_templates.deliver
assert_equal(2, email.parts.size)
assert_equal("multipart/alternate", email.mime_type)
assert_equal("text/html", email.parts[0].mime_type)
@@ -315,7 +279,7 @@ def explicit_multipart_with_any(hash = {})
end
test "explicit multipart with any" do
- email = BaseMailer.deliver_explicit_multipart_with_any
+ email = BaseMailer.explicit_multipart_with_any.deliver
assert_equal(2, email.parts.size)
assert_equal("multipart/alternate", email.mime_type)
assert_equal("text/plain", email.parts[0].mime_type)
@@ -324,21 +288,30 @@ def explicit_multipart_with_any(hash = {})
assert_equal("Format with any!", email.parts[1].body.encoded)
end
- test "ActionMailer should be told when Mail gets delivered" do
- BaseMailer.deliveries.clear
- BaseMailer.expects(:delivered_email).once
- BaseMailer.deliver_welcome
- assert_equal(1, BaseMailer.deliveries.length)
+ # Class level API with method missing
+ test "should respond to action methods" do
+ assert BaseMailer.respond_to?(:welcome)
+ assert BaseMailer.respond_to?(:implicit_multipart)
+ assert !BaseMailer.respond_to?(:mail)
+ assert !BaseMailer.respond_to?(:headers)
end
- test "Calling just the action should return the generated mail object" do
+ test "calling just the action should return the generated mail object" do
BaseMailer.deliveries.clear
email = BaseMailer.welcome
assert_equal(0, BaseMailer.deliveries.length)
assert_equal('The first email on new API!', email.subject)
end
- test "Calling deliver on the action should deliver the mail object" do
+ test "calling deliver on the action should deliver the mail object" do
+ BaseMailer.deliveries.clear
+ BaseMailer.expects(:delivered_email).once
+ BaseMailer.welcome.deliver
+ assert_equal(1, BaseMailer.deliveries.length)
+ end
+
+ # Delivery hooks
+ test "ActionMailer should be told when Mail gets delivered" do
BaseMailer.deliveries.clear
BaseMailer.expects(:delivered_email).once
BaseMailer.welcome.deliver
View
28 actionmailer/test/mail_helper_test.rb
@@ -10,22 +10,22 @@ class HelperMailer < ActionMailer::Base
helper MailerHelper
helper :example
- def use_helper(recipient)
- recipients recipient
+ def use_helper
+ recipients 'test@localhost'
subject "using helpers"
from "tester@example.com"
end
- def use_example_helper(recipient)
- recipients recipient
+ def use_example_helper
+ recipients 'test@localhost'
subject "using helpers"
from "tester@example.com"
@text = "emphasize me!"
end
- def use_mail_helper(recipient)
- recipients recipient
+ def use_mail_helper
+ recipients 'test@localhost'
subject "using mailing helpers"
from "tester@example.com"
@@ -37,8 +37,8 @@ def use_mail_helper(recipient)
"it off!"
end
- def use_helper_method(recipient)
- recipients recipient
+ def use_helper_method
+ recipients 'test@localhost'
subject "using helpers"
from "tester@example.com"
@@ -53,7 +53,7 @@ def name_of_the_mailer_class
helper_method :name_of_the_mailer_class
end
-class MailerHelperTest < Test::Unit::TestCase
+class MailerHelperTest < ActiveSupport::TestCase
def new_mail( charset="utf-8" )
mail = Mail.new
mail.set_content_type "text", "plain", { "charset" => charset } if charset
@@ -64,31 +64,29 @@ def setup
set_delivery_method :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries.clear
-
- @recipient = 'test@localhost'
end
def teardown
restore_delivery_method
end
def test_use_helper
- mail = HelperMailer.create_use_helper(@recipient)
+ mail = HelperMailer.use_helper
assert_match %r{Mr. Joe Person}, mail.encoded
end
def test_use_example_helper
- mail = HelperMailer.create_use_example_helper(@recipient)
+ mail = HelperMailer.use_example_helper
assert_match %r{<em><strong><small>emphasize me!}, mail.encoded
end
def test_use_helper_method
- mail = HelperMailer.create_use_helper_method(@recipient)
+ mail = HelperMailer.use_helper_method
assert_match %r{HelperMailer}, mail.encoded
end
def test_use_mail_helper
- mail = HelperMailer.create_use_mail_helper(@recipient)
+ mail = HelperMailer.use_mail_helper
assert_match %r{ But soft!}, mail.encoded
assert_match %r{east, and\r\n Juliet}, mail.encoded
end
View
42 actionmailer/test/mail_layout_test.rb
@@ -2,32 +2,32 @@
class AutoLayoutMailer < ActionMailer::Base
- def hello(recipient)
- recipients recipient
+ def hello
+ recipients 'test@localhost'
subject "You have a mail"
from "tester@example.com"
end
- def spam(recipient)
- recipients recipient
+ def spam
+ recipients 'test@localhost'
subject "You have a mail"
from "tester@example.com"
@world = "Earth"
render(:inline => "Hello, <%= @world %>", :layout => 'spam')
end
- def nolayout(recipient)
- recipients recipient
+ def nolayout
+ recipients 'test@localhost'
subject "You have a mail"
from "tester@example.com"
@world = "Earth"
render(:inline => "Hello, <%= @world %>", :layout => false)
end
- def multipart(recipient, type = nil)
- recipients recipient
+ def multipart(type = nil)
+ recipients 'test@localhost'
subject "You have a mail"
from "tester@example.com"
@@ -38,14 +38,14 @@ def multipart(recipient, type = nil)
class ExplicitLayoutMailer < ActionMailer::Base
layout 'spam', :except => [:logout]
- def signup(recipient)
- recipients recipient
+ def signup
+ recipients 'test@localhost'
subject "You have a mail"
from "tester@example.com"
end
- def logout(recipient)
- recipients recipient
+ def logout
+ recipients 'test@localhost'
subject "You have a mail"
from "tester@example.com"
end
@@ -56,21 +56,19 @@ def setup
set_delivery_method :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries.clear
-
- @recipient = 'test@localhost'
end
def teardown
restore_delivery_method
end
def test_should_pickup_default_layout
- mail = AutoLayoutMailer.create_hello(@recipient)
+ mail = AutoLayoutMailer.hello
assert_equal "Hello from layout Inside", mail.body.to_s.strip
end
def test_should_pickup_multipart_layout
- mail = AutoLayoutMailer.create_multipart(@recipient)
+ mail = AutoLayoutMailer.multipart
# CHANGED: content_type returns an object
# assert_equal "multipart/alternative", mail.content_type
assert_equal "multipart/alternative", mail.mime_type
@@ -94,7 +92,7 @@ def test_should_pickup_multipart_layout
end
def test_should_pickup_multipartmixed_layout
- mail = AutoLayoutMailer.create_multipart(@recipient, "multipart/mixed")
+ mail = AutoLayoutMailer.multipart("multipart/mixed")
# CHANGED: content_type returns an object
# assert_equal "multipart/mixed", mail.content_type
assert_equal "multipart/mixed", mail.mime_type
@@ -116,7 +114,7 @@ def test_should_pickup_multipartmixed_layout
end
def test_should_fix_multipart_layout
- mail = AutoLayoutMailer.create_multipart(@recipient, "text/plain")
+ mail = AutoLayoutMailer.multipart("text/plain")
assert_equal "multipart/alternative", mail.mime_type
assert_equal 2, mail.parts.size
@@ -129,22 +127,22 @@ def test_should_fix_multipart_layout
def test_should_pickup_layout_given_to_render
- mail = AutoLayoutMailer.create_spam(@recipient)
+ mail = AutoLayoutMailer.spam
assert_equal "Spammer layout Hello, Earth", mail.body.to_s.strip
end
def test_should_respect_layout_false
- mail = AutoLayoutMailer.create_nolayout(@recipient)
+ mail = AutoLayoutMailer.nolayout
assert_equal "Hello, Earth", mail.body.to_s.strip
end
def test_explicit_class_layout
- mail = ExplicitLayoutMailer.create_signup(@recipient)
+ mail = ExplicitLayoutMailer.signup
assert_equal "Spammer layout We do not spam", mail.body.to_s.strip
end
def test_explicit_layout_exceptions
- mail = ExplicitLayoutMailer.create_logout(@recipient)
+ mail = ExplicitLayoutMailer.logout
assert_equal "You logged out", mail.body.to_s.strip
end
end
View
62 actionmailer/test/mail_render_test.rb
@@ -1,55 +1,55 @@
require 'abstract_unit'
class RenderMailer < ActionMailer::Base
- def inline_template(recipient)
- recipients recipient
+ def inline_template
+ recipients 'test@localhost'
subject "using helpers"
from "tester@example.com"
@world = "Earth"
render :inline => "Hello, <%= @world %>"
end
- def file_template(recipient)
- recipients recipient
+ def file_template
+ recipients 'test@localhost'
subject "using helpers"
from "tester@example.com"
- @recipient = recipient
+ @recipient = 'test@localhost'
render :file => "templates/signed_up"
end
- def implicit_body(recipient)
- recipients recipient
+ def implicit_body
+ recipients 'test@localhost'
subject "using helpers"
from "tester@example.com"
- @recipient = recipient
+ @recipient = 'test@localhost'
render :template => "templates/signed_up"
end
- def rxml_template(recipient)
- recipients recipient
+ def rxml_template
+ recipients 'test@localhost'
subject "rendering rxml template"
from "tester@example.com"
end
- def included_subtemplate(recipient)
- recipients recipient
+ def included_subtemplate
+ recipients 'test@localhost'
subject "Including another template in the one being rendered"
from "tester@example.com"
end
- def mailer_accessor(recipient)
- recipients recipient
+ def mailer_accessor
+ recipients 'test@localhost'
subject "Mailer Accessor"
from "tester@example.com"
render :inline => "Look, <%= mailer.subject %>!"
end
- def no_instance_variable(recipient)
- recipients recipient
+ def no_instance_variable
+ recipients 'test@localhost'
subject "No Instance Variable"
from "tester@example.com"
@@ -65,16 +65,16 @@ def initialize_defaults(method_name)
end
class FirstMailer < ActionMailer::Base
- def share(recipient)
- recipients recipient
+ def share
+ recipients 'test@localhost'
subject "using helpers"
from "tester@example.com"
end
end
class SecondMailer < ActionMailer::Base
- def share(recipient)
- recipients recipient
+ def share
+ recipients 'test@localhost'
subject "using helpers"
from "tester@example.com"
end
@@ -96,37 +96,37 @@ def teardown
end
def test_implicit_body
- mail = RenderMailer.create_implicit_body(@recipient)
+ mail = RenderMailer.implicit_body
assert_equal "Hello there, \n\nMr. test@localhost", mail.body.to_s.strip
end
def test_inline_template
- mail = RenderMailer.create_inline_template(@recipient)
+ mail = RenderMailer.inline_template
assert_equal "Hello, Earth", mail.body.to_s.strip
end
def test_file_template
- mail = RenderMailer.create_file_template(@recipient)
+ mail = RenderMailer.file_template
assert_equal "Hello there, \n\nMr. test@localhost", mail.body.to_s.strip
end
def test_rxml_template
- mail = RenderMailer.deliver_rxml_template(@recipient)
+ mail = RenderMailer.rxml_template.deliver
assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test/>", mail.body.to_s.strip
end
def test_included_subtemplate
- mail = RenderMailer.deliver_included_subtemplate(@recipient)
+ mail = RenderMailer.included_subtemplate.deliver
assert_equal "Hey Ho, let's go!", mail.body.to_s.strip
end
def test_mailer_accessor
- mail = RenderMailer.deliver_mailer_accessor(@recipient)
+ mail = RenderMailer.mailer_accessor.deliver
assert_equal "Look, Mailer Accessor!", mail.body.to_s.strip
end
def test_no_instance_variable
- mail = RenderMailer.deliver_no_instance_variable(@recipient)
+ mail = RenderMailer.no_instance_variable.deliver
assert_equal "Look, subject.nil? is true!", mail.body.to_s.strip
end
end
@@ -145,13 +145,13 @@ def teardown
end
def test_ordering
- mail = FirstMailer.create_share(@recipient)
+ mail = FirstMailer.share
assert_equal "first mail", mail.body.to_s.strip
- mail = SecondMailer.create_share(@recipient)
+ mail = SecondMailer.share
assert_equal "second mail", mail.body.to_s.strip
- mail = FirstMailer.create_share(@recipient)
+ mail = FirstMailer.share
assert_equal "first mail", mail.body.to_s.strip
- mail = SecondMailer.create_share(@recipient)
+ mail = SecondMailer.share
assert_equal "second mail", mail.body.to_s.strip
end
end
View
148 actionmailer/test/mail_service_test.rb
@@ -120,11 +120,11 @@ def multipart_with_mime_version(recipient)
content_type "multipart/alternative"
part "text/plain" do |p|
- p.body = render_message(:text => "blah")
+ p.body = render(:text => "blah")
end
part "text/html" do |p|
- p.body = render_message(:inline => "<%= content_tag(:b, 'blah') %>")
+ p.body = render(:inline => "<%= content_tag(:b, 'blah') %>")
end
end
@@ -297,7 +297,7 @@ def return_path
recipients "no.one@nowhere.test"
subject "return path test"
from "some.one@somewhere.test"
- headers "return-path" => "another@somewhere.test"
+ headers["return-path"] = "another@somewhere.test"
render :text => "testing"
end
@@ -350,7 +350,7 @@ def teardown
def test_nested_parts
created = nil
- assert_nothing_raised { created = TestMailer.create_nested_multipart(@recipient)}
+ assert_nothing_raised { created = TestMailer.nested_multipart(@recipient)}
assert_equal 2, created.parts.size
assert_equal 2, created.parts.first.parts.size
@@ -366,8 +366,8 @@ def test_nested_parts
def test_nested_parts_with_body
created = nil
- TestMailer.create_nested_multipart_with_body(@recipient)
- assert_nothing_raised { created = TestMailer.create_nested_multipart_with_body(@recipient)}
+ TestMailer.nested_multipart_with_body(@recipient)
+ assert_nothing_raised { created = TestMailer.nested_multipart_with_body(@recipient)}
assert_equal 1,created.parts.size
assert_equal 2,created.parts.first.parts.size
@@ -382,7 +382,7 @@ def test_nested_parts_with_body
def test_attachment_with_custom_header
created = nil
- assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient) }
+ assert_nothing_raised { created = TestMailer.attachment_with_custom_header(@recipient) }
assert created.parts.any? { |p| p.header['content-id'].to_s == "<test@test.com>" }
end
@@ -397,15 +397,15 @@ def test_signed_up
expected.date = Time.now
created = nil
- assert_nothing_raised { created = TestMailer.create_signed_up(@recipient) }
+ assert_nothing_raised { created = TestMailer.signed_up(@recipient) }
assert_not_nil created
expected.message_id = '<123@456>'
created.message_id = '<123@456>'
assert_equal expected.encoded, created.encoded
- assert_nothing_raised { TestMailer.deliver_signed_up(@recipient) }
+ assert_nothing_raised { TestMailer.signed_up(@recipient).deliver }
delivered = ActionMailer::Base.deliveries.first
assert_not_nil delivered
@@ -425,7 +425,7 @@ def test_custom_template
expected.date = Time.local(2004, 12, 12)
created = nil
- assert_nothing_raised { created = TestMailer.create_custom_template(@recipient) }
+ assert_nothing_raised { created = TestMailer.custom_template(@recipient) }
assert_not_nil created
expected.message_id = '<123@456>'
created.message_id = '<123@456>'
@@ -448,7 +448,7 @@ def test_custom_templating_extension
# Now that the template is registered, there should be one part. The text/plain part.
created = nil
- assert_nothing_raised { created = TestMailer.create_custom_templating_extension(@recipient) }
+ assert_nothing_raised { created = TestMailer.custom_templating_extension(@recipient) }
assert_not_nil created
assert_equal 2, created.parts.length
assert_equal 'text/plain', created.parts[0].mime_type
@@ -464,13 +464,13 @@ def test_cancelled_account
expected.date = Time.local(2004, 12, 12)
created = nil
- assert_nothing_raised { created = TestMailer.create_cancelled_account(@recipient) }
+ assert_nothing_raised { created = TestMailer.cancelled_account(@recipient) }
assert_not_nil created
expected.message_id = '<123@456>'
created.message_id = '<123@456>'
assert_equal expected.encoded, created.encoded
- assert_nothing_raised { TestMailer.deliver_cancelled_account(@recipient) }
+ assert_nothing_raised { TestMailer.cancelled_account(@recipient).deliver }
assert_not_nil ActionMailer::Base.deliveries.first
delivered = ActionMailer::Base.deliveries.first
expected.message_id = '<123@456>'
@@ -491,15 +491,15 @@ def test_cc_bcc
created = nil
assert_nothing_raised do
- created = TestMailer.create_cc_bcc @recipient
+ created = TestMailer.cc_bcc @recipient
end
assert_not_nil created
expected.message_id = '<123@456>'
created.message_id = '<123@456>'
assert_equal expected.encoded, created.encoded
assert_nothing_raised do
- TestMailer.deliver_cc_bcc @recipient
+ TestMailer.cc_bcc(@recipient).deliver
end
assert_not_nil ActionMailer::Base.deliveries.first
@@ -512,7 +512,7 @@ def test_cc_bcc
def test_from_without_name_for_smtp
ActionMailer::Base.delivery_method = :smtp
- TestMailer.deliver_from_without_name
+ TestMailer.from_without_name.deliver
mail = MockSMTP.deliveries.first
assert_not_nil mail
@@ -523,7 +523,7 @@ def test_from_without_name_for_smtp
def test_from_with_name_for_smtp
ActionMailer::Base.delivery_method = :smtp
- TestMailer.deliver_from_with_name
+ TestMailer.from_with_name.deliver
mail = MockSMTP.deliveries.first
assert_not_nil mail
@@ -544,7 +544,7 @@ def test_reply_to
created = nil
assert_nothing_raised do
- created = TestMailer.create_different_reply_to @recipient
+ created = TestMailer.different_reply_to @recipient
end
assert_not_nil created
@@ -554,7 +554,7 @@ def test_reply_to
assert_equal expected.encoded, created.encoded
assert_nothing_raised do
- TestMailer.deliver_different_reply_to @recipient
+ TestMailer.different_reply_to(@recipient).deliver
end
delivered = ActionMailer::Base.deliveries.first
@@ -578,7 +578,7 @@ def test_iso_charset
created = nil
assert_nothing_raised do
- created = TestMailer.create_iso_charset @recipient
+ created = TestMailer.iso_charset @recipient
end
assert_not_nil created
@@ -588,7 +588,7 @@ def test_iso_charset
assert_equal expected.encoded, created.encoded
assert_nothing_raised do
- TestMailer.deliver_iso_charset @recipient
+ TestMailer.iso_charset(@recipient).deliver
end
delivered = ActionMailer::Base.deliveries.first
@@ -612,7 +612,7 @@ def test_unencoded_subject
created = nil
assert_nothing_raised do
- created = TestMailer.create_unencoded_subject @recipient
+ created = TestMailer.unencoded_subject @recipient
end
assert_not_nil created
@@ -622,7 +622,7 @@ def test_unencoded_subject
assert_equal expected.encoded, created.encoded
assert_nothing_raised do
- TestMailer.deliver_unencoded_subject @recipient
+ TestMailer.unencoded_subject(@recipient).deliver
end
delivered = ActionMailer::Base.deliveries.first
@@ -634,38 +634,33 @@ def test_unencoded_subject
assert_equal expected.encoded, delivered.encoded
end
- def test_instances_are_nil
- assert_nil ActionMailer::Base.new
- assert_nil TestMailer.new
- end
-
def test_deliveries_array
assert_not_nil ActionMailer::Base.deliveries
assert_equal 0, ActionMailer::Base.deliveries.size
- TestMailer.deliver_signed_up(@recipient)
+ TestMailer.signed_up(@recipient).deliver
assert_equal 1, ActionMailer::Base.deliveries.size
assert_not_nil ActionMailer::Base.deliveries.first
end
def test_perform_deliveries_flag
ActionMailer::Base.perform_deliveries = false
- TestMailer.deliver_signed_up(@recipient)
+ TestMailer.signed_up(@recipient).deliver
assert_equal 0, ActionMailer::Base.deliveries.size
ActionMailer::Base.perform_deliveries = true
- TestMailer.deliver_signed_up(@recipient)
+ TestMailer.signed_up(@recipient).deliver
assert_equal 1, ActionMailer::Base.deliveries.size
end
def test_doesnt_raise_errors_when_raise_delivery_errors_is_false
ActionMailer::Base.raise_delivery_errors = false
Mail::TestMailer.any_instance.expects(:deliver!).raises(Exception)
- assert_nothing_raised { TestMailer.deliver_signed_up(@recipient) }
+ assert_nothing_raised { TestMailer.signed_up(@recipient).deliver }
end
def test_performs_delivery_via_sendmail
IO.expects(:popen).once.with('/usr/sbin/sendmail -i -t -f "system@loudthinking.com" test@localhost', 'w+')
ActionMailer::Base.delivery_method = :sendmail
- TestMailer.deliver_signed_up(@recipient)
+ TestMailer.signed_up(@recipient).deliver
end
def test_unquote_quoted_printable_subject
@@ -750,7 +745,7 @@ def test_extended_headers
created = nil
assert_nothing_raised do
- created = TestMailer.create_extended_headers @recipient
+ created = TestMailer.extended_headers @recipient
end
assert_not_nil created
@@ -760,7 +755,7 @@ def test_extended_headers
assert_equal expected.encoded, created.encoded
assert_nothing_raised do
- TestMailer.deliver_extended_headers @recipient
+ TestMailer.extended_headers(@recipient).deliver
end
delivered = ActionMailer::Base.deliveries.first
@@ -783,7 +778,7 @@ def test_utf8_body_is_not_quoted
expected.bcc = quote_address_if_necessary @recipient, "utf-8"
expected.date = Time.local 2004, 12, 12
- created = TestMailer.create_utf8_body @recipient
+ created = TestMailer.utf8_body @recipient
assert_match(/åœö blah/, created.encoded)
end
@@ -798,7 +793,7 @@ def test_multiple_utf8_recipients
expected.bcc = quote_address_if_necessary @recipient, "utf-8"
expected.date = Time.local 2004, 12, 12
- created = TestMailer.create_utf8_body @recipient
+ created = TestMailer.utf8_body @recipient
assert_match(/\nFrom: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>\r/, created.encoded)
assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>, \r\n\tExample Recipient <me/, created.encoded)
end
@@ -813,7 +808,7 @@ def test_receive_attachments
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email2")
mail = Mail.new(fixture)
attachment = mail.attachments.last
- assert_equal "smime.p7s", attachment.original_filename
+ assert_equal "smime.p7s", attachment.filename
assert_equal "application/pkcs7-signature", mail.parts.last.mime_type
end
@@ -828,15 +823,15 @@ def test_attachment_using_content_location
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email12")
mail = Mail.new(fixture)
assert_equal 1, mail.attachments.length
- assert_equal "Photo25.jpg", mail.attachments.first.original_filename
+ assert_equal "Photo25.jpg", mail.attachments.first.filename
end
def test_attachment_with_text_type
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email13")
mail = Mail.new(fixture)
assert mail.has_attachments?
assert_equal 1, mail.attachments.length
- assert_equal "hello.rb", mail.attachments.first.original_filename
+ assert_equal "hello.rb", mail.attachments.first.filename
end
def test_decode_part_without_content_type
@@ -858,22 +853,22 @@ def test_decode_message_with_incorrect_charset
end
def test_multipart_with_mime_version
- mail = TestMailer.create_multipart_with_mime_version(@recipient)
+ mail = TestMailer.multipart_with_mime_version(@recipient)
assert_equal "1.1", mail.mime_version
end
def test_multipart_with_utf8_subject
- mail = TestMailer.create_multipart_with_utf8_subject(@recipient)
+ mail = TestMailer.multipart_with_utf8_subject(@recipient)
assert_match(/\nSubject: =\?utf-8\?Q\?Foo_.*?\?=/, mail.encoded)
end
def test_implicitly_multipart_with_utf8
- mail = TestMailer.create_implicitly_multipart_with_utf8
+ mail = TestMailer.implicitly_multipart_with_utf8
assert_match(/\nSubject: =\?utf-8\?Q\?Foo_.*?\?=/, mail.encoded)
end
def test_explicitly_multipart_messages
- mail = TestMailer.create_explicitly_multipart_example(@recipient)
+ mail = TestMailer.explicitly_multipart_example(@recipient)
assert_equal 3, mail.parts.length
assert_equal 'multipart/mixed', mail.mime_type
assert_equal "text/plain", mail.parts[0].mime_type
@@ -890,21 +885,21 @@ def test_explicitly_multipart_messages
end
def test_explicitly_multipart_with_content_type
- mail = TestMailer.create_explicitly_multipart_example(@recipient, "multipart/alternative")
+ mail = TestMailer.explicitly_multipart_example(@recipient, "multipart/alternative")
assert_equal 3, mail.parts.length
assert_equal "multipart/alternative", mail.mime_type
end
def test_explicitly_multipart_with_invalid_content_type
- mail = TestMailer.create_explicitly_multipart_example(@recipient, "text/xml")
+ mail = TestMailer.explicitly_multipart_example(@recipient, "text/xml")
assert_equal 3, mail.parts.length
assert_equal 'multipart/mixed', mail.mime_type
end
def test_implicitly_multipart_messages
assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered"
- mail = TestMailer.create_implicitly_multipart_example(@recipient)
+ mail = TestMailer.implicitly_multipart_example(@recipient)
assert_equal 3, mail.parts.length
assert_equal "1.0", mail.mime_version.to_s
assert_equal "multipart/alternative", mail.mime_type
@@ -919,15 +914,15 @@ def test_implicitly_multipart_messages
def test_implicitly_multipart_messages_with_custom_order
assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered"
- mail = TestMailer.create_implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"])
+ mail = TestMailer.implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"])
assert_equal 3, mail.parts.length
assert_equal "application/x-yaml", mail.parts[0].mime_type
assert_equal "text/plain", mail.parts[1].mime_type
assert_equal "text/html", mail.parts[2].mime_type
end
def test_implicitly_multipart_messages_with_charset
- mail = TestMailer.create_implicitly_multipart_example(@recipient, 'iso-8859-1')
+ mail = TestMailer.implicitly_multipart_example(@recipient, 'iso-8859-1')
assert_equal "multipart/alternative", mail.header['content-type'].content_type
@@ -937,23 +932,23 @@ def test_implicitly_multipart_messages_with_charset
end
def test_html_mail
- mail = TestMailer.create_html_mail(@recipient)
+ mail = TestMailer.html_mail(@recipient)
assert_equal "text/html", mail.mime_type
end
def test_html_mail_with_underscores
- mail = TestMailer.create_html_mail_with_underscores(@recipient)
+ mail = TestMailer.html_mail_with_underscores(@recipient)
assert_equal %{<a href="http://google.com" target="_blank">_Google</a>}, mail.body.to_s
end
def test_various_newlines
- mail = TestMailer.create_various_newlines(@recipient)
+ mail = TestMailer.various_newlines(@recipient)
assert_equal("line #1\nline #2\nline #3\nline #4\n\n" +
"line #5\n\nline#6\n\nline #7", mail.body.to_s)
end
def test_various_newlines_multipart
- mail = TestMailer.create_various_newlines_multipart(@recipient)
+ mail = TestMailer.various_newlines_multipart(@recipient)
assert_equal "line #1\nline #2\nline #3\nline #4\n\n", mail.parts[0].body.to_s
assert_equal "<p>line #1</p>\n<p>line #2</p>\n<p>line #3</p>\n<p>line #4</p>\n\n", mail.parts[1].body.to_s
assert_equal "line #1\r\nline #2\r\nline #3\r\nline #4\r\n\r\n", mail.parts[0].body.encoded
@@ -962,7 +957,7 @@ def test_various_newlines_multipart
def test_headers_removed_on_smtp_delivery
ActionMailer::Base.delivery_method = :smtp
- TestMailer.deliver_cc_bcc(@recipient)
+ TestMailer.cc_bcc(@recipient).deliver
assert MockSMTP.deliveries[0][2].include?("root@loudthinking.com")
assert MockSMTP.deliveries[0][2].include?("nobody@loudthinking.com")
assert MockSMTP.deliveries[0][2].include?(@recipient)
@@ -975,7 +970,7 @@ def test_file_delivery_should_create_a_file
ActionMailer::Base.delivery_method = :file
tmp_location = ActionMailer::Base.file_settings[:location]
- TestMailer.deliver_cc_bcc(@recipient)
+ TestMailer.cc_bcc(@recipient).deliver
assert File.exists?(tmp_location)
assert File.directory?(tmp_location)
assert File.exists?(File.join(tmp_location, @recipient))
@@ -1002,12 +997,12 @@ def test_decode_encoded_attachment_filename
expected = "01 Quien Te Dij\212at. Pitbull.mp3"
if expected.respond_to?(:force_encoding)
- result = attachment.original_filename.dup
+ result = attachment.filename.dup
expected.force_encoding(Encoding::ASCII_8BIT)
result.force_encoding(Encoding::ASCII_8BIT)
assert_equal expected, result
else
- assert_equal expected, attachment.original_filename
+ assert_equal expected, attachment.filename
end
end
@@ -1018,13 +1013,13 @@ def test_decode_message_with_unknown_charset
end
def test_empty_header_values_omitted
- result = TestMailer.create_unnamed_attachment(@recipient).encoded
+ result = TestMailer.unnamed_attachment(@recipient).encoded
assert_match %r{Content-Type: application/octet-stream;}, result
assert_match %r{Content-Disposition: attachment;}, result
end
def test_headers_with_nonalpha_chars
- mail = TestMailer.create_headers_with_nonalpha_chars(@recipient)
+ mail = TestMailer.headers_with_nonalpha_chars(@recipient)
assert !mail.from_addrs.empty?
assert !mail.cc_addrs.empty?
assert !mail.bcc_addrs.empty?
@@ -1033,33 +1028,33 @@ def test_headers_with_nonalpha_chars
assert_match(/:/, mail[:bcc].decoded)
end
- def test_deliver_with_mail_object
- mail = TestMailer.create_headers_with_nonalpha_chars(@recipient)
- assert_nothing_raised { TestMailer.deliver(mail) }
+ def test_with_mail_object_deliver
+ mail = TestMailer.headers_with_nonalpha_chars(@recipient)
+ assert_nothing_raised { mail.deliver }
assert_equal 1, TestMailer.deliveries.length
end
def test_multipart_with_template_path_with_dots
- mail = FunkyPathMailer.create_multipart_with_template_path_with_dots(@recipient)
+ mail = FunkyPathMailer.multipart_with_template_path_with_dots(@recipient)
assert_equal 2, mail.parts.length
assert "text/plain", mail.parts[1].mime_type
assert "utf-8", mail.parts[1].charset
end
def test_custom_content_type_attributes
- mail = TestMailer.create_custom_content_type_attributes
+ mail = TestMailer.custom_content_type_attributes
assert_match %r{format=flowed}, mail.content_type
assert_match %r{charset=utf-8}, mail.content_type
end
def test_return_path_with_create
- mail = TestMailer.create_return_path
+ mail = TestMailer.return_path
assert_equal "another@somewhere.test", mail.return_path
end
def test_return_path_with_deliver
ActionMailer::Base.delivery_method = :smtp
- TestMailer.deliver_return_path
+ TestMailer.return_path.deliver
assert_match %r{^Return-Path: <another@somewhere.test>}, MockSMTP.deliveries[0][0]
assert_equal "another@somewhere.test", MockSMTP.deliveries[0][1].to_s
end
@@ -1069,24 +1064,24 @@ def test_starttls_is_enabled_if_supported
MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(true)
MockSMTP.any_instance.expects(:enable_starttls_auto)
ActionMailer::Base.delivery_method = :smtp
- TestMailer.deliver_signed_up(@recipient)
+ TestMailer.signed_up(@recipient).deliver
end
def test_starttls_is_disabled_if_not_supported
ActionMailer::Base.delivery_settings[:smtp].merge!(:enable_starttls_auto => true)
MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(false)
MockSMTP.any_instance.expects(:enable_starttls_auto).never
ActionMailer::Base.delivery_method = :smtp
- TestMailer.deliver_signed_up(@recipient)
+ TestMailer.signed_up(@recipient).deliver
end
def test_starttls_is_not_enabled
- ActionMailer::Base.delivery_settings[:smtp].merge!(:enable_starttls_auto => false)
+ TestMailer.delivery_settings[:smtp].merge!(:enable_starttls_auto => false)
MockSMTP.any_instance.expects(:respond_to?).never
- ActionMailer::Base.delivery_method = :smtp
- TestMailer.deliver_signed_up(@recipient)
+ TestMailer.delivery_method = :smtp
+ TestMailer.signed_up(@recipient).deliver
ensure
- ActionMailer::Base.delivery_settings[:smtp].merge!(:enable_starttls_auto => true)
+ TestMailer.delivery_settings[:smtp].merge!(:enable_starttls_auto => true)
end
end
@@ -1103,7 +1098,7 @@ def test_attr
end
end
-class MethodNamingTest < Test::Unit::TestCase
+class MethodNamingTest < ActiveSupport::TestCase
class TestMailer < ActionMailer::Base
def send
render :text => 'foo'
@@ -1123,12 +1118,13 @@ def teardown
def test_send_method
assert_nothing_raised do
assert_emails 1 do
- TestMailer.deliver_send
+ assert_deprecated do
+ TestMailer.deliver_send
+ end
end
end
end
end
-
class RespondToTest < Test::Unit::TestCase
class RespondToMailer < ActionMailer::Base; end
@@ -1191,4 +1187,4 @@ def test_should_still_raise_exception_with_expected_message_when_calling_an_unde
assert_match(/undefined method.*not_a_method/, error.message)
end
-end
+end
View
18 actionmailer/test/subscriber_test.rb
@@ -24,21 +24,21 @@ def set_logger(logger)
end
def test_deliver_is_notified
- TestMailer.deliver_basic
+ TestMailer.basic.deliver
wait
- assert_equal 1, @logger.logged(:info).size
- assert_match /Sent mail to somewhere@example.com/, @logger.logged(:info).first
- assert_equal 1, @logger.logged(:debug).size
- assert_match /Hello world/, @logger.logged(:debug).first
+ assert_equal(1, @logger.logged(:info).size)
+ assert_match(/Sent mail to somewhere@example.com/, @logger.logged(:info).first)
+ assert_equal(1, @logger.logged(:debug).size)
+ assert_match(/Hello world/, @logger.logged(:debug).first)
end
def test_receive_is_notified
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email")
TestMailer.receive(fixture)
wait
- assert_equal 1, @logger.logged(:info).size
- assert_match /Received mail/, @logger.logged(:info).first
- assert_equal 1, @logger.logged(:debug).size
- assert_match /Jamis/, @logger.logged(:debug).first
+ assert_equal(1, @logger.logged(:info).size)
+ assert_match(/Received mail/, @logger.logged(:info).first)
+ assert_equal(1, @logger.logged(:debug).size)
+ assert_match(/Jamis/, @logger.logged(:debug).first)
end
end
View
24 actionmailer/test/test_helper_test.rb
@@ -44,51 +44,51 @@ def test_encode
def test_assert_emails
assert_nothing_raised do
assert_emails 1 do
- TestHelperMailer.deliver_test
+ TestHelperMailer.test.deliver
end
end
end
def test_repeated_assert_emails_calls
assert_nothing_raised do
assert_emails 1 do
- TestHelperMailer.deliver_test
+ TestHelperMailer.test.deliver
end
end
assert_nothing_raised do
assert_emails 2 do
- TestHelperMailer.deliver_test
- TestHelperMailer.deliver_test
+ TestHelperMailer.test.deliver
+ TestHelperMailer.test.deliver
end
end
end
def test_assert_emails_with_no_block
assert_nothing_raised do
- TestHelperMailer.deliver_test
+ TestHelperMailer.test.deliver
assert_emails 1
end
assert_nothing_raised do
- TestHelperMailer.deliver_test
- TestHelperMailer.deliver_test
+ TestHelperMailer.test.deliver
+ TestHelperMailer.test.deliver
assert_emails 3
end
end
def test_assert_no_emails
assert_nothing_raised do
assert_no_emails do
- TestHelperMailer.create_test
+ TestHelperMailer.test
end
end
end
def test_assert_emails_too_few_sent
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_emails 2 do
- TestHelperMailer.deliver_test
+ TestHelperMailer.test.deliver
end
end
@@ -98,8 +98,8 @@ def test_assert_emails_too_few_sent
def test_assert_emails_too_many_sent
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_emails 1 do
- TestHelperMailer.deliver_test
- TestHelperMailer.deliver_test
+ TestHelperMailer.test.deliver
+ TestHelperMailer.test.deliver
end
end
@@ -109,7 +109,7 @@ def test_assert_emails_too_many_sent
def test_assert_no_emails_failure
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_no_emails do
- TestHelperMailer.deliver_test
+ TestHelperMailer.test.deliver
end
end
View
14 actionmailer/test/tmail_compat_test.rb
@@ -1,19 +1,23 @@
require 'abstract_unit'
-class TmailCompatTest < Test::Unit::TestCase
+class TmailCompatTest < ActiveSupport::TestCase
def test_set_content_type_raises_deprecation_warning
mail = Mail.new
- assert_nothing_raised do
- mail.set_content_type "text/plain"
+ assert_deprecated do
+ assert_nothing_raised do
+ mail.set_content_type "text/plain"
+ end
end
assert_equal mail.mime_type, "text/plain"
end
def test_transfer_encoding_raises_deprecation_warning
mail = Mail.new
- assert_nothing_raised do
- mail.transfer_encoding "base64"
+ assert_deprecated do
+ assert_nothing_raised do
+ mail.transfer_encoding "base64"
+ end
end
assert_equal mail.content_transfer_encoding, "base64"
end
View
4 actionmailer/test/url_test.rb
@@ -67,14 +67,14 @@ def test_signed_up_with_url
expected.date = Time.local(2004, 12, 12)
created = nil
- assert_nothing_raised { created = TestMailer.create_signed_up_with_url(@recipient) }
+ assert_nothing_raised { created = TestMailer.signed_up_with_url(@recipient) }
assert_not_nil created
expected.message_id = '<123@456>'
created.message_id = '<123@456>'
assert_equal expected.encoded, created.encoded
- assert_nothing_raised { TestMailer.deliver_signed_up_with_url(@recipient) }
+ assert_nothing_raised { TestMailer.signed_up_with_url(@recipient).deliver }
assert_not_nil ActionMailer::Base.deliveries.first
delivered = ActionMailer::Base.deliveries.first

0 comments on commit f30d73b

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