diff options
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/README.rdoc | 2 | ||||
-rwxr-xr-x | actionmailer/Rakefile | 4 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer.rb | 2 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/adv_attr_accessor.rb | 28 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 90 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/delivery_methods.rb | 2 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/old_api.rb | 255 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/tmail_compat.rb | 37 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/version.rb | 4 | ||||
-rw-r--r-- | actionmailer/test/log_subscriber_test.rb | 14 | ||||
-rw-r--r-- | actionmailer/test/old_base/adv_attr_test.rb | 41 | ||||
-rw-r--r-- | actionmailer/test/old_base/mail_render_test.rb | 134 | ||||
-rw-r--r-- | actionmailer/test/old_base/mail_service_test.rb | 1097 | ||||
-rw-r--r-- | actionmailer/test/old_base/tmail_compat_test.rb | 42 |
14 files changed, 47 insertions, 1705 deletions
diff --git a/actionmailer/README.rdoc b/actionmailer/README.rdoc index 2806531dfa..63e3893316 100644 --- a/actionmailer/README.rdoc +++ b/actionmailer/README.rdoc @@ -153,7 +153,7 @@ Action Mailer is released under the MIT license. API documentation is at -* http://api.rubyonrails.com +* http://api.rubyonrails.org Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here: diff --git a/actionmailer/Rakefile b/actionmailer/Rakefile index df996acbc2..e7d8ee299d 100755 --- a/actionmailer/Rakefile +++ b/actionmailer/Rakefile @@ -1,7 +1,7 @@ #!/usr/bin/env rake require 'rake/testtask' require 'rake/packagetask' -require 'rake/gempackagetask' +require 'rubygems/package_task' desc "Default Task" task :default => [ :test ] @@ -24,7 +24,7 @@ end spec = eval(File.read('actionmailer.gemspec')) -Rake::GemPackageTask.new(spec) do |p| +Gem::PackageTask.new(spec) do |p| p.gem_spec = spec end diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index b9e682b711..9bd73dd740 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -40,12 +40,10 @@ require 'active_support/lazy_load_hooks' module ActionMailer extend ::ActiveSupport::Autoload - autoload :AdvAttrAccessor autoload :Collector autoload :Base autoload :DeliveryMethods autoload :MailHelper - autoload :OldApi autoload :TestCase autoload :TestHelper end diff --git a/actionmailer/lib/action_mailer/adv_attr_accessor.rb b/actionmailer/lib/action_mailer/adv_attr_accessor.rb deleted file mode 100644 index c1aa8021ce..0000000000 --- a/actionmailer/lib/action_mailer/adv_attr_accessor.rb +++ /dev/null @@ -1,28 +0,0 @@ -module ActionMailer - module AdvAttrAccessor #:nodoc: - 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) - 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? - 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 - 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 f00a0c8ae0..cb289fd693 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,5 +1,4 @@ require 'mail' -require 'action_mailer/tmail_compat' require 'action_mailer/collector' require 'active_support/core_ext/array/wrap' require 'active_support/core_ext/object/blank' @@ -23,16 +22,16 @@ module ActionMailer #:nodoc: # # Examples: # - # class Notifier < ActionMailer::Base - # default :from => 'no-reply@example.com', + # class Notifier < ActionMailer::Base + # default :from => 'no-reply@example.com', # :return_path => 'system@example.com' # - # def welcome(recipient) - # @account = recipient - # mail(:to => recipient.email_address_with_name, - # :bcc => ["bcc@example.com", "Order Watcher <watcher@example.com>"]) - # end - # end + # def welcome(recipient) + # @account = recipient + # mail(:to => recipient.email_address_with_name, + # :bcc => ["bcc@example.com", "Order Watcher <watcher@example.com>"]) + # end + # end # # Within the mailer method, you have access to the following methods: # @@ -58,7 +57,7 @@ module ActionMailer #:nodoc: # will accept (any valid Email header including optional fields). # # The mail method, if not passed a block, will inspect your views and send all the views with - # the same name as the method, so the above action would send the +welcome.text.plain.erb+ view + # the same name as the method, so the above action would send the +welcome.text.erb+ view # file as well as the +welcome.text.html.erb+ view file in a +multipart/alternative+ email. # # If you want to explicitly render only certain templates, pass a block: @@ -89,7 +88,7 @@ module ActionMailer #:nodoc: # # To define a template to be used with a mailing, create an <tt>.erb</tt> file with the same # name as the method in your mailer model. For example, in the mailer defined above, the template at - # <tt>app/views/notifier/signup_notification.text.plain.erb</tt> would be used to generate the email. + # <tt>app/views/notifier/welcome.text.erb</tt> would be used to generate the email. # # Variables defined in the model are accessible as instance variables in the view. # @@ -123,21 +122,19 @@ module ActionMailer #:nodoc: # # <%= users_url(:host => "example.com") %> # - # You want to avoid using the <tt>name_of_route_path</tt> form of named routes because it doesn't - # make sense to generate relative URLs in email messages. + # You should use the <tt>named_route_url</tt> style (which generates absolute URLs) and avoid using the + # <tt>named_route_path</tt> style (which generates relative URLs), since clients reading the mail will + # have no concept of a current URL from which to determine a relative path. # # It is also possible to set a default host that will be used in all mailers by setting the <tt>:host</tt> # option as a configuration option in <tt>config/application.rb</tt>: # # config.action_mailer.default_url_options = { :host => "example.com" } # - # Setting <tt>ActionMailer::Base.default_url_options</tt> directly is now deprecated, use the configuration - # option mentioned above to set the default host. - # - # If you do decide to set a default <tt>:host</tt> for your mailers you want to use the - # <tt>:only_path => false</tt> option when using <tt>url_for</tt>. This will ensure that absolute URLs are - # generated because the <tt>url_for</tt> view helper will, by default, generate relative URLs when a - # <tt>:host</tt> option isn't explicitly provided. + # When you decide to set a default <tt>:host</tt> for your mailers, then you need to make sure to use the + # <tt>:only_path => false</tt> option when using <tt>url_for</tt>. Since the <tt>url_for</tt> view helper + # will generate relative URLs by default when a <tt>:host</tt> option isn't explicitly provided, passing + # <tt>:only_path => false</tt> will ensure that absolute URLs are generated. # # = Sending mail # @@ -152,12 +149,12 @@ module ActionMailer #:nodoc: # # = Multipart Emails # - # Multipart messages can also be used implicitly because Action Mailer will automatically - # detect and use multipart templates, where each template is named after the name of the action, followed - # by the content type. Each such detected template will be added as separate part to the message. + # Multipart messages can also be used implicitly because Action Mailer will automatically detect and use + # multipart templates, where each template is named after the name of the action, followed by the content + # type. Each such detected template will be added as a separate part to the message. # # For example, if the following templates exist: - # * signup_notification.text.plain.erb + # * signup_notification.text.erb # * signup_notification.text.html.erb # * signup_notification.text.xml.builder # * signup_notification.text.yaml.erb @@ -182,7 +179,7 @@ module ActionMailer #:nodoc: # end # end # - # Which will (if it had both a <tt>welcome.text.plain.erb</tt> and <tt>welcome.text.html.erb</tt> + # Which will (if it had both a <tt>welcome.text.erb</tt> and <tt>welcome.text.html.erb</tt> # template in the view directory), send a complete <tt>multipart/mixed</tt> email with two parts, # the first part being a <tt>multipart/alternative</tt> with the text and HTML email parts inside, # and the second being a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book @@ -216,15 +213,15 @@ module ActionMailer #:nodoc: # # = Observing and Intercepting Mails # - # Action Mailer provides hooks into the Mail observer and interceptor methods. These allow you to - # register objects that are called during the mail delivery life cycle. + # Action Mailer provides hooks into the Mail observer and interceptor methods. These allow you to + # register classes that are called during the mail delivery life cycle. # - # An observer object must implement the <tt>:delivered_email(message)</tt> method which will be + # An observer class must implement the <tt>:delivered_email(message)</tt> method which will be # called once for every email sent after the email has been sent. # - # An interceptor object must implement the <tt>:delivering_email(message)</tt> method which will be + # An interceptor class 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 any needed modifications directly to the passed + # the delivery agents. Your class should make any needed modifications directly to the passed # in Mail::Message instance. # # = Default Hash @@ -297,9 +294,9 @@ module ActionMailer #:nodoc: # 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>:openssl_verify_mode</tt> - When using TLS, you can set how OpenSSL checks the certificate. This is - # really useful if you need to validate a self-signed and/or a wildcard certificate. You can use the name - # of an OpenSSL verify constant ('none', 'peer', 'client_once','fail_if_no_peer_cert') or directly the + # * <tt>:openssl_verify_mode</tt> - When using TLS, you can set how OpenSSL checks the certificate. This is + # really useful if you need to validate a self-signed and/or a wildcard certificate. You can use the name + # of an OpenSSL verify constant ('none', 'peer', 'client_once','fail_if_no_peer_cert') or directly the # constant (OpenSSL::SSL::VERIFY_NONE, OpenSSL::SSL::VERIFY_PEER,...). # # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method. @@ -315,29 +312,16 @@ module ActionMailer #:nodoc: # # * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default), # <tt>:sendmail</tt>, <tt>:test</tt>, and <tt>:file</tt>. Or you may provide a custom delivery method - # object eg. MyOwnDeliveryMethodClass.new. See the Mail gem documentation on the interface you need to + # object eg. MyOwnDeliveryMethodClass.new. See the Mail gem documentation on the interface you need to # implement for a custom delivery agent. # # * <tt>perform_deliveries</tt> - Determines whether emails are actually sent from Action Mailer when you - # call <tt>.deliver</tt> on an mail message or on an Action Mailer method. This is on by default but can + # call <tt>.deliver</tt> on an mail message or on an Action Mailer method. This is on by default but can # be turned off to aid in functional testing. # # * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with # <tt>delivery_method :test</tt>. Most useful for unit and functional testing. # - # * <tt>default_charset</tt> - This is now deprecated, use the +default+ method above to - # set the default +:charset+. - # - # * <tt>default_content_type</tt> - This is now deprecated, use the +default+ method above - # to set the default +:content_type+. - # - # * <tt>default_mime_version</tt> - This is now deprecated, use the +default+ method above - # to set the default +:mime_version+. - # - # * <tt>default_implicit_parts_order</tt> - This is now deprecated, use the +default+ method above - # to set the default +:parts_order+. Parts Order is used when a message is built implicitly - # (i.e. multiple parts are assembled from templates which specify the content type in their - # filenames) this variable controls how the parts are ordered. class Base < AbstractController::Base include DeliveryMethods abstract! @@ -352,7 +336,6 @@ module ActionMailer #:nodoc: self.protected_instance_variables = %w(@_action_has_layout) helper ActionMailer::MailHelper - include ActionMailer::OldApi private_class_method :new #:nodoc: @@ -383,8 +366,8 @@ module ActionMailer #:nodoc: Mail.register_observer(delivery_observer) end - # Register an Inteceptor which will be called before mail is sent. - # Either a class or a string can be passed in as the Observer. If a string is passed in + # Register an Interceptor which will be called before mail is sent. + # Either a class or a string can be passed in as the Interceptor. If a string is passed in # it will be <tt>constantize</tt>d. def register_interceptor(interceptor) delivery_interceptor = (interceptor.is_a?(String) ? interceptor.constantize : interceptor) @@ -567,8 +550,8 @@ module ActionMailer #:nodoc: # method. # # When a <tt>:return_path</tt> is specified as header, that value will be used as the 'envelope from' - # address for the Mail message. Setting this is useful when you want delivery notifications - # sent to a different address than the one in <tt>:from</tt>. Mail will actually use the + # address for the Mail message. Setting this is useful when you want delivery notifications + # sent to a different address than the one in <tt>:from</tt>. Mail will actually use the # <tt>:return_path</tt> in preference to the <tt>:sender</tt> in preference to the <tt>:from</tt> # field for the 'envelope from' value. # @@ -750,3 +733,4 @@ module ActionMailer #:nodoc: 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 b324ba790d..d1467fb526 100644 --- a/actionmailer/lib/action_mailer/delivery_methods.rb +++ b/actionmailer/lib/action_mailer/delivery_methods.rb @@ -1,7 +1,7 @@ require 'tmpdir' module ActionMailer - # This modules handles everything related to the delivery, from registering new + # This module handles everything related to mail delivery, from registering new # delivery methods to configuring the mail object to be sent. module DeliveryMethods extend ActiveSupport::Concern diff --git a/actionmailer/lib/action_mailer/old_api.rb b/actionmailer/lib/action_mailer/old_api.rb deleted file mode 100644 index bfa9499764..0000000000 --- a/actionmailer/lib/action_mailer/old_api.rb +++ /dev/null @@ -1,255 +0,0 @@ -require 'active_support/concern' -require 'active_support/core_ext/object/try' -require 'active_support/core_ext/object/blank' - -module ActionMailer - module OldApi #:nodoc: - extend ActiveSupport::Concern - - included do - extend ActionMailer::AdvAttrAccessor - self.protected_instance_variables.concat %w(@parts @mail_was_called @headers) - - # Specify the BCC addresses for the message - adv_attr_accessor :bcc - - # Specify the CC addresses for the message. - adv_attr_accessor :cc - - # Specify the charset to use for the message. This defaults to the - # +default_charset+ specified for ActionMailer::Base. - adv_attr_accessor :charset - - # Specify the content type for the message. This defaults to <tt>text/plain</tt> - # in most cases, but can be automatically set in some situations. - adv_attr_accessor :content_type - - # Specify the from address for the message. - adv_attr_accessor :from - - # Specify the address (if different than the "from" address) to direct - # replies to this message. - adv_attr_accessor :reply_to - - # Specify the order in which parts should be sorted, based on content-type. - # This defaults to the value for the +default_implicit_parts_order+. - adv_attr_accessor :implicit_parts_order - - # Defaults to "1.0", but may be explicitly given if needed. - adv_attr_accessor :mime_version - - # The recipient addresses for the message, either as a string (for a single - # address) or an array (for multiple addresses). - 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, "Please pass :date as hash key to mail() instead" - - # Specify the subject of the message. - adv_attr_accessor :subject - - # 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, "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 - end - - def process(method_name, *args) - initialize_defaults(method_name) - super - unless @mail_was_called - create_parts - create_mail - end - @_message - end - - # 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) - 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) - 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) - 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) - - if params[:filename] - params = normalize_file_hash(params) - else - params = normalize_nonfile_hash(params) - end - - part(params, &block) - end - - protected - - 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 - m = @_message - - set_fields!({:subject => @subject, :to => @recipients, :from => @from, - :bcc => @bcc, :cc => @cc, :reply_to => @reply_to}, @charset) - - 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 } - - real_content_type, ctype_attrs = parse_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 - @parts.each do |p| - 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" - m.content_type([main_type, sub_type, ctype_attrs]) - end - end - - 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) - @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 - - @parts ||= [] - @headers ||= {} - @sent_on ||= Time.now - @body ||= {} - end - - 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| - self.formats = template.formats - @parts << create_inline_part(render(:template => template), template.mime_type) - end - - if @parts.size > 1 - @content_type = "multipart/alternative" if @content_type !~ /^multipart/ - end - - # If this is a multipart e-mail add the mime_version if it is not - # already set. - @mime_version ||= "1.0" unless @parts.empty? - end - end - - def create_inline_part(body, mime_type=nil) - ct = mime_type || "text/plain" - main_type, sub_type = split_content_type(ct.to_s) - - Mail::Part.new( - :content_type => [main_type, sub_type, {:charset => charset}], - :content_disposition => "inline", - :body => body - ) - end - - def set_fields!(headers, charset) #:nodoc: - m = @_message - m.charset = charset - m.subject ||= headers.delete(:subject) if headers[:subject] - m.to ||= headers.delete(:to) if headers[:to] - m.from ||= headers.delete(:from) if headers[:from] - m.cc ||= headers.delete(:cc) if headers[:cc] - m.bcc ||= headers.delete(:bcc) if headers[:bcc] - m.reply_to ||= headers.delete(:reply_to) if headers[:reply_to] - end - - def split_content_type(ct) - ct.to_s.split("/") - end - - def parse_content_type - if @content_type.blank? - [ nil, {} ] - else - ctype, *attrs = @content_type.split(/;\s*/) - attrs = Hash[attrs.map { |attr| attr.split(/=/, 2) }] - [ctype, {"charset" => @charset}.merge!(attrs)] - end - end - end -end diff --git a/actionmailer/lib/action_mailer/tmail_compat.rb b/actionmailer/lib/action_mailer/tmail_compat.rb deleted file mode 100644 index 1b2cdcfb27..0000000000 --- a/actionmailer/lib/action_mailer/tmail_compat.rb +++ /dev/null @@ -1,37 +0,0 @@ -module Mail - class Message - - def set_content_type(*args) - 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 - 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 - end - end - - def transfer_encoding=(value) - 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 - message = 'Message#original_filename is deprecated, please call Message#filename' - ActiveSupport::Deprecation.warn(message, caller[0,2]) - filename - end - - end -end diff --git a/actionmailer/lib/action_mailer/version.rb b/actionmailer/lib/action_mailer/version.rb index 5654e54d7a..b74ba3cb0d 100644 --- a/actionmailer/lib/action_mailer/version.rb +++ b/actionmailer/lib/action_mailer/version.rb @@ -1,9 +1,9 @@ module ActionMailer module VERSION #:nodoc: MAJOR = 3 - MINOR = 1 + MINOR = 2 TINY = 0 - PRE = "rc1" + PRE = "beta" STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/actionmailer/test/log_subscriber_test.rb b/actionmailer/test/log_subscriber_test.rb index ba9b4d6500..5f52a1bd69 100644 --- a/actionmailer/test/log_subscriber_test.rb +++ b/actionmailer/test/log_subscriber_test.rb @@ -1,4 +1,5 @@ require "abstract_unit" +require 'mailers/base_mailer' require "active_support/log_subscriber/test_helper" require "action_mailer/log_subscriber" @@ -11,13 +12,6 @@ class AMLogSubscriberTest < ActionMailer::TestCase end class TestMailer < ActionMailer::Base - def basic - recipients "somewhere@example.com" - subject "basic" - from "basic@example.com" - body "Hello world" - end - def receive(mail) # Do nothing end @@ -28,12 +22,12 @@ class AMLogSubscriberTest < ActionMailer::TestCase end def test_deliver_is_notified - TestMailer.basic.deliver + BaseMailer.welcome.deliver wait assert_equal(1, @logger.logged(:info).size) - assert_match(/Sent mail to somewhere@example.com/, @logger.logged(:info).first) + assert_match(/Sent mail to system@test.lindsaar.net/, @logger.logged(:info).first) assert_equal(1, @logger.logged(:debug).size) - assert_match(/Hello world/, @logger.logged(:debug).first) + assert_match(/Welcome/, @logger.logged(:debug).first) end def test_receive_is_notified diff --git a/actionmailer/test/old_base/adv_attr_test.rb b/actionmailer/test/old_base/adv_attr_test.rb deleted file mode 100644 index c5a6b6d88b..0000000000 --- a/actionmailer/test/old_base/adv_attr_test.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'abstract_unit' -require 'action_mailer/adv_attr_accessor' - -class AdvAttrTest < ActiveSupport::TestCase - class Person - cattr_reader :protected_instance_variables - @@protected_instance_variables = [] - - extend ActionMailer::AdvAttrAccessor - adv_attr_accessor :name - 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' - 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 - - def test_ivar_is_added_to_protected_instnace_variables - assert Person.protected_instance_variables.include?('@name') - end -end diff --git a/actionmailer/test/old_base/mail_render_test.rb b/actionmailer/test/old_base/mail_render_test.rb deleted file mode 100644 index 3a1d3184f4..0000000000 --- a/actionmailer/test/old_base/mail_render_test.rb +++ /dev/null @@ -1,134 +0,0 @@ -require 'abstract_unit' - -class RenderMailer < ActionMailer::Base - def inline_template - recipients 'test@localhost' - subject "using helpers" - from "tester@example.com" - - @world = "Earth" - body render(:inline => "Hello, <%= @world %>") - end - - def file_template - recipients 'test@localhost' - subject "using helpers" - from "tester@example.com" - - @recipient = 'test@localhost' - body render(:file => "templates/signed_up") - end - - def no_instance_variable - recipients 'test@localhost' - subject "No Instance Variable" - from "tester@example.com" - - silence_warnings do - body render(:inline => "Look, subject.nil? is <%= @subject.nil? %>!") - end - end - - def multipart_alternative - recipients 'test@localhost' - subject 'multipart/alternative' - from 'tester@example.com' - - build_multipart_message(:foo => "bar") - end - - private - def build_multipart_message(assigns = {}) - content_type "multipart/alternative" - - part "text/plain" do |p| - p.body = build_body_part('plain', assigns, :layout => false) - end - - part "text/html" do |p| - p.body = build_body_part('html', assigns) - end - end - - def build_body_part(content_type, assigns, options = {}) - ActiveSupport::Deprecation.silence do - render "#{template}.#{content_type}", :body => assigns - end - end -end - -class FirstMailer < ActionMailer::Base - def share - recipients 'test@localhost' - subject "using helpers" - from "tester@example.com" - end -end - -class SecondMailer < ActionMailer::Base - def share - recipients 'test@localhost' - subject "using helpers" - from "tester@example.com" - 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 - 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 - - def test_inline_template - mail = RenderMailer.inline_template - assert_equal "Hello, Earth", mail.body.to_s.strip - end - - def test_file_template - mail = RenderMailer.file_template - 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 -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 - - @recipient = 'test@localhost' - end - - def teardown - ActiveSupport::Deprecation.silenced = false - restore_delivery_method - end - - def test_ordering - mail = FirstMailer.share - assert_equal "first mail", mail.body.to_s.strip - mail = SecondMailer.share - assert_equal "second mail", mail.body.to_s.strip - mail = FirstMailer.share - assert_equal "first mail", mail.body.to_s.strip - mail = SecondMailer.share - assert_equal "second mail", mail.body.to_s.strip - end -end diff --git a/actionmailer/test/old_base/mail_service_test.rb b/actionmailer/test/old_base/mail_service_test.rb deleted file mode 100644 index 0b5b0b2da3..0000000000 --- a/actionmailer/test/old_base/mail_service_test.rb +++ /dev/null @@ -1,1097 +0,0 @@ -# encoding: utf-8 -require 'abstract_unit' - -class FunkyPathMailer < ActionMailer::Base - self.view_paths = "#{File.dirname(__FILE__)}/../fixtures/path.with.dots" - - def multipart_with_template_path_with_dots(recipient) - recipients recipient - subject "This path has dots" - from "Chad Fowler <chad@chadfowler.com>" - attachment :content_type => "text/plain", - :data => "dots dots dots..." - end -end - -class TestMailer < ActionMailer::Base - def signed_up(recipient) - recipients recipient - subject "[Signed up] Welcome #{recipient}" - from "system@loudthinking.com" - - @recipient = recipient - end - - def cancelled_account(recipient) - recipients recipient - subject "[Cancelled] Goodbye #{recipient}" - from "system@loudthinking.com" - sent_on Time.local(2004, 12, 12) - body "Goodbye, Mr. #{recipient}" - end - - def from_with_name - from "System <system@loudthinking.com>" - recipients "root@loudthinking.com" - body "Nothing to see here." - end - - def from_without_name - from "system@loudthinking.com" - recipients "root@loudthinking.com" - body "Nothing to see here." - end - - def cc_bcc(recipient) - recipients recipient - subject "testing bcc/cc" - from "system@loudthinking.com" - sent_on Time.local(2004, 12, 12) - cc "nobody@loudthinking.com" - bcc "root@loudthinking.com" - - body "Nothing to see here." - end - - def different_reply_to(recipient) - recipients recipient - subject "testing reply_to" - from "system@loudthinking.com" - sent_on Time.local(2008, 5, 23) - reply_to "atraver@gmail.com" - - body "Nothing to see here." - end - - def iso_charset(recipient) - recipients recipient - subject "testing isø charsets" - from "system@loudthinking.com" - sent_on Time.local(2004, 12, 12) - cc "nobody@loudthinking.com" - bcc "root@loudthinking.com" - charset "iso-8859-1" - - body "Nothing to see here." - end - - def unencoded_subject(recipient) - recipients recipient - subject "testing unencoded subject" - from "system@loudthinking.com" - sent_on Time.local(2004, 12, 12) - cc "nobody@loudthinking.com" - bcc "root@loudthinking.com" - - body "Nothing to see here." - end - - def extended_headers(recipient) - recipients recipient - subject "testing extended headers" - from "Grytøyr <stian1@example.net>" - sent_on Time.local(2004, 12, 12) - cc "Grytøyr <stian2@example.net>" - bcc "Grytøyr <stian3@example.net>" - charset "iso-8859-1" - - body "Nothing to see here." - end - - def utf8_body(recipient) - recipients recipient - subject "testing utf-8 body" - from "Foo áëô îü <extended@example.net>" - sent_on Time.local(2004, 12, 12) - cc "Foo áëô îü <extended@example.net>" - bcc "Foo áëô îü <extended@example.net>" - charset "UTF-8" - - body "åœö blah" - end - - def multipart_with_mime_version(recipient) - recipients recipient - subject "multipart with mime_version" - from "test@example.com" - sent_on Time.local(2004, 12, 12) - mime_version "1.1" - content_type "multipart/alternative" - - part "text/plain" do |p| - p.body = render(:text => "blah") - end - - part "text/html" do |p| - p.body = render(:inline => "<%= content_tag(:b, 'blah') %>") - end - end - - def multipart_with_utf8_subject(recipient) - recipients recipient - subject "Foo áëô îü" - from "test@example.com" - charset "UTF-8" - - part "text/plain" do |p| - p.body = "blah" - end - - part "text/html" do |p| - p.body = "<b>blah</b>" - end - end - - def explicitly_multipart_example(recipient, ct=nil) - recipients recipient - subject "multipart example" - from "test@example.com" - sent_on Time.local(2004, 12, 12) - content_type ct if ct - - part "text/html" do |p| - p.charset = "iso-8859-1" - p.body = "blah" - end - - attachment :content_type => "image/jpeg", :filename => File.join(File.dirname(__FILE__), "fixtures", "attachments", "foo.jpg"), - :data => "123456789" - - body "plain text default" - end - - def implicitly_multipart_example(recipient, cs = nil, order = nil) - recipients recipient - subject "multipart example" - from "test@example.com" - sent_on Time.local(2004, 12, 12) - - @charset = cs if cs - @recipient = recipient - @implicit_parts_order = order if order - end - - def implicitly_multipart_with_utf8 - recipients "no.one@nowhere.test" - subject "Foo áëô îü" - from "some.one@somewhere.test" - template "implicitly_multipart_example" - - @recipient = "no.one@nowhere.test" - end - - def html_mail(recipient) - recipients recipient - subject "html mail" - from "test@example.com" - content_type "text/html" - - body "<em>Emphasize</em> <strong>this</strong>" - end - - def html_mail_with_underscores(recipient) - subject "html mail with underscores" - body %{<a href="http://google.com" target="_blank">_Google</a>} - end - - def custom_template(recipient) - recipients recipient - subject "[Signed up] Welcome #{recipient}" - from "system@loudthinking.com" - sent_on Time.local(2004, 12, 12) - template "signed_up" - - @recipient = recipient - end - - def custom_templating_extension(recipient) - recipients recipient - subject "[Signed up] Welcome #{recipient}" - from "system@loudthinking.com" - sent_on Time.local(2004, 12, 12) - - @recipient = recipient - end - - def various_newlines(recipient) - recipients recipient - subject "various newlines" - from "test@example.com" - - body "line #1\nline #2\rline #3\r\nline #4\r\r" + - "line #5\n\nline#6\r\n\r\nline #7" - end - - def various_newlines_multipart(recipient) - recipients recipient - subject "various newlines multipart" - from "test@example.com" - content_type "multipart/alternative" - - part :content_type => "text/plain", :body => "line #1\nline #2\rline #3\r\nline #4\r\r" - part :content_type => "text/html", :body => "<p>line #1</p>\n<p>line #2</p>\r<p>line #3</p>\r\n<p>line #4</p>\r\r" - end - - def nested_multipart(recipient) - recipients recipient - subject "nested multipart" - from "test@example.com" - content_type "multipart/mixed" - - 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 - - attachment :content_type => "application/octet-stream", :filename => "test.txt", :data => "test abcdefghijklmnopqstuvwxyz" - end - - def nested_multipart_with_body(recipient) - recipients recipient - subject "nested multipart with body" - from "test@example.com" - content_type "multipart/mixed" - - part :content_type => "multipart/alternative", :content_disposition => "inline", :body => "Nothing to see here." do |p| - p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>" - end - end - - def attachment_with_custom_header(recipient) - recipients recipient - subject "custom header in attachment" - 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", 'Content-ID' => '<test@test.com>' - end - - def unnamed_attachment(recipient) - recipients recipient - subject "nested multipart" - from "test@example.com" - content_type "multipart/mixed" - part :content_type => "text/plain", :body => "hullo" - attachment :content_type => "application/octet-stream", :data => "test abcdefghijklmnopqstuvwxyz" - end - - def headers_with_nonalpha_chars(recipient) - recipients recipient - subject "nonalpha chars" - from "One: Two <test@example.com>" - cc "Three: Four <test@example.com>" - bcc "Five: Six <test@example.com>" - body "testing" - end - - def custom_content_type_attributes - recipients "no.one@nowhere.test" - subject "custom content types" - from "some.one@somewhere.test" - content_type "text/plain; format=flowed" - body "testing" - end - - def return_path - recipients "no.one@nowhere.test" - subject "return path test" - from "some.one@somewhere.test" - headers["return-path"] = "another@somewhere.test" - body "testing" - end - - def subject_with_i18n(recipient) - recipients recipient - from "system@loudthinking.com" - body "testing" - end - - class << self - attr_accessor :received_body - end - - def receive(mail) - self.class.received_body = mail.body - end -end - -class ActionMailerTest < Test::Unit::TestCase - - def encode( text, charset="UTF-8" ) - Mail::Encodings.q_value_encode( text, charset ) - end - - def new_mail( charset="UTF-8" ) - mail = Mail.new - mail.charset = charset - mail.mime_version = "1.0" - mail - end - - 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 - - @recipient = 'test@localhost' - - TestMailer.delivery_method = :test - end - - def teardown - ActiveSupport::Deprecation.silenced = false - restore_delivery_method - end - - def test_nested_parts - created = nil - assert_nothing_raised { created = TestMailer.nested_multipart(@recipient)} - assert_equal 2, created.parts.size - assert_equal 2, created.parts.first.parts.size - - assert_equal "multipart/mixed", created.mime_type - assert_equal "multipart/alternative", created.parts[0].mime_type - assert_equal "bar", created.parts[0].header['foo'].to_s - assert_not_nil created.parts[0].charset - 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 - created = nil - TestMailer.nested_multipart_with_body(@recipient) - assert_nothing_raised { created = TestMailer.nested_multipart_with_body(@recipient)} - - assert_equal 1,created.parts.size - assert_equal 2,created.parts.first.parts.size - - assert_equal "multipart/mixed", created.mime_type - assert_equal "multipart/alternative", created.parts.first.mime_type - assert_equal "text/plain", created.parts.first.parts.first.mime_type - assert_equal "Nothing to see here.", created.parts.first.parts.first.body.to_s - assert_equal "text/html", created.parts.first.parts.second.mime_type - assert_equal "<b>test</b> HTML<br/>", created.parts.first.parts.second.body.to_s - end - - def test_attachment_with_custom_header - created = nil - assert_nothing_raised { created = TestMailer.attachment_with_custom_header(@recipient) } - assert created.parts.any? { |p| p.header['content-id'].to_s == "<test@test.com>" } - end - - def test_signed_up - TestMailer.delivery_method = :test - - Time.stubs(:now => Time.now) - - expected = new_mail - expected.to = @recipient - expected.subject = "[Signed up] Welcome #{@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>' - - assert_equal expected.encoded, created.encoded - - assert_nothing_raised { TestMailer.signed_up(@recipient).deliver } - - 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 - - def test_custom_template - expected = new_mail - expected.to = @recipient - expected.subject = "[Signed up] Welcome #{@recipient}" - expected.body = "Hello there,\n\nMr. #{@recipient}" - expected.from = "system@loudthinking.com" - expected.date = Time.local(2004, 12, 12) - - created = nil - assert_nothing_raised { created = TestMailer.custom_template(@recipient) } - assert_not_nil created - expected.message_id = '<123@456>' - created.message_id = '<123@456>' - assert_equal expected.encoded, created.encoded - end - - def test_custom_templating_extension - assert ActionView::Template.template_handler_extensions.include?("haml"), "haml extension was not registered" - - # N.b., custom_templating_extension.text.plain.haml is expected to be in fixtures/test_mailer directory - expected = new_mail - expected.to = @recipient - expected.subject = "[Signed up] Welcome #{@recipient}" - expected.body = "Hello there, \n\nMr. #{@recipient}" - expected.from = "system@loudthinking.com" - expected.date = Time.local(2004, 12, 12) - - # Now that the template is registered, there should be one part. The text/plain part. - created = nil - assert_nothing_raised { created = TestMailer.custom_templating_extension(@recipient) } - assert_not_nil created - assert_equal 2, created.parts.length - assert_equal 'text/plain', created.parts[0].mime_type - assert_equal 'text/html', created.parts[1].mime_type - end - - def test_cancelled_account - expected = new_mail - expected.to = @recipient - expected.subject = "[Cancelled] Goodbye #{@recipient}" - expected.body = "Goodbye, Mr. #{@recipient}" - expected.from = "system@loudthinking.com" - expected.date = Time.local(2004, 12, 12) - - created = nil - assert_nothing_raised { created = TestMailer.cancelled_account(@recipient) } - assert_not_nil created - expected.message_id = '<123@456>' - created.message_id = '<123@456>' - assert_equal expected.encoded, created.encoded - - assert_nothing_raised { TestMailer.cancelled_account(@recipient).deliver } - assert_not_nil ActionMailer::Base.deliveries.first - delivered = ActionMailer::Base.deliveries.first - expected.message_id = '<123@456>' - delivered.message_id = '<123@456>' - - assert_equal expected.encoded, delivered.encoded - end - - def test_cc_bcc - expected = new_mail - expected.to = @recipient - expected.subject = "testing bcc/cc" - expected.body = "Nothing to see here." - expected.from = "system@loudthinking.com" - expected.cc = "nobody@loudthinking.com" - expected.bcc = "root@loudthinking.com" - expected.date = Time.local 2004, 12, 12 - - created = nil - assert_nothing_raised do - created = TestMailer.cc_bcc @recipient - end - assert_not_nil created - expected.message_id = '<123@456>' - created.message_id = '<123@456>' - assert_equal expected.encoded, created.encoded - - assert_nothing_raised do - TestMailer.cc_bcc(@recipient).deliver - end - - assert_not_nil ActionMailer::Base.deliveries.first - delivered = ActionMailer::Base.deliveries.first - expected.message_id = '<123@456>' - delivered.message_id = '<123@456>' - - assert_equal expected.encoded, delivered.encoded - end - - def test_from_without_name_for_smtp - TestMailer.delivery_method = :smtp - TestMailer.from_without_name.deliver - - 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 - TestMailer.delivery_method = :smtp - TestMailer.from_with_name.deliver - - mail = MockSMTP.deliveries.first - assert_not_nil mail - mail, from, to = mail - - assert_equal 'system@loudthinking.com', from - end - - def test_reply_to - TestMailer.delivery_method = :test - - expected = new_mail - - expected.to = @recipient - expected.subject = "testing reply_to" - expected.body = "Nothing to see here." - expected.from = "system@loudthinking.com" - expected.reply_to = "atraver@gmail.com" - expected.date = Time.local 2008, 5, 23 - - created = nil - assert_nothing_raised do - 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 - TestMailer.different_reply_to(@recipient).deliver - end - - 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 - - def test_iso_charset - TestMailer.delivery_method = :test - expected = new_mail( "iso-8859-1" ) - expected.to = @recipient - expected.subject = encode "testing isø charsets", "iso-8859-1" - expected.body = "Nothing to see here." - expected.from = "system@loudthinking.com" - expected.cc = "nobody@loudthinking.com" - expected.bcc = "root@loudthinking.com" - expected.date = Time.local 2004, 12, 12 - - created = nil - assert_nothing_raised do - created = TestMailer.iso_charset @recipient - end - assert_not_nil created - - expected.message_id = '<123@456>' - created.message_id = '<123@456>' - - assert_equal expected.encoded, created.encoded - - assert_nothing_raised do - TestMailer.iso_charset(@recipient).deliver - end - - 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 - - def test_unencoded_subject - TestMailer.delivery_method = :test - expected = new_mail - expected.to = @recipient - expected.subject = "testing unencoded subject" - expected.body = "Nothing to see here." - expected.from = "system@loudthinking.com" - expected.cc = "nobody@loudthinking.com" - expected.bcc = "root@loudthinking.com" - expected.date = Time.local 2004, 12, 12 - - created = nil - assert_nothing_raised do - created = TestMailer.unencoded_subject @recipient - end - assert_not_nil created - - expected.message_id = '<123@456>' - created.message_id = '<123@456>' - - assert_equal expected.encoded, created.encoded - - assert_nothing_raised do - TestMailer.unencoded_subject(@recipient).deliver - end - - 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 - - def test_deliveries_array - assert_not_nil ActionMailer::Base.deliveries - assert_equal 0, ActionMailer::Base.deliveries.size - TestMailer.signed_up(@recipient).deliver - assert_equal 1, ActionMailer::Base.deliveries.size - assert_not_nil ActionMailer::Base.deliveries.first - end - - def test_perform_deliveries_flag - ActionMailer::Base.perform_deliveries = false - TestMailer.signed_up(@recipient).deliver - assert_equal 0, ActionMailer::Base.deliveries.size - ActionMailer::Base.perform_deliveries = true - TestMailer.signed_up(@recipient).deliver - assert_equal 1, ActionMailer::Base.deliveries.size - end - - def test_doesnt_raise_errors_when_raise_delivery_errors_is_false - ActionMailer::Base.raise_delivery_errors = false - Mail::TestMailer.any_instance.expects(:deliver!).raises(Exception) - assert_nothing_raised { TestMailer.signed_up(@recipient).deliver } - end - - def test_performs_delivery_via_sendmail - IO.expects(:popen).once.with('/usr/sbin/sendmail -i -t -f "system@loudthinking.com" test@localhost', 'w+') - TestMailer.delivery_method = :sendmail - TestMailer.signed_up(@recipient).deliver - end - - def test_unquote_quoted_printable_subject - msg = <<EOF -From: me@example.com -Subject: =?UTF-8?Q?testing_testing_=D6=A4?= -Content-Type: text/plain; charset=iso-8859-1 - -The body -EOF - mail = Mail.new(msg) - assert_equal "testing testing \326\244", mail.subject - assert_equal "Subject: =?UTF-8?Q?testing_testing_=D6=A4?=\r\n", mail[:subject].encoded - end - - def test_unquote_7bit_subject - msg = <<EOF -From: me@example.com -Subject: this == working? -Content-Type: text/plain; charset=iso-8859-1 - -The body -EOF - mail = Mail.new(msg) - assert_equal "this == working?", mail.subject - assert_equal "Subject: this == working?\r\n", mail[:subject].encoded - end - - def test_unquote_7bit_body - msg = <<EOF -From: me@example.com -Subject: subject -Content-Type: text/plain; charset=iso-8859-1 -Content-Transfer-Encoding: 7bit - -The=3Dbody -EOF - mail = Mail.new(msg) - assert_equal "The=3Dbody", mail.body.to_s.strip - assert_equal "The=3Dbody", mail.body.encoded.strip - end - - def test_unquote_quoted_printable_body - msg = <<EOF -From: me@example.com -Subject: subject -Content-Type: text/plain; charset=iso-8859-1 -Content-Transfer-Encoding: quoted-printable - -The=3Dbody -EOF - mail = Mail.new(msg) - assert_equal "The=body", mail.body.to_s.strip - assert_equal "The=3Dbody=", mail.body.encoded.strip - end - - def test_unquote_base64_body - msg = <<EOF -From: me@example.com -Subject: subject -Content-Type: text/plain; charset=iso-8859-1 -Content-Transfer-Encoding: base64 - -VGhlIGJvZHk= -EOF - mail = Mail.new(msg) - assert_equal "The body", mail.body.to_s.strip - assert_equal "VGhlIGJvZHk=", mail.body.encoded.strip - end - - def test_extended_headers - @recipient = "Grytøyr <test@localhost>" - - expected = new_mail "iso-8859-1" - expected.to = @recipient - expected.subject = "testing extended headers" - expected.body = "Nothing to see here." - expected.from = "Grytøyr <stian1@example.net>" - expected.cc = "Grytøyr <stian2@example.net>" - expected.bcc = "Grytøyr <stian3@example.net>" - expected.date = Time.local 2004, 12, 12 - - created = nil - assert_nothing_raised do - created = TestMailer.extended_headers @recipient - end - - assert_not_nil created - expected.message_id = '<123@456>' - created.message_id = '<123@456>' - - assert_equal expected.encoded, created.encoded - - assert_nothing_raised do - TestMailer.extended_headers(@recipient).deliver - end - - 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 - - def test_utf8_body_is_not_quoted - @recipient = "Foo áëô îü <extended@example.net>" - expected = new_mail "UTF-8" - expected.to = @recipient - expected.subject = "testing UTF-8 body" - expected.body = "åœö blah" - expected.from = @recipient - expected.cc = @recipient - expected.bcc = @recipient - expected.date = Time.local 2004, 12, 12 - - created = TestMailer.utf8_body @recipient - assert_match(/åœö blah/, created.decoded) - end - - def test_multiple_utf8_recipients - @recipient = ["\"Foo áëô îü\" <extended@example.net>", "\"Example Recipient\" <me@example.com>"] - expected = new_mail "UTF-8" - expected.to = @recipient - expected.subject = "testing UTF-8 body" - expected.body = "åœö blah" - expected.from = @recipient.first - expected.cc = @recipient - expected.bcc = @recipient - expected.date = Time.local 2004, 12, 12 - - created = TestMailer.utf8_body @recipient - from_regexp = Regexp.escape('From: Foo =?UTF-8?B?w6HDq8O0?= =?UTF-8?B?IMOuw7w=?=') - assert_match(/#{from_regexp}/m, created.encoded) - - to_regexp = Regexp.escape("To: =?UTF-8?B?Rm9vIMOhw6vDtCDDrsO8?= <extended@example.net>") - assert_match(/#{to_regexp}/m, created.encoded) - end - - 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.to_s) - end - - def test_receive_attachments - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email2") - mail = Mail.new(fixture) - attachment = mail.attachments.last - assert_equal "smime.p7s", attachment.filename - assert_equal "application/pkcs7-signature", mail.parts.last.mime_type - end - - def test_decode_attachment_without_charset - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email3") - mail = Mail.new(fixture) - attachment = mail.attachments.last - assert_equal 1026, attachment.read.length - end - - def test_attachment_using_content_location - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email12") - mail = Mail.new(fixture) - assert_equal 1, mail.attachments.length - assert_equal "Photo25.jpg", mail.attachments.first.filename - end - - def test_attachment_with_text_type - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email13") - mail = Mail.new(fixture) - assert mail.has_attachments? - assert_equal 1, mail.attachments.length - assert_equal "hello.rb", mail.attachments.first.filename - end - - def test_decode_part_without_content_type - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email4") - mail = Mail.new(fixture) - assert_nothing_raised { mail.body } - end - - def test_decode_message_without_content_type - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email5") - mail = Mail.new(fixture) - assert_nothing_raised { mail.body } - end - - def test_decode_message_with_incorrect_charset - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email6") - mail = Mail.new(fixture) - assert_nothing_raised { mail.body } - end - - def test_multipart_with_mime_version - mail = TestMailer.multipart_with_mime_version(@recipient) - assert_equal "1.1", mail.mime_version - end - - def test_multipart_with_utf8_subject - mail = TestMailer.multipart_with_utf8_subject(@recipient) - regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4_=C3=AE=C3=BC?=') - assert_match(/#{regex}/, mail.encoded) - string = "Foo áëô îü" - assert_match(string, mail.subject) - end - - def test_implicitly_multipart_with_utf8 - mail = TestMailer.implicitly_multipart_with_utf8 - regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4_=C3=AE=C3=BC?=') - assert_match(/#{regex}/, mail.encoded) - string = "Foo áëô îü" - assert_match(string, mail.subject) - end - - def test_explicitly_multipart_messages - mail = TestMailer.explicitly_multipart_example(@recipient) - assert_equal 3, mail.parts.length - assert_equal 'multipart/mixed', mail.mime_type - assert_equal "text/plain", mail.parts[0].mime_type - - assert_equal "text/html", mail.parts[1].mime_type - 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 - assert_nil mail.parts[2].charset - end - - def test_explicitly_multipart_with_content_type - mail = TestMailer.explicitly_multipart_example(@recipient, "multipart/alternative") - assert_equal 3, mail.parts.length - assert_equal "multipart/alternative", mail.mime_type - end - - def test_explicitly_multipart_with_invalid_content_type - mail = TestMailer.explicitly_multipart_example(@recipient, "text/xml") - assert_equal 3, mail.parts.length - assert_equal 'multipart/mixed', mail.mime_type - end - - def test_implicitly_multipart_messages - assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered" - - mail = TestMailer.implicitly_multipart_example(@recipient) - assert_equal 3, mail.parts.length - assert_equal "1.0", mail.mime_version.to_s - assert_equal "multipart/alternative", mail.mime_type - assert_equal "text/plain", mail.parts[0].mime_type - assert_equal "UTF-8", mail.parts[0].charset - assert_equal "text/html", mail.parts[1].mime_type - assert_equal "UTF-8", mail.parts[1].charset - assert_equal "application/x-yaml", mail.parts[2].mime_type - assert_equal "UTF-8", mail.parts[2].charset - end - - def test_implicitly_multipart_messages_with_custom_order - assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered" - - mail = TestMailer.implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"]) - assert_equal 3, mail.parts.length - assert_equal "application/x-yaml", mail.parts[0].mime_type - assert_equal "text/plain", mail.parts[1].mime_type - assert_equal "text/html", mail.parts[2].mime_type - end - - def test_implicitly_multipart_messages_with_charset - mail = TestMailer.implicitly_multipart_example(@recipient, 'iso-8859-1') - - assert_equal "multipart/alternative", mail.header['content-type'].content_type - - assert_equal 'iso-8859-1', mail.parts[0].content_type_parameters[:charset] - assert_equal 'iso-8859-1', mail.parts[1].content_type_parameters[:charset] - assert_equal 'iso-8859-1', mail.parts[2].content_type_parameters[:charset] - end - - def test_html_mail - mail = TestMailer.html_mail(@recipient) - assert_equal "text/html", mail.mime_type - end - - def test_html_mail_with_underscores - mail = TestMailer.html_mail_with_underscores(@recipient) - assert_equal %{<a href="http://google.com" target="_blank">_Google</a>}, mail.body.to_s - end - - def test_various_newlines - mail = TestMailer.various_newlines(@recipient) - assert_equal("line #1\nline #2\nline #3\nline #4\n\n" + - "line #5\n\nline#6\n\nline #7", mail.body.to_s) - end - - def test_various_newlines_multipart - mail = TestMailer.various_newlines_multipart(@recipient) - assert_equal "line #1\nline #2\nline #3\nline #4\n\n", mail.parts[0].body.to_s - assert_equal "<p>line #1</p>\n<p>line #2</p>\n<p>line #3</p>\n<p>line #4</p>\n\n", mail.parts[1].body.to_s - assert_equal "line #1\r\nline #2\r\nline #3\r\nline #4\r\n\r\n", mail.parts[0].body.encoded - 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 - - def test_headers_removed_on_smtp_delivery - TestMailer.delivery_method = :smtp - TestMailer.cc_bcc(@recipient).deliver - assert MockSMTP.deliveries[0][2].include?("root@loudthinking.com") - assert MockSMTP.deliveries[0][2].include?("nobody@loudthinking.com") - assert MockSMTP.deliveries[0][2].include?(@recipient) - assert_match %r{^Cc: nobody@loudthinking.com}, MockSMTP.deliveries[0][0] - assert_match %r{^To: #{@recipient}}, MockSMTP.deliveries[0][0] - assert_no_match %r{^Bcc: root@loudthinking.com}, MockSMTP.deliveries[0][0] - end - - def test_file_delivery_should_create_a_file - TestMailer.delivery_method = :file - tmp_location = TestMailer.file_settings[:location] - - result = TestMailer.cc_bcc(@recipient).deliver - assert File.exists?(tmp_location) - assert File.directory?(tmp_location) - assert File.exists?(File.join(tmp_location, @recipient)) - assert File.exists?(File.join(tmp_location, 'nobody@loudthinking.com')) - assert File.exists?(File.join(tmp_location, 'root@loudthinking.com')) - end - - def test_recursive_multipart_processing - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email7") - 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.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) - end - - def test_decode_encoded_attachment_filename - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email8") - mail = Mail.new(fixture) - 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) - result.force_encoding(Encoding::ASCII_8BIT) - assert_equal expected, result - else - assert_equal expected, attachment.filename - end - end - - def test_decode_message_with_unknown_charset - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email10") - mail = Mail.new(fixture) - assert_nothing_raised { mail.body } - end - - def test_empty_header_values_omitted - result = TestMailer.unnamed_attachment(@recipient).encoded - assert_match %r{Content-Type: application/octet-stream}, result - assert_match %r{Content-Disposition: attachment}, result - end - - def test_headers_with_nonalpha_chars - mail = TestMailer.headers_with_nonalpha_chars(@recipient) - assert !mail.from_addrs.empty? - assert !mail.cc_addrs.empty? - assert !mail.bcc_addrs.empty? - assert_match(/:/, mail[:from].decoded) - assert_match(/:/, mail[:cc].decoded) - assert_match(/:/, mail[:bcc].decoded) - end - - def test_with_mail_object_deliver - TestMailer.delivery_method = :test - mail = TestMailer.headers_with_nonalpha_chars(@recipient) - assert_nothing_raised { mail.deliver } - assert_equal 1, TestMailer.deliveries.length - end - - def test_multipart_with_template_path_with_dots - mail = FunkyPathMailer.multipart_with_template_path_with_dots(@recipient) - assert_equal 2, mail.parts.length - assert_equal "text/plain", mail.parts[0].mime_type - assert_equal "text/html", mail.parts[1].mime_type - assert_equal "UTF-8", mail.parts[1].charset - end - - def test_custom_content_type_attributes - mail = TestMailer.custom_content_type_attributes - assert_match %r{format=flowed}, mail.content_type - assert_match %r{charset=UTF-8}, mail.content_type - end - - def test_return_path_with_create - mail = TestMailer.return_path - assert_equal "another@somewhere.test", mail.return_path - end - - def test_return_path_with_deliver - TestMailer.delivery_method = :smtp - TestMailer.return_path.deliver - assert_match %r{^Return-Path: <another@somewhere.test>}, MockSMTP.deliveries[0][0] - assert_equal "another@somewhere.test", MockSMTP.deliveries[0][1].to_s - end - - def test_starttls_is_enabled_if_supported - TestMailer.smtp_settings.merge!(:enable_starttls_auto => true) - MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(true) - MockSMTP.any_instance.expects(:enable_starttls_auto) - TestMailer.delivery_method = :smtp - TestMailer.signed_up(@recipient).deliver - end - - def test_starttls_is_disabled_if_not_supported - TestMailer.smtp_settings.merge!(:enable_starttls_auto => true) - MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(false) - MockSMTP.any_instance.expects(:enable_starttls_auto).never - TestMailer.delivery_method = :smtp - TestMailer.signed_up(@recipient).deliver - end - - def test_starttls_is_not_enabled - TestMailer.smtp_settings.merge!(:enable_starttls_auto => false) - MockSMTP.any_instance.expects(:respond_to?).never - TestMailer.delivery_method = :smtp - TestMailer.signed_up(@recipient).deliver - ensure - TestMailer.smtp_settings.merge!(:enable_starttls_auto => true) - end -end diff --git a/actionmailer/test/old_base/tmail_compat_test.rb b/actionmailer/test/old_base/tmail_compat_test.rb deleted file mode 100644 index 51558c2bfa..0000000000 --- a/actionmailer/test/old_base/tmail_compat_test.rb +++ /dev/null @@ -1,42 +0,0 @@ -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 - assert_deprecated do - assert_nothing_raised do - mail.set_content_type "text/plain" - end - end - assert_equal mail.mime_type, "text/plain" - end - - def test_transfer_encoding_raises_deprecation_warning - mail = Mail.new - assert_deprecated do - assert_nothing_raised do - mail.transfer_encoding "base64" - end - end - assert_equal mail.content_transfer_encoding, "base64" - end - - def test_transfer_encoding_setter_raises_deprecation_warning - mail = Mail.new - assert_deprecated do - assert_nothing_raised do - mail.transfer_encoding = "base64" - end - end - assert_equal mail.content_transfer_encoding, "base64" - end -end |