diff options
author | Jamis Buck <jamis@37signals.com> | 2005-05-29 16:36:22 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2005-05-29 16:36:22 +0000 |
commit | 359caef33ca71b37b3ea2feef0960beccfabf4de (patch) | |
tree | fd5598e50baa90e6e84bf0747866d04c8aecb677 /actionmailer/test | |
parent | 79d9794f090f02ff56c461893785fbd65877109e (diff) | |
download | rails-359caef33ca71b37b3ea2feef0960beccfabf4de.tar.gz rails-359caef33ca71b37b3ea2feef0960beccfabf4de.tar.bz2 rails-359caef33ca71b37b3ea2feef0960beccfabf4de.zip |
A very thorough refactoring, resulting in new mail property setters and support for attachments and multipart messages.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1359 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer/test')
3 files changed, 83 insertions, 25 deletions
diff --git a/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.html.rhtml b/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.html.rhtml new file mode 100644 index 0000000000..946d99ede5 --- /dev/null +++ b/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.html.rhtml @@ -0,0 +1,10 @@ +<html> + <body> + HTML formatted message to <strong><%= @recipient %></strong>. + </body> +</html> +<html> + <body> + HTML formatted message to <strong><%= @recipient %></strong>. + </body> +</html> diff --git a/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.plain.rhtml b/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.plain.rhtml new file mode 100644 index 0000000000..a6c8d54cf9 --- /dev/null +++ b/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.plain.rhtml @@ -0,0 +1,2 @@ +Plain text to <%= @recipient %>. +Plain text to <%= @recipient %>. diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 733ec61e41..861206fc54 100755 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -14,21 +14,21 @@ class TestMailer < ActionMailer::Base 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}" + self.recipients = recipient + self.subject = "[Cancelled] Goodbye #{recipient}" + self.from = "system@loudthinking.com" + self.sent_on = Time.local(2004, 12, 12) + self.body = "Goodbye, Mr. #{recipient}" 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." + 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 iso_charset(recipient) @@ -74,6 +74,30 @@ class TestMailer < ActionMailer::Base @charset = "utf-8" end + def explicitly_multipart_example(recipient) + @recipients = recipient + @subject = "multipart example" + @from = "test@example.com" + @sent_on = Time.local 2004, 12, 12 + @body = "plain text default" + + part "text/html" do |p| + p.charset = "iso-8859-1" + p.body = "blah" + end + + attachment :content_type => "image/jpeg", :filename => "foo.jpg", + :body => "123456789" + end + + def implicitly_multipart_example(recipient) + @recipients = recipient + @subject = "multipart example" + @from = "test@example.com" + @sent_on = Time.local 2004, 12, 12 + @body = { "recipient" => recipient } + end + class <<self attr_accessor :received_body end @@ -86,9 +110,10 @@ end TestMailer.template_root = File.dirname(__FILE__) + "/fixtures" class ActionMailerTest < Test::Unit::TestCase + include ActionMailer::Quoting def encode( text, charset="utf-8" ) - ActionMailer::Base.quoted_printable( text, charset ) + quoted_printable( text, charset ) end def new_mail( charset="utf-8" ) @@ -312,12 +337,12 @@ EOF @recipient = "Grytøyr <test@localhost>" expected = new_mail "iso-8859-1" - expected.to = TestMailer.quote_address_if_necessary @recipient, "iso-8859-1" + expected.to = quote_address_if_necessary @recipient, "iso-8859-1" expected.subject = "testing extended headers" expected.body = "Nothing to see here." - expected.from = TestMailer.quote_address_if_necessary "Grytøyr <stian1@example.net>", "iso-8859-1" - expected.cc = TestMailer.quote_address_if_necessary "Grytøyr <stian2@example.net>", "iso-8859-1" - expected.bcc = TestMailer.quote_address_if_necessary "Grytøyr <stian3@example.net>", "iso-8859-1" + expected.from = quote_address_if_necessary "Grytøyr <stian1@example.net>", "iso-8859-1" + expected.cc = quote_address_if_necessary "Grytøyr <stian2@example.net>", "iso-8859-1" + expected.bcc = quote_address_if_necessary "Grytøyr <stian3@example.net>", "iso-8859-1" expected.date = Time.local 2004, 12, 12 created = nil @@ -339,12 +364,12 @@ EOF def test_utf8_body_is_not_quoted @recipient = "Foo áëô îü <extended@example.net>" expected = new_mail "utf-8" - expected.to = TestMailer.quote_address_if_necessary @recipient, "utf-8" + expected.to = quote_address_if_necessary @recipient, "utf-8" expected.subject = "testing utf-8 body" expected.body = "åœö blah" - expected.from = TestMailer.quote_address_if_necessary @recipient, "utf-8" - expected.cc = TestMailer.quote_address_if_necessary @recipient, "utf-8" - expected.bcc = TestMailer.quote_address_if_necessary @recipient, "utf-8" + expected.from = quote_address_if_necessary @recipient, "utf-8" + expected.cc = quote_address_if_necessary @recipient, "utf-8" + expected.bcc = quote_address_if_necessary @recipient, "utf-8" expected.date = Time.local 2004, 12, 12 created = TestMailer.create_utf8_body @recipient @@ -354,12 +379,12 @@ EOF def test_multiple_utf8_recipients @recipient = ["\"Foo áëô îü\" <extended@example.net>", "\"Example Recipient\" <me@example.com>"] expected = new_mail "utf-8" - expected.to = TestMailer.quote_address_if_necessary @recipient, "utf-8" + expected.to = quote_address_if_necessary @recipient, "utf-8" expected.subject = "testing utf-8 body" expected.body = "åœö blah" - expected.from = TestMailer.quote_address_if_necessary @recipient.first, "utf-8" - expected.cc = TestMailer.quote_address_if_necessary @recipient, "utf-8" - expected.bcc = TestMailer.quote_address_if_necessary @recipient, "utf-8" + expected.from = quote_address_if_necessary @recipient.first, "utf-8" + expected.cc = quote_address_if_necessary @recipient, "utf-8" + expected.bcc = quote_address_if_necessary @recipient, "utf-8" expected.date = Time.local 2004, 12, 12 created = TestMailer.create_utf8_body @recipient @@ -400,5 +425,26 @@ EOF assert_nothing_raised { mail.body } end + def test_explicitly_multipart_messages + mail = TestMailer.create_explicitly_multipart_example(@recipient) + assert_equal 3, mail.parts.length + assert_equal "text/plain", mail.parts[0].content_type + + assert_equal "text/html", mail.parts[1].content_type + assert_equal "inline", mail.parts[1].content_disposition + + assert_equal "image/jpeg", mail.parts[2].content_type + assert_equal "attachment", mail.parts[2].content_disposition + assert_equal "foo.jpg", mail.parts[2].sub_header("content-disposition", "filename") + assert_equal "foo.jpg", mail.parts[2].sub_header("content-type", "name") + end + + def test_implicitly_multipart_messages + mail = TestMailer.create_implicitly_multipart_example(@recipient) + assert_equal 2, mail.parts.length + assert_equal "text/html", mail.parts[0].content_type + assert_equal "text/plain", mail.parts[1].content_type + end + end |