aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test
diff options
context:
space:
mode:
authorJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-23 21:37:34 +1100
committerJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-23 21:37:34 +1100
commitc6b16260fe3d1435848e78415bd0b40c10ad7424 (patch)
tree28000447fed5bdaf954b796fcb4c08f66af816aa /actionmailer/test
parent502028a32bfa46ad18337d2a69f03e8b5dec3c4a (diff)
downloadrails-c6b16260fe3d1435848e78415bd0b40c10ad7424.tar.gz
rails-c6b16260fe3d1435848e78415bd0b40c10ad7424.tar.bz2
rails-c6b16260fe3d1435848e78415bd0b40c10ad7424.zip
Added basic explicit multipart rendering and tests
Diffstat (limited to 'actionmailer/test')
-rw-r--r--actionmailer/test/base_test.rb67
1 files changed, 56 insertions, 11 deletions
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