diff options
author | José Valim and Mikel Lindsaar <raasdnil@gmail.com> | 2010-01-21 00:10:22 +1100 |
---|---|---|
committer | José Valim and Mikel Lindsaar <raasdnil@gmail.com> | 2010-01-21 00:10:22 +1100 |
commit | d3da87ce771845f99bbdc04d6d6587b22655b063 (patch) | |
tree | 8ffef452097acb9336090a340b25aa2866a08f40 | |
parent | c34cfcc29f705c95c2218889cbec1898e008335d (diff) | |
download | rails-d3da87ce771845f99bbdc04d6d6587b22655b063.tar.gz rails-d3da87ce771845f99bbdc04d6d6587b22655b063.tar.bz2 rails-d3da87ce771845f99bbdc04d6d6587b22655b063.zip |
Mail method accepting all headers set via the hash
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 6 | ||||
-rw-r--r-- | actionmailer/test/base_test.rb | 32 |
2 files changed, 31 insertions, 7 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 8825bd35f9..39ddafe7fe 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/class' +require "active_support/core_ext/module/delegation" require 'mail' require 'action_mailer/tmail_compat' @@ -267,7 +268,6 @@ module ActionMailer #:nodoc: include ActionMailer::DeliveryMethods - private_class_method :new #:nodoc: @@raise_delivery_errors = true @@ -355,6 +355,9 @@ module ActionMailer #:nodoc: # Expose the internal Mail message attr_reader :message + # Pass calls to headers and attachment to the Mail#Message instance + delegate :headers, :attachments, :to => :@message + # Alias controller_path to mailer_name so render :partial in views work. alias :controller_path :mailer_name @@ -478,7 +481,6 @@ module ActionMailer #:nodoc: m.cc = quote_address_if_necessary(headers[:cc], m.charset) if headers[:cc] m.bcc = quote_address_if_necessary(headers[:bcc], m.charset) if headers[:bcc] m.reply_to = quote_address_if_necessary(headers[:reply_to], m.charset) if headers[:reply_to] - m.mime_version = headers[:mime_version] if headers[:mime_version] m.date = headers[:date] if headers[:date] m.body.set_sort_order(headers[:parts_order] || @@default_implicit_parts_order) diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index 83d51274f0..b8d2e46241 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -11,7 +11,7 @@ require 'abstract_unit' # end # # def goodbye(user) -# headers["Reply-To"] = 'cancelations@example.com' +# headers["X-SPAM"] = 'Not-SPAM' # mail(:subject => 'Goodbye', :to => user.email_address) do |format| # format.html { render "shared_template "} # format.text # goodbye.text.erb @@ -40,11 +40,14 @@ require 'abstract_unit' class BaseTest < Test::Unit::TestCase class TestMailer < ActionMailer::Base + def welcome(hash = {}) + headers['X-SPAM'] = "Not SPAM" hash = {:to => 'mikel@test.lindsaar.net', :from => 'jose@test.plataformatec.com', :subject => 'The first email on new API!'}.merge!(hash) mail(hash) end + end def test_the_method_call_to_mail_does_not_raise_error @@ -57,12 +60,31 @@ class BaseTest < Test::Unit::TestCase assert_equal(email.from, ['jose@test.plataformatec.com']) assert_equal(email.subject, 'The first email on new API!') end - - def test_calling_mail_should_pass_the_header_hash_to_the_new_mail_object - + + def test_should_allow_all_headers_set + @time = Time.now + email = TestMailer.deliver_welcome(:bcc => 'bcc@test.lindsaar.net', + :cc => 'cc@test.lindsaar.net', + :content_type => 'multipart/mixed', + :charset => 'iso-8559-1', + :mime_version => '2.0', + :reply_to => 'reply-to@test.lindsaar.net', + :date => @time) + assert_equal(email.bcc, ['bcc@test.lindsaar.net']) + assert_equal(email.cc, ['cc@test.lindsaar.net']) + assert_equal(email.content_type, 'multipart/mixed') + assert_equal(email.charset, 'iso-8559-1') + assert_equal(email.mime_version, '2.0') + assert_equal(email.reply_to, ['reply-to@test.lindsaar.net']) + assert_equal(email.date, @time) end - def test_it_should_guard_against_old_api_if_mail_method_called +# def test_should_allow_custom_headers_to_be_set +# email = TestMailer.deliver_welcome +# assert_equal("Not SPAM", email['X-SPAM']) +# end + + def test_should_use_class_defaults end |