From c6b16260fe3d1435848e78415bd0b40c10ad7424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim=20and=20Mikel=20Lindsaar?= Date: Sat, 23 Jan 2010 21:37:34 +1100 Subject: Added basic explicit multipart rendering and tests --- actionmailer/test/base_test.rb | 67 +++++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 11 deletions(-) (limited to 'actionmailer/test/base_test.rb') diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index df0eed695d..bae50868ae 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -69,6 +69,14 @@ class BaseTest < ActiveSupport::TestCase attachments['invoice.pdf'] = 'This is test File content' if hash.delete(:attachments) mail(DEFAULT_HEADERS.merge(hash)) end + + def explicit_multipart(hash = {}) + mail(DEFAULT_HEADERS.merge(hash)) do |format| + format.text { render :text => "TEXT Explicit Multipart" } + format.html { render :text => "HTML Explicit Multipart" } + end + end + end test "method call to mail does not raise error" do @@ -106,6 +114,11 @@ class BaseTest < ActiveSupport::TestCase assert_equal("Welcome", email.body.encoded) end + test "can pass in :body to the mail method hash" do + email = BaseMailer.deliver_welcome(:body => "Hello there") + assert_equal("Hello there", email.body.encoded) + end + # Custom headers test "custom headers" do email = BaseMailer.deliver_welcome @@ -221,17 +234,49 @@ class BaseTest < ActiveSupport::TestCase assert_equal("HTML Implicit Multipart", email.parts[1].parts[1].body.encoded) end - # TODO This should be fixed in mail. Sort parts should be recursive. - # test "implicit multipart with attachments and sort order" do - # order = ["text/html", "text/plain"] - # swap BaseMailer, :default_implicit_parts_order => order do - # email = BaseMailer.deliver_implicit_multipart(:attachments => true) - # assert_equal("application/pdf", email.parts[0].mime_type) - # assert_equal("multipart/alternate", email.parts[1].mime_type) - # assert_equal("text/plain", email.parts[1].parts[1].mime_type) - # assert_equal("text/html", email.parts[1].parts[0].mime_type) - # end - # end + test "implicit multipart with attachments and sort order" do + order = ["text/html", "text/plain"] + swap BaseMailer, :default_implicit_parts_order => order do + email = BaseMailer.deliver_implicit_multipart(:attachments => true) + assert_equal("application/pdf", email.parts[0].mime_type) + assert_equal("multipart/alternate", email.parts[1].mime_type) + assert_equal("text/plain", email.parts[1].parts[1].mime_type) + assert_equal("text/html", email.parts[1].parts[0].mime_type) + end + end + + test "explicit multipart tests" do + email = BaseMailer.deliver_explicit_multipart + assert_equal(2, email.parts.size) + assert_equal("multipart/alternate", email.mime_type) + assert_equal("text/plain", email.parts[0].mime_type) + assert_equal("TEXT Explicit Multipart", email.parts[0].body.encoded) + assert_equal("text/html", email.parts[1].mime_type) + assert_equal("HTML Explicit Multipart", email.parts[1].body.encoded) + end + + test "explicit multipart does not sort order" do + order = ["text/html", "text/plain"] + swap BaseMailer, :default_implicit_parts_order => order do + email = BaseMailer.deliver_explicit_multipart + assert_equal("text/plain", email.parts[0].mime_type) + assert_equal("text/html", email.parts[1].mime_type) + + email = BaseMailer.deliver_explicit_multipart(:parts_order => order.reverse) + assert_equal("text/plain", email.parts[0].mime_type) + assert_equal("text/html", email.parts[1].mime_type) + end + end + + #test "explicit multipart with attachments creates nested parts" do + # email = BaseMailer.deliver_explicit_multipart(:attachments => true) + # assert_equal("application/pdf", email.parts[0].mime_type) + # assert_equal("multipart/alternate", email.parts[1].mime_type) + # assert_equal("text/plain", email.parts[1].parts[0].mime_type) + # assert_equal("TEXT Implicit Multipart", email.parts[1].parts[0].body.encoded) + # assert_equal("text/html", email.parts[1].parts[1].mime_type) + # assert_equal("HTML Implicit Multipart", email.parts[1].parts[1].body.encoded) + #end protected -- cgit v1.2.3