diff options
author | Gonçalo Silva <goncalossilva@gmail.com> | 2011-03-24 17:21:17 +0000 |
---|---|---|
committer | Gonçalo Silva <goncalossilva@gmail.com> | 2011-03-24 17:21:17 +0000 |
commit | 9887f238871bb2dd73de6ce8855615bcc5d8d079 (patch) | |
tree | 74fa9ff9524a51701cfa23f708b3f777c65b7fe5 /actionmailer | |
parent | aff821508a16245ebc03510ba29c70379718dfb7 (diff) | |
parent | 5214e73850916de3c9127d35a4ecee0424d364a3 (diff) | |
download | rails-9887f238871bb2dd73de6ce8855615bcc5d8d079.tar.gz rails-9887f238871bb2dd73de6ce8855615bcc5d8d079.tar.bz2 rails-9887f238871bb2dd73de6ce8855615bcc5d8d079.zip |
Merge branch 'master' of https://github.com/rails/rails
Diffstat (limited to 'actionmailer')
47 files changed, 408 insertions, 628 deletions
diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG index 76eab935e5..167c1da9c5 100644 --- a/actionmailer/CHANGELOG +++ b/actionmailer/CHANGELOG @@ -1,9 +1,16 @@ -*Rails 3.0.0 [release candidate] (July 26th, 2010)* +*Rails 3.1.0 (unreleased)* -* No material changes +* No changes +*Rails 3.0.2 (unreleased)* -*Rails 3.0.0 [beta 4] (June 8th, 2010)* +* No changes + +*Rails 3.0.1 (October 15, 2010)* + +* No Changes, just a version bump. + +*Rails 3.0.0 (August 29, 2010)* * subject is automatically looked up on I18n using mailer_name and action_name as scope as in t(".subject") [JK] @@ -11,16 +18,10 @@ * Added ability to pass Proc objects to the defaults hash [ML] - -*Rails 3.0.0 [beta 3] (April 13th, 2010)* - * Removed all quoting.rb type files from ActionMailer and put Mail 2.2.0 in instead [ML] * Lot of updates to various test cases that now work better with the new Mail and so have different expectations - -*Rails 3.0.0 [beta 2] (April 1st, 2010)* - * Added interceptors and observers from Mail [ML] ActionMailer::Base.register_interceptor calls Mail.register_interceptor @@ -38,9 +39,6 @@ * Whole new API added with tests. See base.rb for full details. Old API is deprecated. - -*Rails 3.0.0 [beta 1] (February 4, 2010)* - * The Mail::Message class has helped methods for all the field types that return 'common' defaults for the common use case, so to get the subject, mail.subject will give you a string, mail.date will give you a DateTime object, mail.from will give you an array of address specs (mikel@test.lindsaar.net) etc. If you want to access the field object itself, call mail[:field_name] which will return the field object you want, which you can then chain, like mail[:from].formatted * Mail#content_type now returns the content_type field as a string. If you want the mime type of a mail, then you call Mail#mime_type (eg, text/plain), if you want the parameters of the content type field, you call Mail#content_type_parameters which gives you a hash, eg {'format' => 'flowed', 'charset' => 'utf-8'} @@ -181,7 +179,7 @@ * ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Marcel Molina Jr.] -* Replace alias method chaining with Module#alias_method_chain. [Marcel Molina Jr.] +* Replace alias method chaining with Module#alias_method_chain. [Marcel Molina Jr.] * Replace Ruby's deprecated append_features in favor of included. [Marcel Molina Jr.] @@ -327,7 +325,7 @@ * Added that deliver_* will now return the email that was sent -* Added that quoting to UTF-8 only happens if the characters used are in that range #955 [Jamis Buck] +* Added that quoting to UTF-8 only happens if the characters used are in that range #955 [Jamis Buck] * Fixed quoting for all address headers, not just to #955 [Jamis Buck] @@ -366,7 +364,7 @@ @body = "Nothing to see here." @charset = "iso-8859-1" end - + def unencoded_subject(recipient) @recipients = recipient @subject = "testing unencoded subject" @@ -375,7 +373,7 @@ @encode_subject = false @charset = "iso-8859-1" end - + *0.6.1* (January 18th, 2005) diff --git a/actionmailer/MIT-LICENSE b/actionmailer/MIT-LICENSE index a345a2419d..7ad1051066 100644 --- a/actionmailer/MIT-LICENSE +++ b/actionmailer/MIT-LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2010 David Heinemeier Hansson +Copyright (c) 2004-2011 David Heinemeier Hansson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/actionmailer/README.rdoc b/actionmailer/README.rdoc index b52c993f56..0fa18d751b 100644 --- a/actionmailer/README.rdoc +++ b/actionmailer/README.rdoc @@ -5,7 +5,7 @@ are used to consolidate code for sending out forgotten passwords, welcome wishes on signup, invoices for billing, and any other use case that requires a written notification to either a person or another system. -Action Mailer is in essence a wrapper around Action Controller and the +Action Mailer is in essence a wrapper around Action Controller and the Mail gem. It provides a way to make emails using templates in the same way that Action Controller renders views using templates. @@ -23,7 +23,7 @@ This can be as simple as: class Notifier < ActionMailer::Base delivers_from 'system@loudthinking.com' - + def welcome(recipient) @recipient = recipient mail(:to => recipient, @@ -36,13 +36,13 @@ ERb) that has the instance variables that are declared in the mailer action. So the corresponding body template for the method above could look like this: - Hello there, + Hello there, Mr. <%= @recipient %> Thank you for signing up! - -And if the recipient was given as "david@loudthinking.com", the email + +And if the recipient was given as "david@loudthinking.com", the email generated would look like this: Date: Mon, 25 Jan 2010 22:48:09 +1100 @@ -55,18 +55,18 @@ generated would look like this: charset="US-ASCII"; Content-Transfer-Encoding: 7bit - Hello there, + Hello there, Mr. david@loudthinking.com -In previous version of rails you would call <tt>create_method_name</tt> and +In previous version of Rails you would call <tt>create_method_name</tt> and <tt>deliver_method_name</tt>. Rails 3.0 has a much simpler interface, you simply call the method and optionally call +deliver+ on the return value. Calling the method returns a Mail Message object: - message = Notifier.welcome #=> Returns a Mail::Message object - message.deliver #=> delivers the email + message = Notifier.welcome # => Returns a Mail::Message object + message.deliver # => delivers the email Or you can just chain the methods together like: @@ -74,10 +74,10 @@ Or you can just chain the methods together like: == Receiving emails -To receive emails, you need to implement a public instance method called <tt>receive</tt> that takes a -tmail object as its single parameter. The Action Mailer framework has a corresponding class method, +To receive emails, you need to implement a public instance method called <tt>receive</tt> that takes an +email object as its single parameter. The Action Mailer framework has a corresponding class method, which is also called <tt>receive</tt>, that accepts a raw, unprocessed email as a string, which it then turns -into the tmail object and calls the receive instance method. +into the email object and calls the receive instance method. Example: @@ -90,7 +90,7 @@ Example: if email.has_attachments? for attachment in email.attachments - page.attachments.create({ + page.attachments.create({ :file => attachment, :description => email.subject }) end @@ -98,13 +98,13 @@ Example: end end -This Mailman can be the target for Postfix or other MTAs. In Rails, you would use the runner in the +This Mailman can be the target for Postfix or other MTAs. In Rails, you would use the runner in the trivial case like this: rails runner 'Mailman.receive(STDIN.read)' -However, invoking Rails in the runner for each mail to be received is very resource intensive. A single -instance of Rails should be run within a daemon if it is going to be utilized to process more than just +However, invoking Rails in the runner for each mail to be received is very resource intensive. A single +instance of Rails should be run within a daemon, if it is going to be utilized to process more than just a limited number of email. == Configuration @@ -128,7 +128,7 @@ The latest version of Action Mailer can be installed with Rubygems: Source code can be downloaded as part of the Rails project on GitHub -* http://github.com/rails/rails/tree/master/actionmailer/ +* https://github.com/rails/rails/tree/master/actionmailer/ == License @@ -145,3 +145,4 @@ API documentation is at Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here: * https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets + diff --git a/actionmailer/Rakefile b/actionmailer/Rakefile index a47426bd07..df996acbc2 100644..100755 --- a/actionmailer/Rakefile +++ b/actionmailer/Rakefile @@ -1,8 +1,5 @@ -gem 'rdoc', '>= 2.5.9' -require 'rdoc' -require 'rake' +#!/usr/bin/env rake require 'rake/testtask' -require 'rdoc/task' require 'rake/packagetask' require 'rake/gempackagetask' @@ -20,24 +17,11 @@ namespace :test do task :isolated do ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME')) Dir.glob("test/**/*_test.rb").all? do |file| - system(ruby, '-Ilib:test', file) + sh(ruby, '-Ilib:test', file) end or raise "Failures" end end -# Generate the RDoc documentation -RDoc::Task.new { |rdoc| - rdoc.rdoc_dir = 'doc' - rdoc.title = "Action Mailer -- Easy email delivery and testing" - rdoc.options << '--charset' << 'utf-8' - rdoc.options << '-f' << 'horo' - rdoc.options << '--main' << 'README.rdoc' - rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG') - rdoc.rdoc_files.include('lib/action_mailer.rb') - rdoc.rdoc_files.include('lib/action_mailer/*.rb') - rdoc.rdoc_files.include('lib/action_mailer/delivery_method/*.rb') -} - spec = eval(File.read('actionmailer.gemspec')) Rake::GemPackageTask.new(spec) do |p| diff --git a/actionmailer/actionmailer.gemspec b/actionmailer/actionmailer.gemspec index daf30e434a..2ae85f8b57 100644 --- a/actionmailer/actionmailer.gemspec +++ b/actionmailer/actionmailer.gemspec @@ -20,5 +20,5 @@ Gem::Specification.new do |s| s.has_rdoc = true s.add_dependency('actionpack', version) - s.add_dependency('mail', '~> 2.2.5') + s.add_dependency('mail', '~> 2.2.15') end diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 6e2d288082..b9e682b711 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -1,5 +1,5 @@ #-- -# Copyright (c) 2004-2010 David Heinemeier Hansson +# Copyright (c) 2004-2011 David Heinemeier Hansson # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -26,6 +26,7 @@ $:.unshift(actionpack_path) if File.directory?(actionpack_path) && !$:.include?( require 'abstract_controller' require 'action_view' +require 'action_mailer/version' # Common Active Support usage in Action Mailer require 'active_support/core_ext/class' @@ -43,7 +44,6 @@ module ActionMailer autoload :Collector autoload :Base autoload :DeliveryMethods - autoload :DeprecatedApi autoload :MailHelper autoload :OldApi autoload :TestCase diff --git a/actionmailer/lib/action_mailer/adv_attr_accessor.rb b/actionmailer/lib/action_mailer/adv_attr_accessor.rb index be6b1feca9..c1aa8021ce 100644 --- a/actionmailer/lib/action_mailer/adv_attr_accessor.rb +++ b/actionmailer/lib/action_mailer/adv_attr_accessor.rb @@ -1,26 +1,28 @@ module ActionMailer module AdvAttrAccessor #:nodoc: - def adv_attr_accessor(*names) - names.each do |name| - ivar = "@#{name}" + def adv_attr_accessor(name, deprecation=nil) + ivar = "@#{name}" + deprecation ||= "Please pass :#{name} as hash key to mail() instead" - class_eval <<-ACCESSORS, __FILE__, __LINE__ + 1 - def #{name}=(value) - #{ivar} = value - end + class_eval <<-ACCESSORS, __FILE__, __LINE__ + 1 + def #{name}=(value) + ActiveSupport::Deprecation.warn "#{name}= is deprecated. #{deprecation}" + #{ivar} = value + 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 - #{ivar} = args.first - end + def #{name}(*args) + raise ArgumentError, "expected 0 or 1 parameters" unless args.length <= 1 + if args.empty? + ActiveSupport::Deprecation.warn "#{name}() is deprecated and will be removed in future versions." + #{ivar} if instance_variable_names.include?(#{ivar.inspect}) + else + ActiveSupport::Deprecation.warn "#{name}(value) is deprecated. #{deprecation}" + #{ivar} = args.first end - ACCESSORS + end + ACCESSORS - self.protected_instance_variables << ivar if self.respond_to?(:protected_instance_variables) - end + 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 f742f982f2..16fcf112b7 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -187,31 +187,31 @@ module ActionMailer #:nodoc: # with the filename +free_book.pdf+. # # = Inline Attachments - # - # You can also specify that a file should be displayed inline with other HTML. This is useful + # + # You can also specify that a file should be displayed inline with other HTML. This is useful # if you want to display a corporate logo or a photo. - # + # # class ApplicationMailer < ActionMailer::Base # def welcome(recipient) # attachments.inline['photo.png'] = File.read('path/to/photo.png') # mail(:to => recipient, :subject => "Here is what we look like") # end # end - # + # # And then to reference the image in the view, you create a <tt>welcome.html.erb</tt> file and - # make a call to +image_tag+ passing in the attachment you want to display and then call + # make a call to +image_tag+ passing in the attachment you want to display and then call # +url+ on the attachment to get the relative content id path for the image source: - # + # # <h1>Please Don't Cringe</h1> - # + # # <%= image_tag attachments['photo.png'].url -%> - # + # # As we are using Action View's +image_tag+ method, you can pass in any other options you want: - # + # # <h1>Please Don't Cringe</h1> - # + # # <%= image_tag attachments['photo.png'].url, :alt => 'Our Photo', :class => 'photo' -%> - # + # # = Observing and Intercepting Mails # # Action Mailer provides hooks into the Mail observer and interceptor methods. These allow you to @@ -222,7 +222,7 @@ module ActionMailer #:nodoc: # # An interceptor object must implement the <tt>:delivering_email(message)</tt> method which will be # called before the email is sent, allowing you to make modifications to the email before it hits - # the delivery agents. Your object should make and needed modifications directly to the passed + # the delivery agents. Your object should make any needed modifications directly to the passed # in Mail::Message instance. # # = Default Hash @@ -234,8 +234,8 @@ module ActionMailer #:nodoc: # default :sender => 'system@example.com' # end # - # You can pass in any header value that a <tt>Mail::Message</tt>, out of the box, <tt>ActionMailer::Base</tt> - # sets the following: + # You can pass in any header value that a <tt>Mail::Message</tt> accepts. Out of the box, + # <tt>ActionMailer::Base</tt> sets the following: # # * <tt>:mime_version => "1.0"</tt> # * <tt>:charset => "UTF-8",</tt> @@ -246,7 +246,7 @@ module ActionMailer #:nodoc: # but Action Mailer translates them appropriately and sets the correct values. # # As you can pass in any header, you need to either quote the header as a string, or pass it in as - # an underscorised symbol, so the following will work: + # an underscored symbol, so the following will work: # # class Notifier < ActionMailer::Base # default 'Content-Transfer-Encoding' => '7bit', @@ -273,7 +273,7 @@ module ActionMailer #:nodoc: # = Configuration options # # These options are specified on the class level, like - # <tt>ActionMailer::Base.template_root = "/my/templates"</tt> + # <tt>ActionMailer::Base.raise_delivery_errors = true</tt> # # * <tt>default</tt> - You can pass this in at a class level as well as within the class itself as # per the above section. @@ -290,13 +290,15 @@ module ActionMailer #:nodoc: # * <tt>:password</tt> - If your mail server requires authentication, set the password in this setting. # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the # authentication type here. - # This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>. + # This is a symbol and one of <tt>:plain</tt> (will send the password in the clear), <tt>:login</tt> (will + # send password Base64 encoded) or <tt>:cram_md5</tt> (combines a Challenge/Response mechanism to exchange + # information and a cryptographic Message Digest 5 algorithm to hash important information) # * <tt>:enable_starttls_auto</tt> - When set to true, detects if STARTTLS is enabled in your SMTP server # and starts to use it. # # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method. # * <tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>. - # * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt> with <tt>-f sender@addres</tt> + # * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt> with <tt>-f sender@address</tt> # added automatically before the message is sent. # # * <tt>file_settings</tt> - Allows you to override options for the <tt>:file</tt> delivery method. @@ -341,10 +343,11 @@ module ActionMailer #:nodoc: include AbstractController::Translation include AbstractController::AssetPaths - helper ActionMailer::MailHelper + cattr_reader :protected_instance_variables + @@protected_instance_variables = [] + helper ActionMailer::MailHelper include ActionMailer::OldApi - include ActionMailer::DeprecatedApi delegate :register_observer, :to => Mail delegate :register_interceptor, :to => Mail @@ -360,7 +363,6 @@ module ActionMailer #:nodoc: }.freeze class << self - def mailer_name @mailer_name ||= name.underscore end @@ -402,14 +404,14 @@ module ActionMailer #:nodoc: end end - def respond_to?(method, *args) #:nodoc: + def respond_to?(method, include_private = false) #:nodoc: super || action_methods.include?(method.to_s) end protected def set_payload_for_mail(payload, mail) #:nodoc: - payload[:mailer] = self.name + payload[:mailer] = name payload[:message_id] = mail.message_id payload[:subject] = mail.subject payload[:to] = mail.to @@ -421,11 +423,8 @@ module ActionMailer #:nodoc: end def method_missing(method, *args) #:nodoc: - if action_methods.include?(method.to_s) - new(method, *args).message - else - super - end + return super unless respond_to?(method) + new(method, *args).message end end @@ -446,6 +445,10 @@ module ActionMailer #:nodoc: super end + def mailer_name + self.class.mailer_name + end + # Allows you to pass random and unusual headers to the new +Mail::Message+ object # which will add them to itself. # @@ -690,15 +693,8 @@ module ActionMailer #:nodoc: end def each_template(paths, name, &block) #:nodoc: - Array.wrap(paths).each do |path| - templates = lookup_context.find_all(name, path) - templates = templates.uniq_by { |t| t.formats } - - unless templates.empty? - templates.each(&block) - return - end - end + templates = lookup_context.find_all(name, Array.wrap(paths)) + templates.uniq_by { |t| t.formats }.each(&block) end def create_parts_from_responses(m, responses) #:nodoc: @@ -720,28 +716,6 @@ module ActionMailer #:nodoc: container.add_part(part) end - module DeprecatedUrlOptions - def default_url_options - deprecated_url_options - end - - def default_url_options=(val) - deprecated_url_options - end - - def deprecated_url_options - raise "You can no longer call ActionMailer::Base.default_url_options " \ - "directly. You need to set config.action_mailer.default_url_options. " \ - "If you are using ActionMailer standalone, you need to include the " \ - "routing url_helpers directly." - end - end - - # This module will complain if the user tries to set default_url_options - # directly instead of through the config object. In Action Mailer's Railtie, - # we include the router's url_helpers, which will override this module. - extend DeprecatedUrlOptions - ActiveSupport.run_load_hooks(:action_mailer, self) end end diff --git a/actionmailer/lib/action_mailer/delivery_methods.rb b/actionmailer/lib/action_mailer/delivery_methods.rb index 043794bb12..b324ba790d 100644 --- a/actionmailer/lib/action_mailer/delivery_methods.rb +++ b/actionmailer/lib/action_mailer/delivery_methods.rb @@ -46,11 +46,11 @@ module ActionMailer # as alias and the default options supplied: # # Example: - # + # # add_delivery_method :sendmail, Mail::Sendmail, # :location => '/usr/sbin/sendmail', # :arguments => '-i -t' - # + # def add_delivery_method(symbol, klass, default_options={}) class_attribute(:"#{symbol}_settings") unless respond_to?(:"#{symbol}_settings") send(:"#{symbol}_settings=", default_options) diff --git a/actionmailer/lib/action_mailer/deprecated_api.rb b/actionmailer/lib/action_mailer/deprecated_api.rb deleted file mode 100644 index 7d57feba04..0000000000 --- a/actionmailer/lib/action_mailer/deprecated_api.rb +++ /dev/null @@ -1,141 +0,0 @@ -require 'active_support/core_ext/object/try' - -module ActionMailer - # This is the API which is deprecated and is going to be removed on Rails 3.1 release. - # Part of the old API will be deprecated after 3.1, for a smoother deprecation process. - # Check those in OldApi instead. - module DeprecatedApi #:nodoc: - extend ActiveSupport::Concern - - included do - [:charset, :content_type, :mime_version, :implicit_parts_order].each do |method| - class_eval <<-FILE, __FILE__, __LINE__ + 1 - def self.default_#{method} - @@default_#{method} - end - - def self.default_#{method}=(value) - ActiveSupport::Deprecation.warn "ActionMailer::Base.default_#{method}=value is deprecated, " << - "use default :#{method} => value instead" - @@default_#{method} = value - end - - @@default_#{method} = nil - FILE - end - end - - module ClassMethods - # Deliver the given mail object directly. This can be used to deliver - # a preconstructed mail object, like: - # - # email = MyMailer.create_some_mail(parameters) - # email.set_some_obscure_header "frobnicate" - # MyMailer.deliver(email) - def deliver(mail, show_warning=true) - if show_warning - 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 - wrap_delivery_behavior(mail) - mail.deliver - mail - end - - def template_root - self.view_paths && self.view_paths.first - end - - def template_root=(root) - ActiveSupport::Deprecation.warn "template_root= is deprecated, use prepend_view_path instead", caller[0,2] - self.view_paths = ActionView::Base.process_view_paths(root) - end - - def respond_to?(method_symbol, include_private = false) - matches_dynamic_method?(method_symbol) || super - end - - def method_missing(method_symbol, *parameters) - if match = matches_dynamic_method?(method_symbol) - case match[1] - 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).message.deliver - else super - end - else - super - end - end - - private - - def matches_dynamic_method?(method_name) - method_name = method_name.to_s - /^(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name) - end - end - - # Delivers a Mail object. By default, it delivers the cached mail - # object (from the <tt>create!</tt> method). If no cached mail object exists, and - # no alternate has been given as the parameter, this will fail. - def deliver!(mail = @_message) - ActiveSupport::Deprecation.warn "Calling deliver in the AM::Base object is deprecated, " << - "please call deliver in the Mail instance", caller[0,2] - self.class.deliver(mail, false) - end - alias :deliver :deliver! - - def render(*args) - options = args.last.is_a?(Hash) ? args.last : {} - - if options[:body].is_a?(Hash) - ActiveSupport::Deprecation.warn(':body in render deprecated. Please use instance ' << - 'variables as assigns instead', caller[0,1]) - - options[:body].each { |k,v| instance_variable_set(:"@#{k}", v) } - end - super - end - - # Render a message but does not set it as mail body. Useful for rendering - # data for part and attachments. - # - # Examples: - # - # render_message "special_message" - # render_message :template => "special_message" - # render_message :inline => "<%= 'Hi!' %>" - # - def render_message(*args) - ActiveSupport::Deprecation.warn "render_message is deprecated, use render instead", caller[0,2] - render(*args) - end - - private - - def initialize_defaults(*) - @charset ||= self.class.default_charset.try(:dup) - @content_type ||= self.class.default_content_type.try(:dup) - @implicit_parts_order ||= self.class.default_implicit_parts_order.try(:dup) - @mime_version ||= self.class.default_mime_version.try(:dup) - super - end - - def create_parts - if @body.is_a?(Hash) && !@body.empty? - ActiveSupport::Deprecation.warn "Giving a hash to body is deprecated, please use instance variables instead", caller[0,2] - @body.each { |k, v| instance_variable_set(:"@#{k}", v) } - end - super - end - - end -end diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb index b708881edf..6f22adc479 100644 --- a/actionmailer/lib/action_mailer/mail_helper.rb +++ b/actionmailer/lib/action_mailer/mail_helper.rb @@ -3,23 +3,14 @@ module ActionMailer # 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) - begin - require 'text/format' - rescue LoadError => e - $stderr.puts "You don't have text-format installed in your application. Please add it to your Gemfile and run bundle install" - raise e - end unless defined?(Text::Format) - formatted = text.split(/\n\r\n/).collect { |paragraph| - Text::Format.new( - :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph - ).format + format_paragraph(paragraph) }.join("\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 @@ -37,5 +28,29 @@ module ActionMailer def attachments @_message.attachments end + + # Returns +text+ wrapped at +len+ columns and indented +indent+ spaces. + # + # === Examples + # + # my_text = "Here is a sample text with more than 40 characters" + # + # format_paragraph(my_text, 25, 4) + # # => " Here is a sample text with\n more than 40 characters" + def format_paragraph(text, len = 72, indent = 2) + sentences = [[]] + + text.split.each do |word| + if (sentences.last + [word]).join(' ').length > len + sentences << [word] + else + sentences.last << word + end + end + + sentences.map { |sentence| + "#{" " * indent}#{sentence.join(' ')}" + }.join "\n" + end end end diff --git a/actionmailer/lib/action_mailer/old_api.rb b/actionmailer/lib/action_mailer/old_api.rb index 79d024a350..04728cafb0 100644 --- a/actionmailer/lib/action_mailer/old_api.rb +++ b/actionmailer/lib/action_mailer/old_api.rb @@ -8,9 +8,7 @@ module ActionMailer included do extend ActionMailer::AdvAttrAccessor - - @@protected_instance_variables = %w(@parts) - cattr_reader :protected_instance_variables + self.protected_instance_variables.concat %w(@parts @mail_was_called) # Specify the BCC addresses for the message adv_attr_accessor :bcc @@ -42,11 +40,11 @@ module ActionMailer # The recipient addresses for the message, either as a string (for a single # address) or an array (for multiple addresses). - adv_attr_accessor :recipients + adv_attr_accessor :recipients, "Please pass :to as hash key to mail() instead" # The date on which the message was sent. If not set (the default), the # header will be set by the delivery agent. - adv_attr_accessor :sent_on + adv_attr_accessor :sent_on, "Please pass :date as hash key to mail() instead" # Specify the subject of the message. adv_attr_accessor :subject @@ -54,20 +52,12 @@ module ActionMailer # Specify the template name to use for current message. This is the "base" # template name, without the extension or directory, and may be used to # have multiple mailer methods share the same template. - adv_attr_accessor :template - - # 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. - adv_attr_accessor :mailer_name + adv_attr_accessor :template, "Please pass :template_name or :template_path as hash key to mail() instead" # Define the body of the message. This is either a Hash (in which case it # specifies the variables to pass to the template when it is rendered), # or a string, in which case it specifies the actual text of the message. adv_attr_accessor :body - - # Alias controller_path to mailer_name so render :partial in views work. - alias :controller_path :mailer_name end def process(method_name, *args) @@ -84,6 +74,8 @@ module ActionMailer # part itself is yielded to the block so that other properties (charset, # body, headers, etc.) can be set on it. def part(params) + ActiveSupport::Deprecation.warn "part() is deprecated and will be removed in future versions. " << + "Please pass a block to mail() instead." params = {:content_type => params} if String === params if custom_headers = params.delete(:headers) @@ -99,6 +91,8 @@ module ActionMailer # 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 and will be removed in future versions. " << + "Please use the attachments[] API instead." params = { :content_type => params } if String === params params[:content] ||= params.delete(:data) || params.delete(:body) @@ -116,43 +110,43 @@ module ActionMailer def normalize_nonfile_hash(params) content_disposition = "attachment;" - + mime_type = params.delete(:mime_type) - + if content_type = params.delete(:content_type) content_type = "#{mime_type || content_type};" end params[:body] = params.delete(:data) if params[:data] - + { :content_type => content_type, :content_disposition => content_disposition }.merge(params) end - + def normalize_file_hash(params) filename = File.basename(params.delete(:filename)) content_disposition = "attachment; filename=\"#{File.basename(filename)}\"" - + mime_type = params.delete(:mime_type) - + if (content_type = params.delete(:content_type)) && (content_type !~ /filename=/) content_type = "#{mime_type || content_type}; filename=\"#{filename}\"" end - + params[:body] = params.delete(:data) if params[:data] - + { :content_type => content_type, :content_disposition => content_disposition }.merge(params) end - def create_mail + def create_mail m = @_message - set_fields!({:subject => subject, :to => recipients, :from => from, - :bcc => bcc, :cc => cc, :reply_to => reply_to}, charset) + set_fields!({:subject => @subject, :to => @recipients, :from => @from, + :bcc => @bcc, :cc => @cc, :reply_to => @reply_to}, @charset) - m.mime_version = mime_version unless mime_version.nil? - m.date = sent_on.to_time rescue sent_on if sent_on + m.mime_version = @mime_version if @mime_version + m.date = @sent_on.to_time rescue @sent_on if @sent_on @headers.each { |k, v| m[k] = v } @@ -178,19 +172,21 @@ module ActionMailer wrap_delivery_behavior! m.content_transfer_encoding = '8bit' unless m.body.only_us_ascii? - + @_message end - + # 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) @charset ||= self.class.default[:charset].try(:dup) @content_type ||= self.class.default[:content_type].try(:dup) @implicit_parts_order ||= self.class.default[:parts_order].try(:dup) @mime_version ||= self.class.default[:mime_version].try(:dup) + @cc, @bcc, @reply_to, @subject, @from, @recipients = nil, nil, nil, nil, nil, nil + @mailer_name ||= self.class.mailer_name.dup @template ||= method_name @mail_was_called = false @@ -201,11 +197,11 @@ module ActionMailer @body ||= {} end - def create_parts + def create_parts if String === @body @parts.unshift create_inline_part(@body) elsif @parts.empty? || @parts.all? { |p| p.content_disposition =~ /^attachment/ } - lookup_context.find_all(@template, @mailer_name).each do |template| + lookup_context.find_all(@template, [@mailer_name]).each do |template| self.formats = template.formats @parts << create_inline_part(render(:template => template), template.mime_type) end @@ -216,11 +212,11 @@ module ActionMailer # If this is a multipart e-mail add the mime_version if it is not # already set. - @mime_version ||= "1.0" if !@parts.empty? + @mime_version ||= "1.0" unless @parts.empty? end end - def create_inline_part(body, mime_type=nil) + def create_inline_part(body, mime_type=nil) ct = mime_type || "text/plain" main_type, sub_type = split_content_type(ct.to_s) @@ -242,17 +238,17 @@ module ActionMailer m.reply_to ||= headers.delete(:reply_to) if headers[:reply_to] end - def split_content_type(ct) + def split_content_type(ct) ct.to_s.split("/") end - def parse_content_type(defaults=nil) + def parse_content_type 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)] + attrs = Hash[attrs.map { |attr| attr.split(/=/, 2) }] + [ctype, {"charset" => @charset}.merge!(attrs)] end end end diff --git a/actionmailer/lib/action_mailer/railtie.rb b/actionmailer/lib/action_mailer/railtie.rb index ce6d8cc5b5..4ec478067f 100644 --- a/actionmailer/lib/action_mailer/railtie.rb +++ b/actionmailer/lib/action_mailer/railtie.rb @@ -1,5 +1,6 @@ require "action_mailer" require "rails" +require "abstract_controller/railties/routes_helpers" module ActionMailer class Railtie < Rails::Railtie @@ -13,14 +14,26 @@ module ActionMailer paths = app.config.paths options = app.config.action_mailer - options.assets_dir ||= paths.public.to_a.first - options.javascripts_dir ||= paths.public.javascripts.to_a.first - options.stylesheets_dir ||= paths.public.stylesheets.to_a.first + options.assets_dir ||= paths["public"].first + options.javascripts_dir ||= paths["public/javascripts"].first + options.stylesheets_dir ||= paths["public/stylesheets"].first + + # make sure readers methods get compiled + options.asset_path ||= app.config.asset_path + options.asset_host ||= app.config.asset_host ActiveSupport.on_load(:action_mailer) do - include app.routes.url_helpers + include AbstractController::UrlFor + extend ::AbstractController::Railties::RoutesHelpers.with(app.routes) + include app.routes.mounted_helpers options.each { |k,v| send("#{k}=", v) } end end + + initializer "action_mailer.compile_config_methods" do + ActiveSupport.on_load(:action_mailer) do + config.compile_methods! if config.respond_to?(:compile_methods!) + end + end end -end
\ No newline at end of file +end diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb index f4d1bb59f1..63e18147f6 100644 --- a/actionmailer/lib/action_mailer/test_case.rb +++ b/actionmailer/lib/action_mailer/test_case.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/class/attribute' + module ActionMailer class NonInferrableMailerError < ::StandardError def initialize(name) @@ -15,11 +17,11 @@ module ActionMailer module ClassMethods def tests(mailer) - write_inheritable_attribute(:mailer_class, mailer) + self._mailer_class = mailer end def mailer_class - if mailer = read_inheritable_attribute(:mailer_class) + if mailer = self._mailer_class mailer else tests determine_default_mailer(name) @@ -65,6 +67,7 @@ module ActionMailer end included do + class_attribute :_mailer_class setup :initialize_test_deliveries setup :set_expected_mail end diff --git a/actionmailer/lib/action_mailer/tmail_compat.rb b/actionmailer/lib/action_mailer/tmail_compat.rb index 26962f972f..1b2cdcfb27 100644 --- a/actionmailer/lib/action_mailer/tmail_compat.rb +++ b/actionmailer/lib/action_mailer/tmail_compat.rb @@ -1,17 +1,19 @@ module Mail class Message - + def set_content_type(*args) - ActiveSupport::Deprecation.warn('Message#set_content_type is deprecated, please just call ' << - 'Message#content_type with the same arguments', caller[0,2]) + message = 'Message#set_content_type is deprecated, please just call ' << + 'Message#content_type with the same arguments' + ActiveSupport::Deprecation.warn(message, caller[0,2]) content_type(*args) end - + alias :old_transfer_encoding :transfer_encoding def transfer_encoding(value = nil) if value - ActiveSupport::Deprecation.warn('Message#transfer_encoding is deprecated, please call ' << - 'Message#content_transfer_encoding with the same arguments', caller[0,2]) + message = 'Message#transfer_encoding is deprecated, ' << + 'please call Message#content_transfer_encoding with the same arguments' + ActiveSupport::Deprecation.warn(message, caller[0,2]) content_transfer_encoding(value) else old_transfer_encoding @@ -19,16 +21,17 @@ module Mail end def transfer_encoding=(value) - ActiveSupport::Deprecation.warn('Message#transfer_encoding= is deprecated, please call ' << - 'Message#content_transfer_encoding= with the same arguments', caller[0,2]) + message = 'Message#transfer_encoding= is deprecated, ' << + 'please call Message#content_transfer_encoding= with the same arguments' + ActiveSupport::Deprecation.warn(message, caller[0,2]) self.content_transfer_encoding = value end def original_filename - ActiveSupport::Deprecation.warn('Message#original_filename is deprecated, ' << - 'please call Message#filename', caller[0,2]) + message = 'Message#original_filename is deprecated, please call Message#filename' + ActiveSupport::Deprecation.warn(message, caller[0,2]) filename end - + end -end
\ No newline at end of file +end diff --git a/actionmailer/lib/action_mailer/version.rb b/actionmailer/lib/action_mailer/version.rb index 805c89be1d..27eb6c2b9b 100644 --- a/actionmailer/lib/action_mailer/version.rb +++ b/actionmailer/lib/action_mailer/version.rb @@ -1,10 +1,10 @@ module ActionMailer module VERSION #:nodoc: MAJOR = 3 - MINOR = 0 + MINOR = 1 TINY = 0 - BUILD = "rc" + PRE = "beta" - STRING = [MAJOR, MINOR, TINY, BUILD].join('.') + STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end end diff --git a/actionmailer/lib/rails/generators/mailer/USAGE b/actionmailer/lib/rails/generators/mailer/USAGE index a08d459739..448ddbd5df 100644 --- a/actionmailer/lib/rails/generators/mailer/USAGE +++ b/actionmailer/lib/rails/generators/mailer/USAGE @@ -1,4 +1,5 @@ Description: +============ Stubs out a new mailer and its views. Pass the mailer name, either CamelCased or under_scored, and an optional list of emails as arguments. @@ -6,10 +7,12 @@ Description: engine and test framework generators. Example: - `rails generate mailer Notifications signup forgot_password invoice` +======== + rails generate mailer Notifications signup forgot_password invoice creates a Notifications mailer class, views, test, and fixtures: Mailer: app/mailers/notifications.rb Views: app/views/notifications/signup.erb [...] Test: test/functional/notifications_test.rb Fixtures: test/fixtures/notifications/signup [...] + diff --git a/actionmailer/lib/rails/generators/mailer/templates/mailer.rb b/actionmailer/lib/rails/generators/mailer/templates/mailer.rb index 21e5918ecb..370a508cad 100644 --- a/actionmailer/lib/rails/generators/mailer/templates/mailer.rb +++ b/actionmailer/lib/rails/generators/mailer/templates/mailer.rb @@ -1,3 +1,4 @@ +<% module_namespacing do -%> class <%= class_name %> < ActionMailer::Base default :from => "from@example.com" <% for action in actions -%> @@ -5,7 +6,7 @@ class <%= class_name %> < ActionMailer::Base # Subject can be set in your I18n file at config/locales/en.yml # with the following lookup: # - # en.<%= file_name %>.<%= action %>.subject + # en.<%= file_path.gsub("/",".") %>.<%= action %>.subject # def <%= action %> @greeting = "Hi" @@ -14,3 +15,4 @@ class <%= class_name %> < ActionMailer::Base end <% end -%> end +<% end -%> diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index ea15709b45..ce664bf301 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -11,11 +11,20 @@ ensure $VERBOSE = old end - require 'active_support/core_ext/kernel/reporting' + +require 'active_support/core_ext/string/encoding' +if "ruby".encoding_aware? + # These are the normal settings that will be set up by Railties + # TODO: Have these tests support other combinations of these values + silence_warnings do + Encoding.default_internal = "UTF-8" + Encoding.default_external = "UTF-8" + end +end + silence_warnings do # These external dependencies have warnings :/ - require 'text/format' require 'mail' end @@ -67,4 +76,6 @@ end def restore_delivery_method ActionMailer::Base.delivery_method = @old_delivery_method -end
\ No newline at end of file +end + +ActiveSupport::Deprecation.silenced = true diff --git a/actionmailer/test/old_base/asset_host_test.rb b/actionmailer/test/asset_host_test.rb index cc13c8a4d7..b24eca5fbb 100644 --- a/actionmailer/test/old_base/asset_host_test.rb +++ b/actionmailer/test/asset_host_test.rb @@ -3,9 +3,9 @@ require 'action_controller' class AssetHostMailer < ActionMailer::Base def email_with_asset - recipients 'test@localhost' - subject "testing email containing asset path while asset_host is set" - from "tester@example.com" + mail :to => 'test@localhost', + :subject => 'testing email containing asset path while asset_host is set', + :from => 'tester@example.com' end end @@ -29,7 +29,7 @@ class AssetHostTest < Test::Unit::TestCase assert_equal %Q{<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 + def test_asset_host_as_one_argument_proc AssetHostMailer.config.asset_host = Proc.new { |source| if source.starts_with?('/images') "http://images.example.com" @@ -41,7 +41,7 @@ class AssetHostTest < Test::Unit::TestCase assert_equal %Q{<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 + def test_asset_host_as_two_argument_proc ActionController::Base.config.asset_host = Proc.new {|source,request| if request && request.ssl? "https://www.example.com" diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index fec0ecf477..6a7931da8c 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -7,9 +7,6 @@ require 'mailers/proc_mailer' require 'mailers/asset_mailer' class BaseTest < ActiveSupport::TestCase - # TODO Add some tests for implicity layout render and url helpers - # so we can get rid of old base tests altogether with old base. - def teardown ActionMailer::Base.asset_host = nil ActionMailer::Base.assets_dir = nil @@ -35,21 +32,21 @@ class BaseTest < ActiveSupport::TestCase end test "mail() with bcc, cc, content_type, charset, mime_version, reply_to and date" do - @time = Time.now.beginning_of_day.to_datetime + time = Time.now.beginning_of_day.to_datetime 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) + :date => time) assert_equal(['bcc@test.lindsaar.net'], email.bcc) assert_equal(['cc@test.lindsaar.net'], email.cc) assert_equal('multipart/mixed; charset=iso-8559-1', email.content_type) assert_equal('iso-8559-1', email.charset) assert_equal('2.0', email.mime_version) assert_equal(['reply-to@test.lindsaar.net'], email.reply_to) - assert_equal(@time, email.date) + assert_equal(time, email.date) end test "mail() renders the template using the method being processed" do @@ -148,7 +145,7 @@ class BaseTest < ActiveSupport::TestCase assert_equal("application/pdf", email.parts[1].mime_type) assert_equal("VGhpcyBpcyB0ZXN0IEZpbGUgY29udGVudA==\r\n", email.parts[1].body.encoded) end - + test "can embed an inline attachment" do email = BaseMailer.inline_attachment # Need to call #encoded to force the JIT sort on parts @@ -156,8 +153,8 @@ class BaseTest < ActiveSupport::TestCase assert_equal(2, email.parts.length) assert_equal("multipart/related", email.mime_type) assert_equal("multipart/alternative", email.parts[0].mime_type) - assert_equal("text/plain", email.parts[0].parts[0].mime_type) - assert_equal("text/html", email.parts[0].parts[1].mime_type) + assert_equal("text/plain", email.parts[0].parts[0].mime_type) + assert_equal("text/html", email.parts[0].parts[1].mime_type) assert_equal("logo.png", email.parts[1].filename) end @@ -209,6 +206,12 @@ class BaseTest < ActiveSupport::TestCase assert_equal "New Subject!", email.subject end + test "translations are scoped properly" do + I18n.backend.store_translations('en', :base_mailer => {:email_with_translations => {:greet_user => "Hello %{name}!"}}) + email = BaseMailer.email_with_translations + assert_equal 'Hello lifo!', email.body.encoded + end + # Implicit multipart test "implicit multipart" do email = BaseMailer.implicit_multipart @@ -413,7 +416,7 @@ class BaseTest < ActiveSupport::TestCase BaseMailer.welcome.deliver assert_equal(1, BaseMailer.deliveries.length) end - + test "calling deliver, ActionMailer should yield back to mail to let it call :do_delivery on itself" do mail = Mail::Message.new mail.expects(:do_delivery).once @@ -447,7 +450,7 @@ class BaseTest < ActiveSupport::TestCase mail = BaseMailer.welcome_from_another_path(['unknown/invalid', 'another.path/base_mailer']).deliver assert_equal("Welcome from another path", mail.body.encoded) end - + test "assets tags should use ActionMailer's asset_host settings" do ActionMailer::Base.config.asset_host = "http://global.com" ActionMailer::Base.config.assets_dir = "global/" @@ -456,7 +459,7 @@ class BaseTest < ActiveSupport::TestCase assert_equal(%{<img alt="Dummy" src="http://global.com/images/dummy.png" />}, mail.body.to_s.strip) end - + test "assets tags should use a Mailer's asset_host settings when available" do ActionMailer::Base.config.asset_host = "global.com" ActionMailer::Base.config.assets_dir = "global/" @@ -469,12 +472,12 @@ class BaseTest < ActiveSupport::TestCase end # Before and After hooks - + class MyObserver def self.delivered_email(mail) end end - + test "you can register an observer to the mail object that gets informed on email delivery" do ActionMailer::Base.register_observer(MyObserver) mail = BaseMailer.welcome @@ -493,7 +496,7 @@ class BaseTest < ActiveSupport::TestCase MyInterceptor.expects(:delivering_email).with(mail) mail.deliver end - + test "being able to put proc's into the defaults hash and they get evaluated on mail sending" do mail1 = ProcMailer.welcome yesterday = 1.day.ago @@ -501,7 +504,7 @@ class BaseTest < ActiveSupport::TestCase mail2 = ProcMailer.welcome assert(mail1['X-Proc-Method'].to_s.to_i > mail2['X-Proc-Method'].to_s.to_i) end - + test "we can call other defined methods on the class as needed" do mail = ProcMailer.welcome assert_equal("Thanks for signing up this afternoon", mail.subject) diff --git a/actionmailer/test/delivery_methods_test.rb b/actionmailer/test/delivery_methods_test.rb index 22a7d19bc2..08f84dbf3b 100644 --- a/actionmailer/test/delivery_methods_test.rb +++ b/actionmailer/test/delivery_methods_test.rb @@ -128,7 +128,7 @@ class MailDeliveryTest < ActiveSupport::TestCase Mail::Message.any_instance.expects(:deliver!).never DeliveryMailer.welcome.deliver end - + test "does not append the deliveries collection if told not to perform the delivery" do DeliveryMailer.perform_deliveries = false DeliveryMailer.deliveries.clear @@ -160,7 +160,7 @@ class MailDeliveryTest < ActiveSupport::TestCase DeliveryMailer.welcome.deliver end end - + test "does not increment the deliveries collection on bogus deliveries" do DeliveryMailer.delivery_method = BogusDelivery DeliveryMailer.raise_delivery_errors = false @@ -168,5 +168,5 @@ class MailDeliveryTest < ActiveSupport::TestCase DeliveryMailer.welcome.deliver assert_equal(0, DeliveryMailer.deliveries.length) end - + end diff --git a/actionmailer/test/fixtures/base_mailer/email_with_translations.html.erb b/actionmailer/test/fixtures/base_mailer/email_with_translations.html.erb new file mode 100644 index 0000000000..30466dd005 --- /dev/null +++ b/actionmailer/test/fixtures/base_mailer/email_with_translations.html.erb @@ -0,0 +1 @@ +<%= t('.greet_user', :name => 'lifo') %>
\ No newline at end of file diff --git a/actionmailer/test/fixtures/i18n_test_mailer/mail_with_i18n_subject.erb b/actionmailer/test/fixtures/i18n_test_mailer/mail_with_i18n_subject.erb new file mode 100644 index 0000000000..f5340283f1 --- /dev/null +++ b/actionmailer/test/fixtures/i18n_test_mailer/mail_with_i18n_subject.erb @@ -0,0 +1,4 @@ +Hello there, + +Mr. <%= @recipient %>. Be greeted, new member! + diff --git a/actionmailer/test/fixtures/raw_email10 b/actionmailer/test/fixtures/raw_email10 index b1fc2b2617..edad5ccff1 100644 --- a/actionmailer/test/fixtures/raw_email10 +++ b/actionmailer/test/fixtures/raw_email10 @@ -15,6 +15,6 @@ Content-Type: text/plain; charset=X-UNKNOWN Test test. Hi. Waving. m ---------------------------------------------------------------- -Sent via Bell Mobility's Text Messaging service. +Sent via Bell Mobility's Text Messaging service. Envoyé par le service de messagerie texte de Bell Mobilité. ---------------------------------------------------------------- diff --git a/actionmailer/test/fixtures/raw_email2 b/actionmailer/test/fixtures/raw_email2 index 3999fcc877..9f87bb2a98 100644 --- a/actionmailer/test/fixtures/raw_email2 +++ b/actionmailer/test/fixtures/raw_email2 @@ -32,7 +32,7 @@ To: xxxxx xxxx <xxxxx@xxxxxxxxx.com> Subject: Fwd: Signed email causes file attachments In-Reply-To: <F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@mac.com> Mime-Version: 1.0 -Content-Type: multipart/mixed; +Content-Type: multipart/mixed; boundary="----=_Part_5028_7368284.1115579351471" References: <F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@mac.com> diff --git a/actionmailer/test/fixtures/raw_email3 b/actionmailer/test/fixtures/raw_email3 index 771a96350d..3a0927490a 100644 --- a/actionmailer/test/fixtures/raw_email3 +++ b/actionmailer/test/fixtures/raw_email3 @@ -31,7 +31,7 @@ Reply-To: Test Tester <xxxx@xxxx.com> To: xxxx@xxxx.com, xxxx@xxxx.com Subject: Another PDF Mime-Version: 1.0 -Content-Type: multipart/mixed; +Content-Type: multipart/mixed; boundary="----=_Part_2192_32400445.1115745999735" X-Virus-Scanned: amavisd-new at textdrive.com diff --git a/actionmailer/test/fixtures/raw_email5 b/actionmailer/test/fixtures/raw_email5 index 151c631471..bbe31bcdc5 100644 --- a/actionmailer/test/fixtures/raw_email5 +++ b/actionmailer/test/fixtures/raw_email5 @@ -14,6 +14,6 @@ Importance: normal Test test. Hi. Waving. m ---------------------------------------------------------------- -Sent via Bell Mobility's Text Messaging service. +Sent via Bell Mobility's Text Messaging service. Envoyé par le service de messagerie texte de Bell Mobilité. ---------------------------------------------------------------- diff --git a/actionmailer/test/fixtures/raw_email6 b/actionmailer/test/fixtures/raw_email6 index 93289c4f92..8e37bd7392 100644 --- a/actionmailer/test/fixtures/raw_email6 +++ b/actionmailer/test/fixtures/raw_email6 @@ -15,6 +15,6 @@ Content-Type: text/plain; charset=us-ascii Test test. Hi. Waving. m ---------------------------------------------------------------- -Sent via Bell Mobility's Text Messaging service. +Sent via Bell Mobility's Text Messaging service. Envoyé par le service de messagerie texte de Bell Mobilité. ---------------------------------------------------------------- diff --git a/actionmailer/test/fixtures/raw_email8 b/actionmailer/test/fixtures/raw_email8 index 2382dfdf34..79996365b3 100644 --- a/actionmailer/test/fixtures/raw_email8 +++ b/actionmailer/test/fixtures/raw_email8 @@ -8,7 +8,7 @@ To: xxxxx xxxx <xxxxx@xxxxxxxxx.com> Subject: Fwd: Signed email causes file attachments In-Reply-To: <F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@mac.com> Mime-Version: 1.0 -Content-Type: multipart/mixed; +Content-Type: multipart/mixed; boundary="----=_Part_5028_7368284.1115579351471" References: <F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@mac.com> diff --git a/actionmailer/test/fixtures/raw_email9 b/actionmailer/test/fixtures/raw_email9 index 8b9b1eaa04..02ea0b05c5 100644 --- a/actionmailer/test/fixtures/raw_email9 +++ b/actionmailer/test/fixtures/raw_email9 @@ -10,19 +10,19 @@ Date: Wed, 23 Feb 2005 18:20:17 -0400 From: "xxx xxx" <xxx@xxx.xxx> Message-ID: <4D6AA7EB.6490534@xxx.xxx> To: xxx@xxx.com -Subject: Stop adware/spyware once and for all. +Subject: Stop adware/spyware once and for all. X-Scanned-By: MIMEDefang 2.11 (www dot roaringpenguin dot com slash mimedefang) -You are infected with: +You are infected with: Ad Ware and Spy Ware -Get your free scan and removal download now, -before it gets any worse. +Get your free scan and removal download now, +before it gets any worse. http://xxx.xxx.info?aid=3D13&?stat=3D4327kdzt -no more? (you will still be infected) +no more? (you will still be infected) http://xxx.xxx.info/discon/?xxx@xxx.com diff --git a/actionmailer/test/fixtures/templates/signed_up.erb b/actionmailer/test/fixtures/templates/signed_up.erb index a85d5fa442..7afe1f651c 100644 --- a/actionmailer/test/fixtures/templates/signed_up.erb +++ b/actionmailer/test/fixtures/templates/signed_up.erb @@ -1,3 +1,3 @@ -Hello there, +Hello there, Mr. <%= @recipient %>
\ No newline at end of file diff --git a/actionmailer/test/fixtures/test_mailer/custom_templating_extension.html.haml b/actionmailer/test/fixtures/test_mailer/custom_templating_extension.html.haml index 847d065c37..8dcf9746cc 100644 --- a/actionmailer/test/fixtures/test_mailer/custom_templating_extension.html.haml +++ b/actionmailer/test/fixtures/test_mailer/custom_templating_extension.html.haml @@ -1,6 +1,6 @@ -%p Hello there, +%p Hello there, -%p +%p Mr. = @recipient from haml
\ No newline at end of file diff --git a/actionmailer/test/fixtures/test_mailer/custom_templating_extension.text.haml b/actionmailer/test/fixtures/test_mailer/custom_templating_extension.text.haml index 847d065c37..8dcf9746cc 100644 --- a/actionmailer/test/fixtures/test_mailer/custom_templating_extension.text.haml +++ b/actionmailer/test/fixtures/test_mailer/custom_templating_extension.text.haml @@ -1,6 +1,6 @@ -%p Hello there, +%p Hello there, -%p +%p Mr. = @recipient from haml
\ No newline at end of file diff --git a/actionmailer/test/fixtures/test_mailer/signed_up.html.erb b/actionmailer/test/fixtures/test_mailer/signed_up.html.erb index a85d5fa442..7afe1f651c 100644 --- a/actionmailer/test/fixtures/test_mailer/signed_up.html.erb +++ b/actionmailer/test/fixtures/test_mailer/signed_up.html.erb @@ -1,3 +1,3 @@ -Hello there, +Hello there, Mr. <%= @recipient %>
\ No newline at end of file diff --git a/actionmailer/test/fixtures/url_test_mailer/signed_up_with_url.erb b/actionmailer/test/fixtures/url_test_mailer/signed_up_with_url.erb index 4c5806d30d..6e7875cff5 100644 --- a/actionmailer/test/fixtures/url_test_mailer/signed_up_with_url.erb +++ b/actionmailer/test/fixtures/url_test_mailer/signed_up_with_url.erb @@ -1,4 +1,4 @@ -Hello there, +Hello there, Mr. <%= @recipient %>. Please see our greeting at <%= @welcome_url %> <%= welcome_url %> diff --git a/actionmailer/test/i18n_with_controller_test.rb b/actionmailer/test/i18n_with_controller_test.rb new file mode 100644 index 0000000000..7040ae6f8d --- /dev/null +++ b/actionmailer/test/i18n_with_controller_test.rb @@ -0,0 +1,46 @@ +require 'abstract_unit' +require 'action_controller' + +class I18nTestMailer < ActionMailer::Base + configure do |c| + c.assets_dir = '' + end + + def mail_with_i18n_subject(recipient) + @recipient = recipient + I18n.locale = :de + mail(:to => recipient, :subject => "#{I18n.t :email_subject} #{recipient}", + :from => "system@loudthinking.com", :date => Time.local(2004, 12, 12)) + end +end + +class TestController < ActionController::Base + def send_mail + I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver + render :text => 'Mail sent' + end +end + +class ActionMailerI18nWithControllerTest < ActionDispatch::IntegrationTest + Routes = ActionDispatch::Routing::RouteSet.new + Routes.draw do + match ':controller(/:action(/:id))' + end + + def app + Routes + end + + def setup + I18n.backend.store_translations('de', :email_subject => '[Signed up] Welcome') + end + + def teardown + I18n.locale = :en + end + + def test_send_mail + get '/test/send_mail' + assert_equal "Mail sent", @response.body + end +end diff --git a/actionmailer/test/mail_helper_test.rb b/actionmailer/test/mail_helper_test.rb index 7cc0804323..17e9c82045 100644 --- a/actionmailer/test/mail_helper_test.rb +++ b/actionmailer/test/mail_helper_test.rb @@ -14,6 +14,14 @@ class HelperMailer < ActionMailer::Base end end + def use_format_paragraph + @text = "But soft! What light through yonder window breaks?" + + mail_with_defaults do |format| + format.html { render(:inline => "<%= format_paragraph @text, 15, 1 %>") } + end + end + def use_mailer mail_with_defaults do |format| format.html { render(:inline => "<%= mailer.message.subject %>") } @@ -50,5 +58,10 @@ class MailerHelperTest < ActionMailer::TestCase mail = HelperMailer.use_message assert_match "using helpers", mail.body.encoded end + + def test_use_format_paragraph + mail = HelperMailer.use_format_paragraph + assert_match " But soft! What\r\n light through\r\n yonder window\r\n breaks?", mail.body.encoded + end end diff --git a/actionmailer/test/old_base/mail_layout_test.rb b/actionmailer/test/mail_layout_test.rb index 2c2daa0f28..def8da81b8 100644 --- a/actionmailer/test/old_base/mail_layout_test.rb +++ b/actionmailer/test/mail_layout_test.rb @@ -1,53 +1,45 @@ require 'abstract_unit' class AutoLayoutMailer < ActionMailer::Base + default :to => 'test@localhost', + :subject => "You have a mail", + :from => "tester@example.com" def hello - recipients 'test@localhost' - subject "You have a mail" - from "tester@example.com" + mail() end def spam - recipients 'test@localhost' - subject "You have a mail" - from "tester@example.com" - @world = "Earth" - body render(:inline => "Hello, <%= @world %>", :layout => 'spam') + mail(:body => render(:inline => "Hello, <%= @world %>", :layout => 'spam')) end def nolayout - recipients 'test@localhost' - subject "You have a mail" - from "tester@example.com" - @world = "Earth" - body render(:inline => "Hello, <%= @world %>", :layout => false) + mail(:body => render(:inline => "Hello, <%= @world %>", :layout => false)) end def multipart(type = nil) - recipients 'test@localhost' - subject "You have a mail" - from "tester@example.com" - - content_type(type) if type + mail(:content_type => type) do |format| + format.text { render } + format.html { render } + end end end class ExplicitLayoutMailer < ActionMailer::Base layout 'spam', :except => [:logout] + default :to => 'test@localhost', + :subject => "You have a mail", + :from => "tester@example.com" + def signup - recipients 'test@localhost' - subject "You have a mail" - from "tester@example.com" + mail() end def logout - recipients 'test@localhost' - subject "You have a mail" - from "tester@example.com" + mail() end end @@ -91,19 +83,6 @@ class LayoutMailerTest < Test::Unit::TestCase assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s end - def test_should_fix_multipart_layout - mail = AutoLayoutMailer.multipart("text/plain") - assert_equal "multipart/alternative", mail.mime_type - assert_equal 2, mail.parts.size - - assert_equal 'text/plain', mail.parts.first.mime_type - assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s - - assert_equal 'text/html', mail.parts.last.mime_type - 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.spam assert_equal "Spammer layout Hello, Earth", mail.body.to_s.strip diff --git a/actionmailer/test/mailers/base_mailer.rb b/actionmailer/test/mailers/base_mailer.rb index 2c6de36ccf..9416bc718e 100644 --- a/actionmailer/test/mailers/base_mailer.rb +++ b/actionmailer/test/mailers/base_mailer.rb @@ -111,4 +111,8 @@ class BaseMailer < ActionMailer::Base format.html { render :layout => layout_name } end end + + def email_with_translations + mail :body => render("email_with_translations.html") + end end diff --git a/actionmailer/test/mailers/proc_mailer.rb b/actionmailer/test/mailers/proc_mailer.rb index 6a79cd71fc..43916e1421 100644 --- a/actionmailer/test/mailers/proc_mailer.rb +++ b/actionmailer/test/mailers/proc_mailer.rb @@ -6,11 +6,11 @@ class ProcMailer < ActionMailer::Base def welcome mail end - + private - + def give_a_greeting "Thanks for signing up this afternoon" end - + end diff --git a/actionmailer/test/old_base/adv_attr_test.rb b/actionmailer/test/old_base/adv_attr_test.rb index f22d733bc5..c5a6b6d88b 100644 --- a/actionmailer/test/old_base/adv_attr_test.rb +++ b/actionmailer/test/old_base/adv_attr_test.rb @@ -11,9 +11,14 @@ class AdvAttrTest < ActiveSupport::TestCase end def setup + ActiveSupport::Deprecation.silenced = true @person = Person.new end + def teardown + ActiveSupport::Deprecation.silenced = false + end + def test_adv_attr assert_nil @person.name @person.name 'Bob' diff --git a/actionmailer/test/old_base/mail_render_test.rb b/actionmailer/test/old_base/mail_render_test.rb index 08951833a5..3a1d3184f4 100644 --- a/actionmailer/test/old_base/mail_render_test.rb +++ b/actionmailer/test/old_base/mail_render_test.rb @@ -19,18 +19,6 @@ class RenderMailer < ActionMailer::Base body render(:file => "templates/signed_up") end - def rxml_template - recipients 'test@localhost' - subject "rendering rxml template" - from "tester@example.com" - end - - def included_subtemplate - recipients 'test@localhost' - subject "Including another template in the one being rendered" - from "tester@example.com" - end - def no_instance_variable recipients 'test@localhost' subject "No Instance Variable" @@ -41,11 +29,6 @@ class RenderMailer < ActionMailer::Base end end - def initialize_defaults(method_name) - super - mailer_name "test_mailer" - end - def multipart_alternative recipients 'test@localhost' subject 'multipart/alternative' @@ -97,11 +80,13 @@ class RenderHelperTest < Test::Unit::TestCase set_delivery_method :test ActionMailer::Base.perform_deliveries = true ActionMailer::Base.deliveries.clear + ActiveSupport::Deprecation.silenced = true @recipient = 'test@localhost' end def teardown + ActiveSupport::Deprecation.silenced = false restore_delivery_method end @@ -112,38 +97,19 @@ class RenderHelperTest < Test::Unit::TestCase def test_file_template mail = RenderMailer.file_template - assert_equal "Hello there, \n\nMr. test@localhost", mail.body.to_s.strip - end - - def test_rxml_template - 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.included_subtemplate.deliver - assert_equal "Hey Ho, let's go!", mail.body.to_s.strip + assert_equal "Hello there,\n\nMr. test@localhost", mail.body.to_s.strip end def test_no_instance_variable mail = RenderMailer.no_instance_variable.deliver assert_equal "Look, subject.nil? is true!", mail.body.to_s.strip end - - def test_legacy_multipart_alternative - mail = RenderMailer.multipart_alternative.deliver - assert_equal(2, mail.parts.size) - assert_equal("multipart/alternative", mail.mime_type) - assert_equal("text/plain", mail.parts[0].mime_type) - assert_equal("foo: bar", mail.parts[0].body.encoded) - assert_equal("text/html", mail.parts[1].mime_type) - assert_equal("<strong>foo</strong> bar", mail.parts[1].body.encoded) - end end class FirstSecondHelperTest < Test::Unit::TestCase def setup set_delivery_method :test + ActiveSupport::Deprecation.silenced = true ActionMailer::Base.perform_deliveries = true ActionMailer::Base.deliveries.clear @@ -151,6 +117,7 @@ class FirstSecondHelperTest < Test::Unit::TestCase end def teardown + ActiveSupport::Deprecation.silenced = false restore_delivery_method end diff --git a/actionmailer/test/old_base/mail_service_test.rb b/actionmailer/test/old_base/mail_service_test.rb index 831adf3e32..0b5b0b2da3 100644 --- a/actionmailer/test/old_base/mail_service_test.rb +++ b/actionmailer/test/old_base/mail_service_test.rb @@ -106,7 +106,7 @@ class TestMailer < ActionMailer::Base cc "Foo áëô îü <extended@example.net>" bcc "Foo áëô îü <extended@example.net>" charset "UTF-8" - + body "åœö blah" end @@ -328,21 +328,20 @@ class ActionMailerTest < Test::Unit::TestCase mail end - # Replacing logger work around for mocha bug. Should be fixed in mocha 0.3.3 def setup set_delivery_method :test ActionMailer::Base.perform_deliveries = true ActionMailer::Base.raise_delivery_errors = true ActionMailer::Base.deliveries.clear + ActiveSupport::Deprecation.silenced = true - @original_logger = TestMailer.logger @recipient = 'test@localhost' TestMailer.delivery_method = :test end def teardown - TestMailer.logger = @original_logger + ActiveSupport::Deprecation.silenced = false restore_delivery_method end @@ -359,7 +358,7 @@ class ActionMailerTest < Test::Unit::TestCase assert_equal "text/plain", created.parts[0].parts[0].mime_type assert_equal "text/html", created.parts[0].parts[1].mime_type assert_equal "application/octet-stream", created.parts[1].mime_type - + end def test_nested_parts_with_body @@ -392,14 +391,14 @@ class ActionMailerTest < Test::Unit::TestCase expected = new_mail expected.to = @recipient expected.subject = "[Signed up] Welcome #{@recipient}" - expected.body = "Hello there, \n\nMr. #{@recipient}" + expected.body = "Hello there,\n\nMr. #{@recipient}" expected.from = "system@loudthinking.com" expected.date = Time.now created = nil assert_nothing_raised { created = TestMailer.signed_up(@recipient) } assert_not_nil created - + expected.message_id = '<123@456>' created.message_id = '<123@456>' @@ -420,7 +419,7 @@ class ActionMailerTest < Test::Unit::TestCase expected = new_mail expected.to = @recipient expected.subject = "[Signed up] Welcome #{@recipient}" - expected.body = "Hello there, \n\nMr. #{@recipient}" + expected.body = "Hello there,\n\nMr. #{@recipient}" expected.from = "system@loudthinking.com" expected.date = Time.local(2004, 12, 12) @@ -503,7 +502,7 @@ class ActionMailerTest < Test::Unit::TestCase delivered = ActionMailer::Base.deliveries.first expected.message_id = '<123@456>' delivered.message_id = '<123@456>' - + assert_equal expected.encoded, delivered.encoded end @@ -546,10 +545,10 @@ class ActionMailerTest < Test::Unit::TestCase created = TestMailer.different_reply_to @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 @@ -558,10 +557,10 @@ class ActionMailerTest < Test::Unit::TestCase delivered = ActionMailer::Base.deliveries.first assert_not_nil delivered - + expected.message_id = '<123@456>' delivered.message_id = '<123@456>' - + assert_equal expected.encoded, delivered.encoded end @@ -581,7 +580,7 @@ class ActionMailerTest < Test::Unit::TestCase created = TestMailer.iso_charset @recipient end assert_not_nil created - + expected.message_id = '<123@456>' created.message_id = '<123@456>' @@ -596,7 +595,7 @@ class ActionMailerTest < Test::Unit::TestCase expected.message_id = '<123@456>' delivered.message_id = '<123@456>' - + assert_equal expected.encoded, delivered.encoded end @@ -631,7 +630,7 @@ class ActionMailerTest < Test::Unit::TestCase expected.message_id = '<123@456>' delivered.message_id = '<123@456>' - + assert_equal expected.encoded, delivered.encoded end @@ -761,10 +760,10 @@ EOF delivered = ActionMailer::Base.deliveries.first assert_not_nil delivered - + expected.message_id = '<123@456>' delivered.message_id = '<123@456>' - + assert_equal expected.encoded, delivered.encoded end @@ -887,7 +886,7 @@ EOF assert_equal "iso-8859-1", mail.parts[1].charset assert_equal "image/jpeg", mail.parts[2].mime_type - + 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 @@ -1005,7 +1004,7 @@ EOF attachment = mail.attachments.last expected = "01 Quien Te Dij\212at. Pitbull.mp3" - + if expected.respond_to?(:force_encoding) result = attachment.filename.dup expected.force_encoding(Encoding::ASCII_8BIT) @@ -1096,111 +1095,3 @@ EOF TestMailer.smtp_settings.merge!(:enable_starttls_auto => true) end end - -class InheritableTemplateRootTest < ActiveSupport::TestCase - def test_attr - expected = File.expand_path("#{File.dirname(__FILE__)}/../fixtures/path.with.dots") - assert_equal expected, FunkyPathMailer.template_root.to_s - - sub = Class.new(FunkyPathMailer) - assert_deprecated do - sub.template_root = 'test/path' - end - - assert_equal File.expand_path('test/path'), sub.template_root.to_s - assert_equal expected, FunkyPathMailer.template_root.to_s - end -end - -class MethodNamingTest < ActiveSupport::TestCase - include ActionMailer::TestHelper - - class TestMailer < ActionMailer::Base - def send - body 'foo' - end - end - - def setup - set_delivery_method :test - ActionMailer::Base.perform_deliveries = true - ActionMailer::Base.deliveries.clear - end - - def teardown - restore_delivery_method - end - - def test_send_method - assert_nothing_raised do - assert_emails 1 do - assert_deprecated do - TestMailer.deliver_send - end - end - end - end -end -class RespondToTest < Test::Unit::TestCase - class RespondToMailer < ActionMailer::Base; end - - def setup - set_delivery_method :test - end - - def teardown - restore_delivery_method - end - - def test_should_respond_to_new - assert_respond_to RespondToMailer, :new - end - - def test_should_respond_to_create_with_template_suffix - assert_respond_to RespondToMailer, :create_any_old_template - end - - def test_should_respond_to_deliver_with_template_suffix - assert_respond_to RespondToMailer, :deliver_any_old_template - end - - def test_should_not_respond_to_new_with_template_suffix - assert !RespondToMailer.respond_to?(:new_any_old_template) - end - - def test_should_not_respond_to_create_with_template_suffix_unless_it_is_separated_by_an_underscore - assert !RespondToMailer.respond_to?(:createany_old_template) - end - - def test_should_not_respond_to_deliver_with_template_suffix_unless_it_is_separated_by_an_underscore - assert !RespondToMailer.respond_to?(:deliverany_old_template) - end - - def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_uppercase_letter - assert !RespondToMailer.respond_to?(:create_Any_old_template) - end - - def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_uppercase_letter - assert !RespondToMailer.respond_to?(:deliver_Any_old_template) - end - - def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_digit - assert !RespondToMailer.respond_to?(:create_1_template) - end - - def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_digit - assert !RespondToMailer.respond_to?(:deliver_1_template) - end - - def test_should_not_respond_to_method_where_deliver_is_not_a_suffix - assert !RespondToMailer.respond_to?(:foo_deliver_template) - end - - def test_should_still_raise_exception_with_expected_message_when_calling_an_undefined_method - error = assert_raise NoMethodError do - RespondToMailer.not_a_method - end - - assert_match(/method.*not_a_method/, error.message) - end -end diff --git a/actionmailer/test/old_base/tmail_compat_test.rb b/actionmailer/test/old_base/tmail_compat_test.rb index 255205de84..51558c2bfa 100644 --- a/actionmailer/test/old_base/tmail_compat_test.rb +++ b/actionmailer/test/old_base/tmail_compat_test.rb @@ -1,6 +1,14 @@ require 'abstract_unit' class TmailCompatTest < ActiveSupport::TestCase + def setup + @silence = ActiveSupport::Deprecation.silenced + ActiveSupport::Deprecation.silenced = false + end + + def teardown + ActiveSupport::Deprecation.silenced = @silence + end def test_set_content_type_raises_deprecation_warning mail = Mail.new @@ -31,5 +39,4 @@ class TmailCompatTest < ActiveSupport::TestCase end assert_equal mail.content_transfer_encoding, "base64" end - end diff --git a/actionmailer/test/test_helper_test.rb b/actionmailer/test/test_helper_test.rb index 8ff604c2c7..dd62164176 100644 --- a/actionmailer/test/test_helper_test.rb +++ b/actionmailer/test/test_helper_test.rb @@ -2,11 +2,10 @@ require 'abstract_unit' class TestHelperMailer < ActionMailer::Base def test - recipients "test@example.com" - from "tester@example.com" - @world = "Earth" - render(:inline => "Hello, <%= @world %>") + mail :body => render(:inline => "Hello, <%= @world %>"), + :to => "test@example.com", + :from => "tester@example.com" end end @@ -32,7 +31,7 @@ class TestHelperMailerTest < ActionMailer::TestCase self.class.determine_default_mailer("NotAMailerTest") end end - + def test_charset_is_utf_8 assert_equal "UTF-8", charset end @@ -44,14 +43,14 @@ class TestHelperMailerTest < ActionMailer::TestCase end end end - + def test_repeated_assert_emails_calls assert_nothing_raised do assert_emails 1 do TestHelperMailer.test.deliver end end - + assert_nothing_raised do assert_emails 2 do TestHelperMailer.test.deliver @@ -59,20 +58,20 @@ class TestHelperMailerTest < ActionMailer::TestCase end end end - + def test_assert_emails_with_no_block assert_nothing_raised do TestHelperMailer.test.deliver assert_emails 1 end - + assert_nothing_raised do TestHelperMailer.test.deliver TestHelperMailer.test.deliver assert_emails 3 end end - + def test_assert_no_emails assert_nothing_raised do assert_no_emails do @@ -80,17 +79,17 @@ class TestHelperMailerTest < ActionMailer::TestCase end end end - + def test_assert_emails_too_few_sent error = assert_raise ActiveSupport::TestCase::Assertion do assert_emails 2 do TestHelperMailer.test.deliver end end - + assert_match(/2 .* but 1/, error.message) end - + def test_assert_emails_too_many_sent error = assert_raise ActiveSupport::TestCase::Assertion do assert_emails 1 do @@ -98,17 +97,17 @@ class TestHelperMailerTest < ActionMailer::TestCase TestHelperMailer.test.deliver end end - + assert_match(/1 .* but 2/, error.message) end - + def test_assert_no_emails_failure error = assert_raise ActiveSupport::TestCase::Assertion do assert_no_emails do TestHelperMailer.test.deliver end end - + assert_match(/0 .* but 1/, error.message) end end diff --git a/actionmailer/test/old_base/url_test.rb b/actionmailer/test/url_test.rb index b6496bfe1b..0536e83098 100644 --- a/actionmailer/test/old_base/url_test.rb +++ b/actionmailer/test/url_test.rb @@ -18,13 +18,10 @@ class UrlTestMailer < ActionMailer::Base end def signed_up_with_url(recipient) - @recipients = recipient - @subject = "[Signed up] Welcome #{recipient}" - @from = "system@loudthinking.com" - @sent_on = Time.local(2004, 12, 12) - @recipient = recipient @welcome_url = url_for :host => "example.com", :controller => "welcome", :action => "greeting" + mail(:to => recipient, :subject => "[Signed up] Welcome #{recipient}", + :from => "system@loudthinking.com", :date => Time.local(2004, 12, 12)) end end @@ -47,6 +44,7 @@ class ActionMailerUrlTest < ActionMailer::TestCase set_delivery_method :test ActionMailer::Base.perform_deliveries = true ActionMailer::Base.deliveries.clear + ActiveSupport::Deprecation.silenced = false @recipient = 'test@localhost' end @@ -58,19 +56,18 @@ class ActionMailerUrlTest < ActionMailer::TestCase def test_signed_up_with_url UrlTestMailer.delivery_method = :test - assert_deprecated do - AppRoutes.draw do |map| - map.connect ':controller/:action/:id' - map.welcome 'welcome', :controller=>"foo", :action=>"bar" - end + AppRoutes.draw do + match ':controller(/:action(/:id))' + match '/welcome' => "foo#bar", :as => "welcome" 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.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) + expected.content_type = "text/html" created = nil assert_nothing_raised { created = UrlTestMailer.signed_up_with_url(@recipient) } @@ -83,7 +80,7 @@ class ActionMailerUrlTest < ActionMailer::TestCase assert_nothing_raised { UrlTestMailer.signed_up_with_url(@recipient).deliver } assert_not_nil ActionMailer::Base.deliveries.first delivered = ActionMailer::Base.deliveries.first - + delivered.message_id = '<123@456>' assert_equal expected.encoded, delivered.encoded end |