aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-12-29 15:46:12 -0800
committerJeremy Kemper <jeremy@bitsweat.net>2009-12-29 15:46:12 -0800
commitb27a3e8da39484d8a02d3b9c1e4dc3cb60ddcce7 (patch)
tree372a4af6df43eb8bed19c11e55b2f70907d60507 /actionmailer
parentada895e8cac855a2f248aafdb92457365f062d07 (diff)
parentb354496bda901cb0af499d6f3dff17a96a834a67 (diff)
downloadrails-b27a3e8da39484d8a02d3b9c1e4dc3cb60ddcce7.tar.gz
rails-b27a3e8da39484d8a02d3b9c1e4dc3cb60ddcce7.tar.bz2
rails-b27a3e8da39484d8a02d3b9c1e4dc3cb60ddcce7.zip
Merge branch 'master' of git://github.com/mikel/rails into mail
Conflicts: actionmailer/lib/action_mailer.rb
Diffstat (limited to 'actionmailer')
-rw-r--r--actionmailer/CHANGELOG9
-rw-r--r--actionmailer/Rakefile1
-rw-r--r--actionmailer/lib/action_mailer.rb39
-rw-r--r--actionmailer/lib/action_mailer/adv_attr_accessor.rb32
-rw-r--r--actionmailer/lib/action_mailer/base.rb234
-rw-r--r--actionmailer/lib/action_mailer/delivery_method.rb5
-rw-r--r--actionmailer/lib/action_mailer/delivery_method/file.rb2
-rw-r--r--actionmailer/lib/action_mailer/delivery_method/smtp.rb4
-rw-r--r--actionmailer/lib/action_mailer/deprecated_body.rb8
-rw-r--r--actionmailer/lib/action_mailer/mail_helper.rb33
-rw-r--r--actionmailer/lib/action_mailer/rails.rb24
-rw-r--r--actionmailer/lib/action_mailer/test_case.rb1
-rw-r--r--actionmailer/test/abstract_unit.rb7
-rw-r--r--actionmailer/test/adv_attr_test.rb32
-rw-r--r--actionmailer/test/asset_host_test.rb6
-rw-r--r--actionmailer/test/mail_helper_test.rb2
-rw-r--r--actionmailer/test/mail_layout_test.rb22
-rw-r--r--actionmailer/test/mail_render_test.rb57
-rw-r--r--actionmailer/test/mail_service_test.rb96
-rw-r--r--actionmailer/test/mail_test.rb (renamed from actionmailer/test/tmail_test.rb)6
-rw-r--r--actionmailer/test/quoting_test.rb2
-rw-r--r--actionmailer/test/test_helper_test.rb6
-rw-r--r--actionmailer/test/url_test.rb54
23 files changed, 366 insertions, 316 deletions
diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG
index 9b07686b64..dc2d5f7314 100644
--- a/actionmailer/CHANGELOG
+++ b/actionmailer/CHANGELOG
@@ -1,10 +1,17 @@
*Mail Integration
+* ActionMailer::Base :default_implicit_parts_order now is in the sequence of the order you want, no
+reversing of ordering takes place. The default order now is text/plain, then text/enriched, then
+text/html and then any other part that is not one of these three.
+
* Mail does not have "quoted_body", "quoted_subject" etc. All of these are accessed via body.encoded,
subject.encoded etc
* Every part of a Mail object returns an object, never a string. So Mail.body returns a Mail::Body
- class object, need to call #encoded or #decoded to get the string you want
+ class object, need to call #encoded or #decoded to get the string you want.
+
+* By default, a field will return the #decoded value when you send it :to_s and any object that
+ is a container (like header, body etc) will return #encoded value when you send it :to_s
* Mail::Message#set_content_type does not exist, it is simply Mail::Message#content_type
diff --git a/actionmailer/Rakefile b/actionmailer/Rakefile
index 1a7ece5068..6c19371514 100644
--- a/actionmailer/Rakefile
+++ b/actionmailer/Rakefile
@@ -23,7 +23,6 @@ task :default => [ :test ]
Rake::TestTask.new { |t|
t.libs << "test"
t.pattern = 'test/*_test.rb'
- t.verbose = true
t.warning = true
}
diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb
index 0ca08e4d1f..55ddbb24f4 100644
--- a/actionmailer/lib/action_mailer.rb
+++ b/actionmailer/lib/action_mailer.rb
@@ -21,36 +21,27 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-actionpack_path = "#{File.dirname(__FILE__)}/../../actionpack/lib"
-$:.unshift(actionpack_path) if File.directory?(actionpack_path)
+actionpack_path = File.expand_path('../../../actionpack/lib', __FILE__)
+$:.unshift(actionpack_path) if File.directory?(actionpack_path) && !$:.include?(actionpack_path)
+
require 'action_controller'
require 'action_view'
module ActionMailer
- def self.load_all!
- [Base, Part, ::Text::Format, ::Net::SMTP]
- end
-
- autoload :AdvAttrAccessor, 'action_mailer/adv_attr_accessor'
- autoload :DeprecatedBody, 'action_mailer/deprecated_body'
- autoload :Base, 'action_mailer/base'
- autoload :DeliveryMethod, 'action_mailer/delivery_method'
- autoload :Part, 'action_mailer/part'
- autoload :PartContainer, 'action_mailer/part_container'
- autoload :Quoting, 'action_mailer/quoting'
- autoload :TestCase, 'action_mailer/test_case'
- autoload :TestHelper, 'action_mailer/test_helper'
-
+ extend ::ActiveSupport::Autoload
+
+ autoload :AdvAttrAccessor
+ autoload :Base
+ autoload :DeliveryMethod
+ autoload :DeprecatedBody
+ autoload :MailHelper
+ autoload :Quoting
+ autoload :TestCase
+ autoload :TestHelper
end
module Text
- autoload :Format, 'action_mailer/vendor/text_format'
-end
+ extend ActiveSupport::Autoload
-module Net
- autoload :SMTP, 'net/smtp'
+ autoload :Format, 'action_mailer/vendor/text_format'
end
-
-autoload :MailHelper, 'action_mailer/mail_helper'
-
-require 'mail'
diff --git a/actionmailer/lib/action_mailer/adv_attr_accessor.rb b/actionmailer/lib/action_mailer/adv_attr_accessor.rb
index e77029afdd..be6b1feca9 100644
--- a/actionmailer/lib/action_mailer/adv_attr_accessor.rb
+++ b/actionmailer/lib/action_mailer/adv_attr_accessor.rb
@@ -1,29 +1,25 @@
module ActionMailer
module AdvAttrAccessor #:nodoc:
- def self.included(base)
- base.extend(ClassMethods)
- end
-
- module ClassMethods #:nodoc:
- def adv_attr_accessor(*names)
- names.each do |name|
- ivar = "@#{name}"
+ def adv_attr_accessor(*names)
+ names.each do |name|
+ ivar = "@#{name}"
- define_method("#{name}=") do |value|
- instance_variable_set(ivar, value)
+ class_eval <<-ACCESSORS, __FILE__, __LINE__ + 1
+ def #{name}=(value)
+ #{ivar} = value
end
- define_method(name) do |*parameters|
- raise ArgumentError, "expected 0 or 1 parameters" unless parameters.length <= 1
- if parameters.empty?
- if instance_variable_names.include?(ivar)
- instance_variable_get(ivar)
- end
+ def #{name}(*args)
+ raise ArgumentError, "expected 0 or 1 parameters" unless args.length <= 1
+ if args.empty?
+ #{ivar} if instance_variable_names.include?(#{ivar.inspect})
else
- instance_variable_set(ivar, parameters.first)
+ #{ivar} = args.first
end
end
- end
+ ACCESSORS
+
+ self.protected_instance_variables << ivar if self.respond_to?(:protected_instance_variables)
end
end
end
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 3639992ce9..aea2498d4d 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -1,9 +1,9 @@
require 'active_support/core_ext/class'
+require 'mail'
module ActionMailer #:nodoc:
# Action Mailer allows you to send email from your application using a mailer model and views.
#
- #
# = Mailer Models
#
# To use Action Mailer, you need to create a mailer model.
@@ -22,7 +22,8 @@ module ActionMailer #:nodoc:
# bcc ["bcc@example.com", "Order Watcher <watcher@example.com>"]
# from "system@example.com"
# subject "New account information"
- # body :account => recipient
+ #
+ # @account = recipient
# end
# end
#
@@ -42,13 +43,6 @@ module ActionMailer #:nodoc:
# address. Setting this is useful when you want delivery notifications sent to a different address than
# the one in <tt>from</tt>.
#
- # The <tt>body</tt> method has special behavior. It takes a hash which generates an instance variable
- # named after each key in the hash containing the value that that key points to.
- #
- # So, for example, <tt>body :account => recipient</tt> would result
- # in an instance variable <tt>@account</tt> with the value of <tt>recipient</tt> being accessible in the
- # view.
- #
#
# = Mailer views
#
@@ -68,7 +62,12 @@ module ActionMailer #:nodoc:
# You can even use Action Pack helpers in these views. For example:
#
# You got a new note!
- # <%= truncate(note.body, 25) %>
+ # <%= truncate(@note.body, 25) %>
+ #
+ # If you need to access the subject, from or the recipients in the view, you can do that through mailer object:
+ #
+ # You got a new note from <%= mailer.from %>!
+ # <%= truncate(@note.body, 25) %>
#
#
# = Generating URLs
@@ -250,29 +249,22 @@ module ActionMailer #:nodoc:
# <tt>["text/html", "text/enriched", "text/plain"]</tt>. Items that appear first in the array have higher priority in the mail client
# 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
- include AdvAttrAccessor, Quoting
+ class Base < AbstractController::Base
+ include Quoting
+ extend AdvAttrAccessor
- include AbstractController::RenderingController
+ include AbstractController::Rendering
include AbstractController::LocalizedCache
include AbstractController::Layouts
-
include AbstractController::Helpers
- helper MailHelper
- if Object.const_defined?(:ActionController)
- include ActionController::UrlWriter
- end
+ helper ActionMailer::MailHelper
+ include ActionController::UrlWriter
include ActionMailer::DeprecatedBody
private_class_method :new #:nodoc:
- class_inheritable_accessor :view_paths
- self.view_paths = []
-
- cattr_accessor :logger
-
@@raise_delivery_errors = true
cattr_accessor :raise_delivery_errors
@@ -291,10 +283,16 @@ module ActionMailer #:nodoc:
@@default_mime_version = "1.0"
cattr_accessor :default_mime_version
- @@default_implicit_parts_order = [ "text/html", "text/enriched", "text/plain" ]
+ # This specifies the order that the parts of a multipart email will be. Usually you put
+ # text/plain at the top so someone without a MIME capable email reader can read the plain
+ # text of your email first.
+ #
+ # Any content type that is not listed here will be inserted in the order you add them to
+ # the email after the content types you list here.
+ @@default_implicit_parts_order = [ "text/plain", "text/enriched", "text/html" ]
cattr_accessor :default_implicit_parts_order
- @@protected_instance_variables = []
+ @@protected_instance_variables = %w(@parts @mail)
cattr_reader :protected_instance_variables
# Specify the BCC addresses for the message
@@ -344,57 +342,17 @@ module ActionMailer #:nodoc:
# have multiple mailer methods share the same template.
adv_attr_accessor :template
- # The mail and action_name instances referenced by this mailer.
- attr_reader :mail, :action_name
-
- # Where the response body is stored.
- attr_internal :response_body
-
# Override the mailer name, which defaults to an inflected version of the
# mailer's class name. If you want to use a template in a non-standard
# location, you can use this to specify that location.
- attr_writer :mailer_name
+ adv_attr_accessor :mailer_name
- def mailer_name(value = nil)
- if value
- @mailer_name = value
- else
- @mailer_name || self.class.mailer_name
- end
- end
+ # Expose the internal mail
+ attr_reader :mail
# Alias controller_path to mailer_name so render :partial in views work.
alias :controller_path :mailer_name
- # Add a part to a multipart message, with the given content-type. The
- # part itself is yielded to the block so that other properties (charset,
- # body, headers, etc.) can be set on it.
- def part(params)
- params = {:content_type => params} if String === params
- if custom_headers = params.delete(:headers)
- ActiveSupport::Deprecation.warn('Passing custom headers with :headers => {} is deprecated. ' <<
- 'Please just pass in custom headers directly.', caller[0,10])
- params.merge!(custom_headers)
- end
- part = Mail::Part.new(params)
- yield part if block_given?
- @parts << part
- end
-
- # Add an attachment to a multipart message. This is simply a part with the
- # content-disposition set to "attachment".
- def attachment(params, &block)
- params = { :content_type => params } if String === params
- params = { :content_disposition => "attachment",
- :content_transfer_encoding => "base64" }.merge(params)
- if params[:body]
- ActiveSupport::Deprecation.warn('attachment :body => "string" is deprecated. To set the body of an attachment ' <<
- 'please use :data instead, like attachment :data => "string".', caller[0,10])
- params[:data] = params.delete(:body)
- end
- part(params, &block)
- end
-
class << self
attr_writer :mailer_name
@@ -475,21 +433,47 @@ module ActionMailer #:nodoc:
superclass_delegating_reader :delivery_method
self.delivery_method = :smtp
+ # Add a part to a multipart message, with the given content-type. The
+ # part itself is yielded to the block so that other properties (charset,
+ # body, headers, etc.) can be set on it.
+ def part(params)
+ params = {:content_type => params} if String === params
+ if custom_headers = params.delete(:headers)
+ ActiveSupport::Deprecation.warn('Passing custom headers with :headers => {} is deprecated. ' <<
+ 'Please just pass in custom headers directly.', caller[0,10])
+ params.merge!(custom_headers)
+ end
+ part = Mail::Part.new(params)
+ yield part if block_given?
+ @parts << part
+ end
+
+ # Add an attachment to a multipart message. This is simply a part with the
+ # content-disposition set to "attachment".
+ def attachment(params, &block)
+ super # Run deprecation hooks
+
+ params = { :content_type => params } if String === params
+ params = { :content_disposition => "attachment",
+ :content_transfer_encoding => "base64" }.merge(params)
+
+ part(params, &block)
+ end
+
# Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
# will be initialized according to the named method. If not, the mailer will
# remain uninitialized (useful when you only need to invoke the "receive"
# method, for instance).
- def initialize(method_name=nil, *parameters) #:nodoc:
- @_response_body = nil
+ def initialize(method_name=nil, *args)
super()
- create!(method_name, *parameters) if method_name
+ process(method_name, *args) if method_name
end
- # Initialize the mailer via the given +method_name+. The body will be
+ # Process the mailer via the given +method_name+. The body will be
# rendered and a new Mail object created.
- def create!(method_name, *parameters) #:nodoc:
+ def process(method_name, *args)
initialize_defaults(method_name)
- __send__(method_name, *parameters)
+ super
# Create e-mail parts
create_parts
@@ -498,8 +482,8 @@ module ActionMailer #:nodoc:
@subject ||= I18n.t(:subject, :scope => [:actionmailer, mailer_name, method_name],
:default => method_name.humanize)
- # build the mail object itself
- @mail = create_mail
+ # Build the mail object itself
+ create_mail
end
# Delivers a Mail object. By default, it delivers the cached mail
@@ -513,7 +497,7 @@ module ActionMailer #:nodoc:
logger.debug "\n#{mail.encoded}"
end
- ActiveSupport::Notifications.instrument(:deliver_mail, :mail => @mail) do
+ ActiveSupport::Notifications.instrument(:deliver_mail, :mail => mail) do
begin
self.delivery_method.perform_delivery(mail) if perform_deliveries
rescue Exception => e # Net::SMTP errors or sendmail pipe errors
@@ -529,15 +513,14 @@ module ActionMailer #:nodoc:
# Set up the default values for the various instance variables of this
# mailer. Subclasses may override this method to provide different
# defaults.
- def initialize_defaults(method_name)
+ def initialize_defaults(method_name) #:nodoc:
@charset ||= @@default_charset.dup
@content_type ||= @@default_content_type.dup
@implicit_parts_order ||= @@default_implicit_parts_order.dup
@mime_version ||= @@default_mime_version.dup if @@default_mime_version
- @mailer_name ||= self.class.mailer_name
+ @mailer_name ||= self.class.mailer_name.dup
@template ||= method_name
- @action_name = @template
@parts ||= []
@headers ||= {}
@@ -546,29 +529,18 @@ module ActionMailer #:nodoc:
super # Run deprecation hooks
end
- def create_parts
+ def create_parts #:nodoc:
super # Run deprecation hooks
if String === response_body
- @parts.unshift Mail::Part.new(
- :content_type => ["text", "plain", {:charset => charset}],
- :content_disposition => "inline",
- :body => response_body
- )
+ @parts.unshift create_inline_part(response_body)
else
- self.class.template_root.find_all(@template, {}, mailer_name).each do |template|
- ct = template.mime_type ? template.mime_type.to_s : "text/plain"
- main_type, sub_type = ct.split("/")
- @parts << Mail::Part.new(
- :content_type => [main_type, sub_type, {:charset => charset}],
- :content_disposition => "inline",
- :body => render_to_body(:_template => template)
- )
+ self.class.template_root.find_all(@template, {}, @mailer_name).each do |template|
+ @parts << create_inline_part(render_to_body(:_template => template), template.mime_type)
end
if @parts.size > 1
@content_type = "multipart/alternative" if @content_type !~ /^multipart/
- @parts = sort_parts(@parts, @implicit_parts_order)
end
# If this is a multipart e-mail add the mime_version if it is not
@@ -577,36 +549,18 @@ module ActionMailer #:nodoc:
end
end
- def sort_parts(parts, order = [])
- order = order.collect { |s| s.downcase }
-
- parts = parts.sort do |a, b|
- a_ct = a.content_type.string.downcase
- b_ct = b.content_type.string.downcase
-
- a_in = order.include? a_ct
- b_in = order.include? b_ct
-
- s = case
- when a_in && b_in
- order.index(a_ct) <=> order.index(b_ct)
- when a_in
- -1
- when b_in
- 1
- else
- a_ct <=> b_ct
- end
+ def create_inline_part(body, mime_type=nil) #:nodoc:
+ ct = mime_type || "text/plain"
+ main_type, sub_type = split_content_type(ct.to_s)
- # reverse the ordering because parts that come last are displayed
- # first in mail clients
- (s * -1)
- end
-
- parts
+ Mail::Part.new(
+ :content_type => [main_type, sub_type, {:charset => charset}],
+ :content_disposition => "inline",
+ :body => body
+ )
end
- def create_mail
+ def create_mail #:nodoc:
m = Mail.new
m.subject, = quote_any_if_necessary(charset, subject)
@@ -620,13 +574,9 @@ module ActionMailer #:nodoc:
headers.each { |k, v| m[k] = v }
real_content_type, ctype_attrs = parse_content_type
-
- if @parts.empty?
- main_type, sub_type = split_content_type(real_content_type)
- m.content_type([main_type, sub_type, ctype_attrs])
- m.body = body
- elsif @parts.size == 1 && @parts.first.parts.empty?
- main_type, sub_type = split_content_type(real_content_type)
+ main_type, sub_type = split_content_type(real_content_type)
+
+ if @parts.size == 1 && @parts.first.parts.empty?
m.content_type([main_type, sub_type, ctype_attrs])
m.body = @parts.first.body.encoded
else
@@ -634,31 +584,33 @@ module ActionMailer #:nodoc:
m.add_part(p)
end
+ m.body.set_sort_order(@implicit_parts_order)
+ m.body.sort_parts!
+
if real_content_type =~ /multipart/
ctype_attrs.delete "charset"
- main_type, sub_type = split_content_type(real_content_type)
m.content_type([main_type, sub_type, ctype_attrs])
end
end
+ m.content_transfer_encoding = '8bit' unless m.body.only_us_ascii?
+
@mail = m
end
- def split_content_type(ct)
+ def split_content_type(ct) #:nodoc:
ct.to_s.split("/")
end
- def parse_content_type(defaults=nil)
- if content_type.blank?
- return defaults ?
- [ defaults.content_type, { 'charset' => defaults.charset } ] :
- [ nil, {} ]
- end
- ctype, *attrs = content_type.split(/;\s*/)
- attrs = attrs.inject({}) { |h,s| k,v = s.split(/=/, 2); h[k] = v; h }
- [ctype, {"charset" => charset || defaults && defaults.charset}.merge(attrs)]
+ def parse_content_type(defaults=nil) #:nodoc:
+ if @content_type.blank?
+ [ nil, {} ]
+ else
+ ctype, *attrs = @content_type.split(/;\s*/)
+ attrs = attrs.inject({}) { |h,s| k,v = s.split(/\=/, 2); h[k] = v; h }
+ [ctype, {"charset" => @charset}.merge(attrs)]
+ end
end
-
end
end
diff --git a/actionmailer/lib/action_mailer/delivery_method.rb b/actionmailer/lib/action_mailer/delivery_method.rb
index 29a51afdc3..4f7d3afc3c 100644
--- a/actionmailer/lib/action_mailer/delivery_method.rb
+++ b/actionmailer/lib/action_mailer/delivery_method.rb
@@ -1,7 +1,7 @@
-require "active_support/core_ext/class"
+require 'active_support/core_ext/class'
+
module ActionMailer
module DeliveryMethod
-
autoload :File, 'action_mailer/delivery_method/file'
autoload :Sendmail, 'action_mailer/delivery_method/sendmail'
autoload :Smtp, 'action_mailer/delivery_method/smtp'
@@ -52,6 +52,5 @@ module ActionMailer
superclass_delegating_accessor :settings
self.settings = {}
end
-
end
end
diff --git a/actionmailer/lib/action_mailer/delivery_method/file.rb b/actionmailer/lib/action_mailer/delivery_method/file.rb
index 99ef5bc76d..571e32df49 100644
--- a/actionmailer/lib/action_mailer/delivery_method/file.rb
+++ b/actionmailer/lib/action_mailer/delivery_method/file.rb
@@ -6,7 +6,7 @@ module ActionMailer
# A delivery method implementation which writes all mails to a file.
class File < Method
self.settings = {
- :location => defined?(Rails) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails"
+ :location => defined?(Rails.root) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails"
}
def perform_delivery(mail)
diff --git a/actionmailer/lib/action_mailer/delivery_method/smtp.rb b/actionmailer/lib/action_mailer/delivery_method/smtp.rb
index 9622dbb93a..af30c498b5 100644
--- a/actionmailer/lib/action_mailer/delivery_method/smtp.rb
+++ b/actionmailer/lib/action_mailer/delivery_method/smtp.rb
@@ -1,8 +1,9 @@
+require 'net/smtp'
+
module ActionMailer
module DeliveryMethod
# A delivery method implementation which sends via smtp.
class Smtp < Method
-
self.settings = {
:address => "localhost",
:port => 25,
@@ -25,6 +26,5 @@ module ActionMailer
end
end
end
-
end
end
diff --git a/actionmailer/lib/action_mailer/deprecated_body.rb b/actionmailer/lib/action_mailer/deprecated_body.rb
index 50ff262432..20b0989a85 100644
--- a/actionmailer/lib/action_mailer/deprecated_body.rb
+++ b/actionmailer/lib/action_mailer/deprecated_body.rb
@@ -15,6 +15,14 @@ module ActionMailer
@body ||= {}
end
+ def attachment(params, &block)
+ if params[:body]
+ ActiveSupport::Deprecation.warn('attachment :body => "string" is deprecated. To set the body of an attachment ' <<
+ 'please use :data instead, like attachment :data => "string".', caller[0,10])
+ params[:data] = params.delete(:body)
+ end
+ end
+
def create_parts
if String === @body
ActiveSupport::Deprecation.warn('body is deprecated. To set the body with a text ' <<
diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb
index 351b966abe..701dc34431 100644
--- a/actionmailer/lib/action_mailer/mail_helper.rb
+++ b/actionmailer/lib/action_mailer/mail_helper.rb
@@ -1,17 +1,24 @@
-module MailHelper
- # Uses Text::Format to take the text and format it, indented two spaces for
- # each line, and wrapped at 72 columns.
- def block_format(text)
- formatted = text.split(/\n\r\n/).collect { |paragraph|
- Text::Format.new(
- :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph
- ).format
- }.join("\n")
+module ActionMailer
+ module MailHelper
+ # Uses Text::Format to take the text and format it, indented two spaces for
+ # each line, and wrapped at 72 columns.
+ def block_format(text)
+ formatted = text.split(/\n\r\n/).collect { |paragraph|
+ Text::Format.new(
+ :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph
+ ).format
+ }.join("\n")
- # Make list points stand on their own line
- formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" }
- formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| " #{$1} #{$2.strip}\n" }
+ # Make list points stand on their own line
+ formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" }
+ formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| " #{$1} #{$2.strip}\n" }
+
+ formatted
+ end
- formatted
+ # Access the mailer instance.
+ def mailer #:nodoc:
+ @controller
+ end
end
end
diff --git a/actionmailer/lib/action_mailer/rails.rb b/actionmailer/lib/action_mailer/rails.rb
new file mode 100644
index 0000000000..a3573cdea7
--- /dev/null
+++ b/actionmailer/lib/action_mailer/rails.rb
@@ -0,0 +1,24 @@
+require "action_mailer"
+
+module ActionMailer
+ class Plugin < Rails::Plugin
+ plugin_name :action_mailer
+
+ initializer "action_mailer.set_configs" do |app|
+ app.config.action_mailer.each do |k,v|
+ ActionMailer::Base.send "#{k}=", v
+ end
+ end
+
+ # TODO: ActionController::Base.logger should delegate to its own config.logger
+ initializer "action_mailer.logger" do
+ ActionMailer::Base.logger ||= Rails.logger
+ end
+
+ initializer "action_mailer.view_paths" do |app|
+ # TODO: this should be combined with the logic for default config.action_mailer.view_paths
+ view_path = ActionView::PathSet.type_cast(app.config.view_path, app.config.cache_classes)
+ ActionMailer::Base.template_root = view_path if ActionMailer::Base.view_paths.blank?
+ end
+ end
+end \ No newline at end of file
diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb
index 49f6d680a2..445abd0b89 100644
--- a/actionmailer/lib/action_mailer/test_case.rb
+++ b/actionmailer/lib/action_mailer/test_case.rb
@@ -1,4 +1,5 @@
require 'active_support/test_case'
+require 'mail'
module ActionMailer
class NonInferrableMailerError < ::StandardError
diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb
index e84b3b0d23..af6f1bc92e 100644
--- a/actionmailer/test/abstract_unit.rb
+++ b/actionmailer/test/abstract_unit.rb
@@ -1,12 +1,9 @@
-root = File.expand_path('../../..', __FILE__)
begin
- require "#{root}/vendor/gems/environment"
+ require File.expand_path('../../../vendor/gems/environment', __FILE__)
rescue LoadError
- $:.unshift("#{root}/activesupport/lib")
- $:.unshift("#{root}/actionpack/lib")
end
-lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
+lib = File.expand_path('../../lib', __FILE__)
$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
require 'rubygems'
diff --git a/actionmailer/test/adv_attr_test.rb b/actionmailer/test/adv_attr_test.rb
index fd909a5627..f22d733bc5 100644
--- a/actionmailer/test/adv_attr_test.rb
+++ b/actionmailer/test/adv_attr_test.rb
@@ -1,18 +1,36 @@
require 'abstract_unit'
require 'action_mailer/adv_attr_accessor'
-class AdvAttrTest < Test::Unit::TestCase
+class AdvAttrTest < ActiveSupport::TestCase
class Person
- include ActionMailer::AdvAttrAccessor
+ cattr_reader :protected_instance_variables
+ @@protected_instance_variables = []
+
+ extend ActionMailer::AdvAttrAccessor
adv_attr_accessor :name
end
+ def setup
+ @person = Person.new
+ end
+
def test_adv_attr
- bob = Person.new
- assert_nil bob.name
- bob.name 'Bob'
- assert_equal 'Bob', bob.name
+ assert_nil @person.name
+ @person.name 'Bob'
+ assert_equal 'Bob', @person.name
+ end
+
+ def test_adv_attr_writer
+ assert_nil @person.name
+ @person.name = 'Bob'
+ assert_equal 'Bob', @person.name
+ end
+
+ def test_raise_an_error_with_multiple_args
+ assert_raise(ArgumentError) { @person.name('x', 'y') }
+ end
- assert_raise(ArgumentError) {bob.name 'x', 'y'}
+ def test_ivar_is_added_to_protected_instnace_variables
+ assert Person.protected_instance_variables.include?('@name')
end
end
diff --git a/actionmailer/test/asset_host_test.rb b/actionmailer/test/asset_host_test.rb
index 0b74fe8c24..f3383e5608 100644
--- a/actionmailer/test/asset_host_test.rb
+++ b/actionmailer/test/asset_host_test.rb
@@ -24,7 +24,7 @@ class AssetHostTest < Test::Unit::TestCase
def test_asset_host_as_string
ActionController::Base.asset_host = "http://www.example.com"
mail = AssetHostMailer.deliver_email_with_asset(@recipient)
- assert_equal "<img alt=\"Somelogo\" src=\"http://www.example.com/images/somelogo.png\" />", mail.body.decoded.strip
+ assert_equal "<img alt=\"Somelogo\" src=\"http://www.example.com/images/somelogo.png\" />", mail.body.to_s.strip
end
def test_asset_host_as_one_arguement_proc
@@ -36,7 +36,7 @@ class AssetHostTest < Test::Unit::TestCase
end
}
mail = AssetHostMailer.deliver_email_with_asset(@recipient)
- assert_equal "<img alt=\"Somelogo\" src=\"http://images.example.com/images/somelogo.png\" />", mail.body.decoded.strip
+ assert_equal "<img alt=\"Somelogo\" src=\"http://images.example.com/images/somelogo.png\" />", mail.body.to_s.strip
end
def test_asset_host_as_two_arguement_proc
@@ -49,6 +49,6 @@ class AssetHostTest < Test::Unit::TestCase
}
mail = nil
assert_nothing_raised { mail = AssetHostMailer.deliver_email_with_asset(@recipient) }
- assert_equal "<img alt=\"Somelogo\" src=\"http://www.example.com/images/somelogo.png\" />", mail.body.decoded.strip
+ assert_equal "<img alt=\"Somelogo\" src=\"http://www.example.com/images/somelogo.png\" />", mail.body.to_s.strip
end
end \ No newline at end of file
diff --git a/actionmailer/test/mail_helper_test.rb b/actionmailer/test/mail_helper_test.rb
index d04215171d..2d3565d159 100644
--- a/actionmailer/test/mail_helper_test.rb
+++ b/actionmailer/test/mail_helper_test.rb
@@ -56,7 +56,7 @@ end
class MailerHelperTest < Test::Unit::TestCase
def new_mail( charset="utf-8" )
mail = Mail.new
- mail.content_type(["text", "plain", { "charset" => charset }])
+ mail.set_content_type "text", "plain", { "charset" => charset } if charset
mail
end
diff --git a/actionmailer/test/mail_layout_test.rb b/actionmailer/test/mail_layout_test.rb
index 4775545039..84f13a6d3c 100644
--- a/actionmailer/test/mail_layout_test.rb
+++ b/actionmailer/test/mail_layout_test.rb
@@ -65,7 +65,7 @@ class LayoutMailerTest < Test::Unit::TestCase
def test_should_pickup_default_layout
mail = AutoLayoutMailer.create_hello(@recipient)
- assert_equal "Hello from layout Inside", mail.body.decoded.strip
+ assert_equal "Hello from layout Inside", mail.body.to_s.strip
end
def test_should_pickup_multipart_layout
@@ -81,7 +81,7 @@ class LayoutMailerTest < Test::Unit::TestCase
# CHANGED: body returns an object
# assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
- assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.decoded
+ assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s
# CHANGED: content_type returns an object
# assert_equal 'text/html', mail.parts.last.content_type
@@ -89,7 +89,7 @@ class LayoutMailerTest < Test::Unit::TestCase
# CHANGED: body returns an object
# assert_equal "Hello from layout text/html multipart", mail.parts.last.body
- assert_equal "Hello from layout text/html multipart", mail.parts.last.body.decoded
+ assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s
end
def test_should_pickup_multipartmixed_layout
@@ -104,14 +104,14 @@ class LayoutMailerTest < Test::Unit::TestCase
assert_equal 'text/plain', mail.parts.first.content_type.string
# CHANGED: body returns an object
# assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
- assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.decoded
+ assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s
# CHANGED: content_type returns an object
# assert_equal 'text/html', mail.parts.last.content_type
assert_equal 'text/html', mail.parts.last.content_type.string
# CHANGED: body returns an object
# assert_equal "Hello from layout text/html multipart", mail.parts.last.body
- assert_equal "Hello from layout text/html multipart", mail.parts.last.body.decoded
+ assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s
end
def test_should_fix_multipart_layout
@@ -120,30 +120,30 @@ class LayoutMailerTest < Test::Unit::TestCase
assert_equal 2, mail.parts.size
assert_equal 'text/plain', mail.parts.first.content_type.string
- assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.decoded
+ assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s
assert_equal 'text/html', mail.parts.last.content_type.string
- assert_equal "Hello from layout text/html multipart", mail.parts.last.body.decoded
+ assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s
end
def test_should_pickup_layout_given_to_render
mail = AutoLayoutMailer.create_spam(@recipient)
- assert_equal "Spammer layout Hello, Earth", mail.body.decoded.strip
+ assert_equal "Spammer layout Hello, Earth", mail.body.to_s.strip
end
def test_should_respect_layout_false
mail = AutoLayoutMailer.create_nolayout(@recipient)
- assert_equal "Hello, Earth", mail.body.decoded.strip
+ assert_equal "Hello, Earth", mail.body.to_s.strip
end
def test_explicit_class_layout
mail = ExplicitLayoutMailer.create_signup(@recipient)
- assert_equal "Spammer layout We do not spam", mail.body.decoded.strip
+ assert_equal "Spammer layout We do not spam", mail.body.to_s.strip
end
def test_explicit_layout_exceptions
mail = ExplicitLayoutMailer.create_logout(@recipient)
- assert_equal "You logged out", mail.body.decoded.strip
+ assert_equal "You logged out", mail.body.to_s.strip
end
end
diff --git a/actionmailer/test/mail_render_test.rb b/actionmailer/test/mail_render_test.rb
index 3c97ad2a03..09ce5e4854 100644
--- a/actionmailer/test/mail_render_test.rb
+++ b/actionmailer/test/mail_render_test.rb
@@ -40,13 +40,22 @@ class RenderMailer < ActionMailer::Base
from "tester@example.com"
end
- def included_old_subtemplate(recipient)
+ def mailer_accessor(recipient)
recipients recipient
- subject "Including another template in the one being rendered"
+ subject "Mailer Accessor"
from "tester@example.com"
- @world = "Earth"
- render :inline => "Hello, <%= render \"subtemplate\" %>"
+ render :inline => "Look, <%= mailer.subject %>!"
+ end
+
+ def no_instance_variable(recipient)
+ recipients recipient
+ subject "No Instance Variable"
+ from "tester@example.com"
+
+ silence_warnings do
+ render :inline => "Look, subject.nil? is <%= @subject.nil? %>!"
+ end
end
def initialize_defaults(method_name)
@@ -71,6 +80,8 @@ class SecondMailer < ActionMailer::Base
end
end
+# CHANGED: Those tests were changed because body returns an object now
+# Instead of mail.body.strip, we should mail.body.to_s.strip
class RenderHelperTest < Test::Unit::TestCase
def setup
set_delivery_method :test
@@ -86,37 +97,37 @@ class RenderHelperTest < Test::Unit::TestCase
def test_implicit_body
mail = RenderMailer.create_implicit_body(@recipient)
- # CHANGED: body returns an object now
- # assert_equal "Hello there, \n\nMr. test@localhost", mail.body.strip
- assert_equal "Hello there, \n\nMr. test@localhost", mail.body.decoded.strip
+ assert_equal "Hello there, \n\nMr. test@localhost", mail.body.to_s.strip
end
def test_inline_template
mail = RenderMailer.create_inline_template(@recipient)
- # CHANGED: body returns an object now
- # assert_equal "Hello, Earth", mail.body.strip
- assert_equal "Hello, Earth", mail.body.decoded.strip
+ assert_equal "Hello, Earth", mail.body.to_s.strip
end
def test_file_template
mail = RenderMailer.create_file_template(@recipient)
- # CHANGED: body returns an object now
- # assert_equal "Hello there, \n\nMr. test@localhost", mail.body.strip
- assert_equal "Hello there, \n\nMr. test@localhost", mail.body.decoded.strip
+ assert_equal "Hello there, \n\nMr. test@localhost", mail.body.to_s.strip
end
def test_rxml_template
mail = RenderMailer.deliver_rxml_template(@recipient)
- # CHANGED: body returns an object now
- # assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test/>", mail.body.strip
- assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test/>", mail.body.decoded.strip
+ 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)
- # CHANGED: body returns an object now
- # assert_equal "Hey Ho, let's go!", mail.body.strip
- assert_equal "Hey Ho, let's go!", mail.body.decoded.strip
+ assert_equal "Hey Ho, let's go!", mail.body.to_s.strip
+ end
+
+ def test_mailer_accessor
+ mail = RenderMailer.deliver_mailer_accessor(@recipient)
+ assert_equal "Look, Mailer Accessor!", mail.body.to_s.strip
+ end
+
+ def test_no_instance_variable
+ mail = RenderMailer.deliver_no_instance_variable(@recipient)
+ assert_equal "Look, subject.nil? is true!", mail.body.to_s.strip
end
end
@@ -135,12 +146,12 @@ class FirstSecondHelperTest < Test::Unit::TestCase
def test_ordering
mail = FirstMailer.create_share(@recipient)
- assert_equal "first mail", mail.body.decoded.strip
+ assert_equal "first mail", mail.body.to_s.strip
mail = SecondMailer.create_share(@recipient)
- assert_equal "second mail", mail.body.decoded.strip
+ assert_equal "second mail", mail.body.to_s.strip
mail = FirstMailer.create_share(@recipient)
- assert_equal "first mail", mail.body.decoded.strip
+ assert_equal "first mail", mail.body.to_s.strip
mail = SecondMailer.create_share(@recipient)
- assert_equal "second mail", mail.body.decoded.strip
+ assert_equal "second mail", mail.body.to_s.strip
end
end
diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb
index 7a47a654cd..152900259d 100644
--- a/actionmailer/test/mail_service_test.rb
+++ b/actionmailer/test/mail_service_test.rb
@@ -31,6 +31,18 @@ class TestMailer < ActionMailer::Base
render :text => "Goodbye, Mr. #{recipient}"
end
+ def from_with_name
+ from "System <system@loudthinking.com>"
+ recipients "root@loudthinking.com"
+ render :text => "Nothing to see here."
+ end
+
+ def from_without_name
+ from "system@loudthinking.com"
+ recipients "root@loudthinking.com"
+ render :text => "Nothing to see here."
+ end
+
def cc_bcc(recipient)
recipients recipient
subject "testing bcc/cc"
@@ -95,7 +107,7 @@ class TestMailer < ActionMailer::Base
cc "Foo áëô îü <extended@example.net>"
bcc "Foo áëô îü <extended@example.net>"
charset "utf-8"
-
+
render :text => "åœö blah"
end
@@ -227,7 +239,7 @@ class TestMailer < ActionMailer::Base
from "test@example.com"
content_type "multipart/mixed"
- part :content_type => "multipart/alternative", :content_disposition => "inline", :headers => { "foo" => "bar" } do |p|
+ part :content_type => "multipart/alternative", :content_disposition => "inline", "foo" => "bar" do |p|
p.part :content_type => "text/plain", :body => "test text\nline #2"
p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2"
end
@@ -252,7 +264,7 @@ class TestMailer < ActionMailer::Base
from "test@example.com"
content_type "multipart/related"
part :content_type => "text/html", :body => 'yo'
- attachment :content_type => "image/jpeg", :filename => File.join(File.dirname(__FILE__), "fixtures", "attachments", "test.jpg"), :data => "i am not a real picture", :headers => { 'Content-ID' => '<test@test.com>' }
+ attachment :content_type => "image/jpeg", :filename => File.join(File.dirname(__FILE__), "fixtures", "attachments", "test.jpg"), :data => "i am not a real picture", 'Content-ID' => '<test@test.com>'
end
def unnamed_attachment(recipient)
@@ -289,6 +301,7 @@ class TestMailer < ActionMailer::Base
render :text => "testing"
end
+ # This tests body calls accepeting a hash, which is deprecated.
def body_ivar(recipient)
recipients recipient
subject "Body as a local variable"
@@ -351,7 +364,7 @@ class ActionMailerTest < Test::Unit::TestCase
assert_equal "multipart/mixed", created.content_type.string
assert_equal "multipart/alternative", created.parts[0].content_type.string
- assert_equal "bar", created.parts[0].header['foo'].decoded
+ assert_equal "bar", created.parts[0].header['foo'].to_s
assert_nil created.parts[0].charset
assert_equal "text/plain", created.parts[0].parts[0].content_type.string
assert_equal "text/html", created.parts[0].parts[1].content_type.string
@@ -370,9 +383,9 @@ class ActionMailerTest < Test::Unit::TestCase
assert_equal "multipart/mixed", created.content_type.string
assert_equal "multipart/alternative", created.parts.first.content_type.string
assert_equal "text/plain", created.parts.first.parts.first.content_type.string
- assert_equal "Nothing to see here.", created.parts.first.parts.first.body.decoded
+ assert_equal "Nothing to see here.", created.parts.first.parts.first.body.to_s
assert_equal "text/html", created.parts.first.parts.second.content_type.string
- assert_equal "<b>test</b> HTML<br/>", created.parts.first.parts.second.body.decoded
+ assert_equal "<b>test</b> HTML<br/>", created.parts.first.parts.second.body.to_s
end
def test_attachment_with_custom_header
@@ -413,11 +426,11 @@ class ActionMailerTest < Test::Unit::TestCase
def test_subject_with_i18n
assert_nothing_raised { TestMailer.deliver_subject_with_i18n(@recipient) }
- assert_equal "Subject with i18n", ActionMailer::Base.deliveries.first.subject.decoded
+ assert_equal "Subject with i18n", ActionMailer::Base.deliveries.first.subject.to_s
I18n.backend.store_translations('en', :actionmailer => {:test_mailer => {:subject_with_i18n => {:subject => "New Subject!"}}})
assert_nothing_raised { TestMailer.deliver_subject_with_i18n(@recipient) }
- assert_equal "New Subject!", ActionMailer::Base.deliveries.last.subject.decoded
+ assert_equal "New Subject!", ActionMailer::Base.deliveries.last.subject.to_s
end
def test_custom_template
@@ -514,6 +527,28 @@ class ActionMailerTest < Test::Unit::TestCase
assert_equal expected.encoded, delivered.encoded
end
+ def test_from_without_name_for_smtp
+ ActionMailer::Base.delivery_method = :smtp
+ TestMailer.deliver_from_without_name
+
+ mail = MockSMTP.deliveries.first
+ assert_not_nil mail
+ mail, from, to = mail
+
+ assert_equal 'system@loudthinking.com', from.to_s
+ end
+
+ def test_from_with_name_for_smtp
+ ActionMailer::Base.delivery_method = :smtp
+ TestMailer.deliver_from_with_name
+
+ mail = MockSMTP.deliveries.first
+ assert_not_nil mail
+ mail, from, to = mail
+
+ assert_equal 'system@loudthinking.com', from.addresses.first
+ end
+
def test_reply_to
expected = new_mail
@@ -696,7 +731,7 @@ Content-Type: text/plain; charset=iso-8859-1
The body
EOF
mail = Mail.new(msg)
- assert_equal "testing testing \326\244", mail.subject.decoded
+ assert_equal "testing testing \326\244", mail.subject.to_s
assert_equal "Subject: =?utf-8?Q?testing_testing_=D6=A4?=\r\n", mail.subject.encoded
end
@@ -709,7 +744,7 @@ Content-Type: text/plain; charset=iso-8859-1
The body
EOF
mail = Mail.new(msg)
- assert_equal "this == working?", mail.subject.decoded
+ assert_equal "this == working?", mail.subject.to_s
assert_equal "Subject: this == working?\r\n", mail.subject.encoded
end
@@ -723,7 +758,7 @@ Content-Transfer-Encoding: 7bit
The=3Dbody
EOF
mail = Mail.new(msg)
- assert_equal "The=3Dbody", mail.body.decoded.strip
+ assert_equal "The=3Dbody", mail.body.to_s.strip
assert_equal "The=3Dbody", mail.body.encoded.strip
end
@@ -737,7 +772,7 @@ Content-Transfer-Encoding: quoted-printable
The=3Dbody
EOF
mail = Mail.new(msg)
- assert_equal "The=body", mail.body.decoded.strip
+ assert_equal "The=body", mail.body.to_s.strip
assert_equal "The=3Dbody", mail.body.encoded.strip
end
@@ -751,7 +786,7 @@ Content-Transfer-Encoding: base64
VGhlIGJvZHk=
EOF
mail = Mail.new(msg)
- assert_equal "The body", mail.body.decoded.strip
+ assert_equal "The body", mail.body.to_s.strip
assert_equal "VGhlIGJvZHk=", mail.body.encoded.strip
end
@@ -825,7 +860,7 @@ EOF
def test_receive_decodes_base64_encoded_mail
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email")
TestMailer.receive(fixture)
- assert_match(/Jamis/, TestMailer.received_body.decoded)
+ assert_match(/Jamis/, TestMailer.received_body.to_s)
end
def test_receive_attachments
@@ -895,7 +930,6 @@ EOF
mail = TestMailer.create_explicitly_multipart_example(@recipient)
assert_equal 3, mail.parts.length
assert_equal 'multipart/mixed', mail.content_type.string
-
assert_equal "text/plain", mail.parts[0].content_type.string
assert_equal "text/html", mail.parts[1].content_type.string
@@ -903,7 +937,6 @@ EOF
assert_equal "image/jpeg", mail.parts[2].content_type.string
assert_equal "attachment", mail.parts[2].content_disposition.disposition_type
-
assert_equal "foo.jpg", mail.parts[2].content_disposition.filename
assert_equal "foo.jpg", mail.parts[2].content_type.filename
assert_nil mail.parts[2].charset
@@ -926,13 +959,13 @@ EOF
mail = TestMailer.create_implicitly_multipart_example(@recipient)
assert_equal 3, mail.parts.length
- assert_equal "1.0", mail.mime_version.decoded
+ assert_equal "1.0", mail.mime_version.to_s
assert_equal "multipart/alternative", mail.content_type.string
- assert_equal "application/x-yaml", mail.parts[0].content_type.string
+ assert_equal "text/plain", mail.parts[0].content_type.string
assert_equal "utf-8", mail.parts[0].charset
- assert_equal "text/plain", mail.parts[1].content_type.string
+ assert_equal "text/html", mail.parts[1].content_type.string
assert_equal "utf-8", mail.parts[1].charset
- assert_equal "text/html", mail.parts[2].content_type.string
+ assert_equal "application/x-yaml", mail.parts[2].content_type.string
assert_equal "utf-8", mail.parts[2].charset
end
@@ -941,9 +974,9 @@ EOF
mail = TestMailer.create_implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"])
assert_equal 3, mail.parts.length
- assert_equal "text/html", mail.parts[0].content_type.string
+ assert_equal "application/x-yaml", mail.parts[0].content_type.string
assert_equal "text/plain", mail.parts[1].content_type.string
- assert_equal "application/x-yaml", mail.parts[2].content_type.string
+ assert_equal "text/html", mail.parts[2].content_type.string
end
def test_implicitly_multipart_messages_with_charset
@@ -963,19 +996,19 @@ EOF
def test_html_mail_with_underscores
mail = TestMailer.create_html_mail_with_underscores(@recipient)
- assert_equal %{<a href="http://google.com" target="_blank">_Google</a>}, mail.body.decoded
+ 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)
assert_equal("line #1\nline #2\nline #3\nline #4\n\n" +
- "line #5\n\nline#6\n\nline #7", mail.body.decoded)
+ "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)
- assert_equal "line #1\nline #2\nline #3\nline #4\n\n", mail.parts[0].body.decoded
- 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.decoded
+ 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
assert_equal "<p>line #1</p>\r\n<p>line #2</p>\r\n<p>line #3</p>\r\n<p>line #4</p>\r\n\r\n", mail.parts[1].body.encoded
end
@@ -1008,7 +1041,7 @@ EOF
mail = Mail.new(fixture)
assert_equal(2, mail.parts.length)
assert_equal(4, mail.parts.first.parts.length)
- assert_equal("This is the first part.", mail.parts.first.parts.first.body.decoded)
+ assert_equal("This is the first part.", mail.parts.first.parts.first.body.to_s)
assert_equal("test.rb", mail.parts.first.parts.second.filename)
assert_equal("flowed", mail.parts.first.parts.fourth.content_type.parameters[:format])
assert_equal('smime.p7s', mail.parts.second.filename)
@@ -1074,7 +1107,7 @@ EOF
def test_return_path_with_create
mail = TestMailer.create_return_path
- assert_equal "another@somewhere.test", mail['return-path'].decoded.to_s
+ assert_equal "another@somewhere.test", mail['return-path'].to_s
end
def test_return_path_with_deliver
@@ -1085,8 +1118,9 @@ EOF
end
def test_body_is_stored_as_an_ivar
- mail = TestMailer.create_body_ivar(@recipient)
- assert_equal "body: foo\nbar: baz", mail.body.decoded
+ mail = nil
+ ActiveSupport::Deprecation.silence { mail = TestMailer.create_body_ivar(@recipient) }
+ assert_equal "body: foo\nbar: baz", mail.body.to_s
end
def test_starttls_is_enabled_if_supported
@@ -1215,6 +1249,6 @@ class RespondToTest < Test::Unit::TestCase
RespondToMailer.not_a_method
end
- assert_match /undefined method.*not_a_method/, error.message
+ assert_match(/undefined method.*not_a_method/, error.message)
end
end
diff --git a/actionmailer/test/tmail_test.rb b/actionmailer/test/mail_test.rb
index 5d895f3790..ea6f25d157 100644
--- a/actionmailer/test/tmail_test.rb
+++ b/actionmailer/test/mail_test.rb
@@ -1,6 +1,6 @@
require 'abstract_unit'
-class TMailMailTest < Test::Unit::TestCase
+class MailTest < Test::Unit::TestCase
def test_body
m = Mail.new
expected = 'something_with_underscores'
@@ -8,8 +8,8 @@ class TMailMailTest < Test::Unit::TestCase
quoted_body = [expected].pack('*M')
m.body = quoted_body
assert_equal "something_with_underscores=\r\n", m.body.encoded
- # CHANGED: body returns object, not string, Changed m.body to m.body.decoded
- assert_equal expected, m.body.decoded
+ # CHANGED: body returns object, not string, Changed m.body to m.body.to_s
+ assert_equal expected, m.body.to_s
end
def test_nested_attachments_are_recognized_correctly
diff --git a/actionmailer/test/quoting_test.rb b/actionmailer/test/quoting_test.rb
index 32f34f6028..b16d160805 100644
--- a/actionmailer/test/quoting_test.rb
+++ b/actionmailer/test/quoting_test.rb
@@ -71,7 +71,7 @@ class QuotingTest < Test::Unit::TestCase
mail = Mail.new(IO.read("#{File.dirname(__FILE__)}/fixtures/raw_email_quoted_with_0d0a"))
# CHANGED: subject returns an object now
# assert_match %r{Elapsed time}, mail.body
- assert_match %r{Elapsed time}, mail.body.decoded
+ assert_match %r{Elapsed time}, mail.body.to_s
end
def test_email_with_partially_quoted_subject
diff --git a/actionmailer/test/test_helper_test.rb b/actionmailer/test/test_helper_test.rb
index 8e4254411c..86d22da9bf 100644
--- a/actionmailer/test/test_helper_test.rb
+++ b/actionmailer/test/test_helper_test.rb
@@ -92,7 +92,7 @@ class TestHelperMailerTest < ActionMailer::TestCase
end
end
- assert_match /2 .* but 1/, error.message
+ assert_match(/2 .* but 1/, error.message)
end
def test_assert_emails_too_many_sent
@@ -103,7 +103,7 @@ class TestHelperMailerTest < ActionMailer::TestCase
end
end
- assert_match /1 .* but 2/, error.message
+ assert_match(/1 .* but 2/, error.message)
end
def test_assert_no_emails_failure
@@ -113,7 +113,7 @@ class TestHelperMailerTest < ActionMailer::TestCase
end
end
- assert_match /0 .* but 1/, error.message
+ assert_match(/0 .* but 1/, error.message)
end
end
diff --git a/actionmailer/test/url_test.rb b/actionmailer/test/url_test.rb
index 427833b36c..12bf609dce 100644
--- a/actionmailer/test/url_test.rb
+++ b/actionmailer/test/url_test.rb
@@ -1,7 +1,9 @@
require 'abstract_unit'
-class TestMailer < ActionMailer::Base
+class WelcomeController < ActionController::Base
+end
+class TestMailer < ActionMailer::Base
default_url_options[:host] = 'www.basecamphq.com'
def signed_up_with_url(recipient)
@@ -10,8 +12,8 @@ class TestMailer < ActionMailer::Base
@from = "system@loudthinking.com"
@sent_on = Time.local(2004, 12, 12)
- @body["recipient"] = recipient
- @body["welcome_url"] = url_for :host => "example.com", :controller => "welcome", :action => "greeting"
+ @recipient = recipient
+ @welcome_url = url_for :host => "example.com", :controller => "welcome", :action => "greeting"
end
class <<self
@@ -52,27 +54,31 @@ class ActionMailerUrlTest < Test::Unit::TestCase
end
def test_signed_up_with_url
- ActionController::Routing.use_controllers! ['welcome'] do
- ActionController::Routing::Routes.draw do |map|
- map.connect ':controller/:action/:id'
- map.welcome 'welcome', :controller=>"foo", :action=>"bar"
- end
-
- expected = new_mail
- expected.to = @recipient
- expected.subject = "[Signed up] Welcome #{@recipient}"
- expected.body = "Hello there, \n\nMr. #{@recipient}. Please see our greeting at http://example.com/welcome/greeting http://www.basecamphq.com/welcome\n\n<img alt=\"Somelogo\" src=\"/images/somelogo.png\" />"
- expected.from = "system@loudthinking.com"
- expected.date = Time.local(2004, 12, 12)
-
- created = nil
- assert_nothing_raised { created = TestMailer.create_signed_up_with_url(@recipient) }
- assert_not_nil created
- assert_equal expected.encoded, created.encoded
-
- assert_nothing_raised { TestMailer.deliver_signed_up_with_url(@recipient) }
- assert_not_nil ActionMailer::Base.deliveries.first
- assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
+ ActionController::Routing::Routes.draw do |map|
+ map.connect ':controller/:action/:id'
+ map.welcome 'welcome', :controller=>"foo", :action=>"bar"
end
+
+ expected = new_mail
+ expected.to = @recipient
+ expected.subject = "[Signed up] Welcome #{@recipient}"
+ expected.body = "Hello there, \n\nMr. #{@recipient}. Please see our greeting at http://example.com/welcome/greeting http://www.basecamphq.com/welcome\n\n<img alt=\"Somelogo\" src=\"/images/somelogo.png\" />"
+ expected.from = "system@loudthinking.com"
+ expected.date = Time.local(2004, 12, 12)
+
+ created = nil
+ assert_nothing_raised { created = TestMailer.create_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_not_nil ActionMailer::Base.deliveries.first
+ delivered = ActionMailer::Base.deliveries.first
+
+ delivered.message_id = '<123@456>'
+ assert_equal expected.encoded, delivered.encoded
end
end