From c985a0ee3d9ae279fd02814ca60782e2f93215e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim=20and=20Mikel=20Lindsaar?= Date: Sat, 23 Jan 2010 12:46:33 +0100 Subject: Add some tests to collector with templates and any. --- actionmailer/test/base_test.rb | 57 +++++++++++++++++----- .../explicit_multipart_templates.html.erb | 1 + .../explicit_multipart_templates.text.erb | 1 + 3 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 actionmailer/test/fixtures/base_mailer/explicit_multipart_templates.html.erb create mode 100644 actionmailer/test/fixtures/base_mailer/explicit_multipart_templates.text.erb (limited to 'actionmailer/test') diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index 3033b2db0f..83943162d2 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -77,7 +77,19 @@ class BaseTest < ActiveSupport::TestCase format.html { render :text => "HTML Explicit Multipart" } end end - + + def explicit_multipart_templates(hash = {}) + mail(DEFAULT_HEADERS.merge(hash)) do |format| + format.html + format.text + end + end + + def explicit_multipart_with_any(hash = {}) + mail(DEFAULT_HEADERS.merge(hash)) do |format| + format.any(:text, :html){ render :text => "Format with any!" } + end + end end test "method call to mail does not raise error" do @@ -214,7 +226,7 @@ class BaseTest < ActiveSupport::TestCase end # Implicit multipart - test "implicit multipart tests" do + test "implicit multipart" do email = BaseMailer.deliver_implicit_multipart assert_equal(2, email.parts.size) assert_equal("multipart/alternate", email.mime_type) @@ -224,7 +236,7 @@ class BaseTest < ActiveSupport::TestCase assert_equal("HTML Implicit Multipart", email.parts[1].body.encoded) end - test "implicit multipart tests with sort order" do + test "implicit multipart with sort order" do order = ["text/html", "text/plain"] swap BaseMailer, :default_implicit_parts_order => order do email = BaseMailer.deliver_implicit_multipart @@ -258,7 +270,8 @@ class BaseTest < ActiveSupport::TestCase end end - test "explicit multipart tests" do + # Explicit multipart + test "explicit multipart" do email = BaseMailer.deliver_explicit_multipart assert_equal(2, email.parts.size) assert_equal("multipart/alternate", email.mime_type) @@ -282,15 +295,37 @@ class BaseTest < ActiveSupport::TestCase 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 Explicit Multipart", email.parts[1].parts[0].body.encoded) - assert_equal("text/html", email.parts[1].parts[1].mime_type) - assert_equal("HTML Explicit Multipart", email.parts[1].parts[1].body.encoded) + 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 Explicit Multipart", email.parts[1].parts[0].body.encoded) + assert_equal("text/html", email.parts[1].parts[1].mime_type) + assert_equal("HTML Explicit Multipart", email.parts[1].parts[1].body.encoded) end + # TODO Seems Mail is sorting the templates automatically, and not on demand + # test "explicit multipart with templates" do + # email = BaseMailer.deliver_explicit_multipart_templates + # assert_equal(2, email.parts.size) + # assert_equal("multipart/alternate", email.mime_type) + # assert_equal("text/html", email.parts[0].mime_type) + # assert_equal("HTML Explicit Multipart Templates", email.parts[0].body.encoded) + # assert_equal("text/plain", email.parts[1].mime_type) + # assert_equal("TEXT Explicit Multipart Templates", email.parts[1].body.encoded) + # end + + test "explicit multipart with any" do + email = BaseMailer.deliver_explicit_multipart_with_any + assert_equal(2, email.parts.size) + assert_equal("multipart/alternate", email.mime_type) + assert_equal("text/plain", email.parts[0].mime_type) + assert_equal("Format with any!", email.parts[0].body.encoded) + assert_equal("text/html", email.parts[1].mime_type) + assert_equal("Format with any!", email.parts[1].body.encoded) + end + + protected # Execute the block setting the given values and restoring old values after diff --git a/actionmailer/test/fixtures/base_mailer/explicit_multipart_templates.html.erb b/actionmailer/test/fixtures/base_mailer/explicit_multipart_templates.html.erb new file mode 100644 index 0000000000..c0a61b6249 --- /dev/null +++ b/actionmailer/test/fixtures/base_mailer/explicit_multipart_templates.html.erb @@ -0,0 +1 @@ +HTML Explicit Multipart Templates \ No newline at end of file diff --git a/actionmailer/test/fixtures/base_mailer/explicit_multipart_templates.text.erb b/actionmailer/test/fixtures/base_mailer/explicit_multipart_templates.text.erb new file mode 100644 index 0000000000..507230b1de --- /dev/null +++ b/actionmailer/test/fixtures/base_mailer/explicit_multipart_templates.text.erb @@ -0,0 +1 @@ +TEXT Explicit Multipart Templates \ No newline at end of file -- cgit v1.2.3