aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-04-11 19:20:39 -0700
committerwycats <wycats@gmail.com>2010-04-11 19:20:39 -0700
commit59c6082d9867572352e2ac2070d5aa9590132ef8 (patch)
treee9211dd3d0699452e623309a612a3be5efba0f0e /actionmailer/test
parentecf039fc05ac32b7a8cbd005dd4723d7eadc61c0 (diff)
parentdd02090d762bfbb8fdada60142e35247797f32c7 (diff)
downloadrails-59c6082d9867572352e2ac2070d5aa9590132ef8.tar.gz
rails-59c6082d9867572352e2ac2070d5aa9590132ef8.tar.bz2
rails-59c6082d9867572352e2ac2070d5aa9590132ef8.zip
Merge remote branch 'mikel/master'
Diffstat (limited to 'actionmailer/test')
-rw-r--r--actionmailer/test/old_base/mail_service_test.rb85
-rw-r--r--actionmailer/test/old_base/url_test.rb5
-rw-r--r--actionmailer/test/quoting_test.rb106
-rw-r--r--actionmailer/test/test_helper_test.rb6
4 files changed, 49 insertions, 153 deletions
diff --git a/actionmailer/test/old_base/mail_service_test.rb b/actionmailer/test/old_base/mail_service_test.rb
index 9eb067554f..db2db59cc7 100644
--- a/actionmailer/test/old_base/mail_service_test.rb
+++ b/actionmailer/test/old_base/mail_service_test.rb
@@ -105,7 +105,7 @@ class TestMailer < ActionMailer::Base
sent_on Time.local(2004, 12, 12)
cc "Foo áëô îü <extended@example.net>"
bcc "Foo áëô îü <extended@example.net>"
- charset "utf-8"
+ charset "UTF-8"
body "åœö blah"
end
@@ -131,7 +131,7 @@ class TestMailer < ActionMailer::Base
recipients recipient
subject "Foo áëô îü"
from "test@example.com"
- charset "utf-8"
+ charset "UTF-8"
part "text/plain" do |p|
p.body = "blah"
@@ -316,18 +316,15 @@ class TestMailer < ActionMailer::Base
end
class ActionMailerTest < Test::Unit::TestCase
- include ActionMailer::Quoting
- def encode( text, charset="utf-8" )
- quoted_printable( text, charset )
+ def encode( text, charset="UTF-8" )
+ Mail::Encodings.q_value_encode( text, charset )
end
- def new_mail( charset="utf-8" )
+ def new_mail( charset="UTF-8" )
mail = Mail.new
+ mail.charset = charset
mail.mime_version = "1.0"
- if charset
- mail.content_type ["text", "plain", { "charset" => charset }]
- end
mail
end
@@ -358,7 +355,7 @@ class ActionMailerTest < Test::Unit::TestCase
assert_equal "multipart/mixed", created.mime_type
assert_equal "multipart/alternative", created.parts[0].mime_type
assert_equal "bar", created.parts[0].header['foo'].to_s
- assert_nil created.parts[0].charset
+ assert_not_nil created.parts[0].charset
assert_equal "text/plain", created.parts[0].parts[0].mime_type
assert_equal "text/html", created.parts[0].parts[1].mime_type
assert_equal "application/octet-stream", created.parts[1].mime_type
@@ -570,7 +567,6 @@ class ActionMailerTest < Test::Unit::TestCase
def test_iso_charset
TestMailer.delivery_method = :test
-
expected = new_mail( "iso-8859-1" )
expected.to = @recipient
expected.subject = encode "testing isø charsets", "iso-8859-1"
@@ -671,14 +667,14 @@ class ActionMailerTest < Test::Unit::TestCase
def test_unquote_quoted_printable_subject
msg = <<EOF
From: me@example.com
-Subject: =?utf-8?Q?testing_testing_=D6=A4?=
+Subject: =?UTF-8?Q?testing_testing_=D6=A4?=
Content-Type: text/plain; charset=iso-8859-1
The body
EOF
mail = Mail.new(msg)
assert_equal "testing testing \326\244", mail.subject
- assert_equal "Subject: =?utf-8?Q?testing_testing_=D6=A4?=\r\n", mail[:subject].encoded
+ assert_equal "Subject: testing testing =?UTF-8?Q?_=D6=A4=?=\r\n", mail[:subject].encoded
end
def test_unquote_7bit_subject
@@ -719,7 +715,7 @@ The=3Dbody
EOF
mail = Mail.new(msg)
assert_equal "The=body", mail.body.to_s.strip
- assert_equal "The=3Dbody", mail.body.encoded.strip
+ assert_equal "The=3Dbody=", mail.body.encoded.strip
end
def test_unquote_base64_body
@@ -740,12 +736,12 @@ EOF
@recipient = "Grytøyr <test@localhost>"
expected = new_mail "iso-8859-1"
- expected.to = quote_address_if_necessary @recipient, "iso-8859-1"
+ expected.to = @recipient
expected.subject = "testing extended headers"
expected.body = "Nothing to see here."
- 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.from = "Grytøyr <stian1@example.net>"
+ expected.cc = "Grytøyr <stian2@example.net>"
+ expected.bcc = "Grytøyr <stian3@example.net>"
expected.date = Time.local 2004, 12, 12
created = nil
@@ -774,13 +770,13 @@ EOF
def test_utf8_body_is_not_quoted
@recipient = "Foo áëô îü <extended@example.net>"
- expected = new_mail "utf-8"
- expected.to = quote_address_if_necessary @recipient, "utf-8"
- expected.subject = "testing utf-8 body"
+ expected = new_mail "UTF-8"
+ expected.to = @recipient
+ expected.subject = "testing UTF-8 body"
expected.body = "åœö blah"
- 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.from = @recipient
+ expected.cc = @recipient
+ expected.bcc = @recipient
expected.date = Time.local 2004, 12, 12
created = TestMailer.utf8_body @recipient
@@ -789,18 +785,21 @@ EOF
def test_multiple_utf8_recipients
@recipient = ["\"Foo áëô îü\" <extended@example.net>", "\"Example Recipient\" <me@example.com>"]
- expected = new_mail "utf-8"
- expected.to = quote_address_if_necessary @recipient, "utf-8"
- expected.subject = "testing utf-8 body"
+ expected = new_mail "UTF-8"
+ expected.to = @recipient
+ expected.subject = "testing UTF-8 body"
expected.body = "åœö blah"
- 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.from = @recipient.first
+ expected.cc = @recipient
+ expected.bcc = @recipient
expected.date = Time.local 2004, 12, 12
created = TestMailer.utf8_body @recipient
- assert_match(/\nFrom: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>\r/, created.encoded)
- assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>, \r\n\tExample Recipient <me/, created.encoded)
+ from_regexp = Regexp.escape('From: Foo =?UTF-8?B?w6HDq8O0?= =?UTF-8?B?IMOuw7w=?=')
+ assert_match(/#{from_regexp}/m, created.encoded)
+
+ to_regexp = Regexp.escape("To: =?UTF-8?B?Rm9vIMOhw6vDtCDDrsO8?= <extended@example.net>")
+ assert_match(/#{to_regexp}/m, created.encoded)
end
def test_receive_decodes_base64_encoded_mail
@@ -864,12 +863,20 @@ EOF
def test_multipart_with_utf8_subject
mail = TestMailer.multipart_with_utf8_subject(@recipient)
- assert_match(/\nSubject: =\?utf-8\?Q\?Foo_.*?\?=/, mail.encoded)
+ regex = Regexp.escape('Subject: Foo =?UTF-8?Q?=C3=A1=C3=AB=C3=B4=?= =?UTF-8?Q?_=C3=AE=C3=BC=?=')
+ assert_match(/#{regex}/, mail.encoded)
+ string = "Foo áëô îü"
+ string.force_encoding('UTF-8') if string.respond_to?(:force_encoding)
+ assert_match(string, mail.subject)
end
def test_implicitly_multipart_with_utf8
mail = TestMailer.implicitly_multipart_with_utf8
- assert_match(/\nSubject: =\?utf-8\?Q\?Foo_.*?\?=/, mail.encoded)
+ regex = Regexp.escape('Subject: Foo =?UTF-8?Q?=C3=A1=C3=AB=C3=B4=?= =?UTF-8?Q?_=C3=AE=C3=BC=?=')
+ assert_match(/#{regex}/, mail.encoded)
+ string = "Foo áëô îü"
+ string.force_encoding('UTF-8') if string.respond_to?(:force_encoding)
+ assert_match(string, mail.subject)
end
def test_explicitly_multipart_messages
@@ -909,11 +916,11 @@ EOF
assert_equal "1.0", mail.mime_version.to_s
assert_equal "multipart/alternative", mail.mime_type
assert_equal "text/plain", mail.parts[0].mime_type
- assert_equal "utf-8", mail.parts[0].charset
+ assert_equal "UTF-8", mail.parts[0].charset
assert_equal "text/html", mail.parts[1].mime_type
- assert_equal "utf-8", mail.parts[1].charset
+ assert_equal "UTF-8", mail.parts[1].charset
assert_equal "application/x-yaml", mail.parts[2].mime_type
- assert_equal "utf-8", mail.parts[2].charset
+ assert_equal "UTF-8", mail.parts[2].charset
end
def test_implicitly_multipart_messages_with_custom_order
@@ -1044,13 +1051,13 @@ EOF
mail = FunkyPathMailer.multipart_with_template_path_with_dots(@recipient)
assert_equal 2, mail.parts.length
assert "text/plain", mail.parts[1].mime_type
- assert "utf-8", mail.parts[1].charset
+ assert "UTF-8", mail.parts[1].charset
end
def test_custom_content_type_attributes
mail = TestMailer.custom_content_type_attributes
assert_match %r{format=flowed}, mail.content_type
- assert_match %r{charset=utf-8}, mail.content_type
+ assert_match %r{charset=UTF-8}, mail.content_type
end
def test_return_path_with_create
diff --git a/actionmailer/test/old_base/url_test.rb b/actionmailer/test/old_base/url_test.rb
index 17b383cc2a..6895fb230e 100644
--- a/actionmailer/test/old_base/url_test.rb
+++ b/actionmailer/test/old_base/url_test.rb
@@ -29,13 +29,12 @@ class UrlTestMailer < ActionMailer::Base
end
class ActionMailerUrlTest < Test::Unit::TestCase
- include ActionMailer::Quoting
- def encode( text, charset="utf-8" )
+ def encode( text, charset="UTF-8" )
quoted_printable( text, charset )
end
- def new_mail( charset="utf-8" )
+ def new_mail( charset="UTF-8" )
mail = Mail.new
mail.mime_version = "1.0"
if charset
diff --git a/actionmailer/test/quoting_test.rb b/actionmailer/test/quoting_test.rb
deleted file mode 100644
index 7640f4b086..0000000000
--- a/actionmailer/test/quoting_test.rb
+++ /dev/null
@@ -1,106 +0,0 @@
-# encoding: utf-8
-require 'abstract_unit'
-require 'tempfile'
-
-class QuotingTest < Test::Unit::TestCase
- # Move some tests from TMAIL here
- def test_unquote_quoted_printable
- a ="=?ISO-8859-1?Q?[166417]_Bekr=E6ftelse_fra_Rejsefeber?="
- b = Mail::Encodings.unquote_and_convert_to(a, 'utf-8')
- assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b
- end
-
- def test_unquote_base64
- a ="=?ISO-8859-1?B?WzE2NjQxN10gQmVrcuZmdGVsc2UgZnJhIFJlanNlZmViZXI=?="
- b = Mail::Encodings.unquote_and_convert_to(a, 'utf-8')
- assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b
- end
-
- def test_unquote_without_charset
- a ="[166417]_Bekr=E6ftelse_fra_Rejsefeber"
- b = Mail::Encodings.unquote_and_convert_to(a, 'utf-8')
- assert_equal "[166417]_Bekr=E6ftelse_fra_Rejsefeber", b
- end
-
- def test_unqoute_multiple
- a ="=?utf-8?q?Re=3A_=5B12=5D_=23137=3A_Inkonsistente_verwendung_von_=22Hin?==?utf-8?b?enVmw7xnZW4i?="
- b = Mail::Encodings.unquote_and_convert_to(a, 'utf-8')
- assert_equal "Re: [12] #137: Inkonsistente verwendung von \"Hinzuf\303\274gen\"", b
- end
-
- def test_unqoute_in_the_middle
- a ="Re: Photos =?ISO-8859-1?Q?Brosch=FCre_Rand?="
- b = Mail::Encodings.unquote_and_convert_to(a, 'utf-8')
- assert_equal "Re: Photos Brosch\303\274re Rand", b
- end
-
- def test_unqoute_iso
- a ="=?ISO-8859-1?Q?Brosch=FCre_Rand?="
- b = Mail::Encodings.unquote_and_convert_to(a, 'iso-8859-1')
- expected = "Brosch\374re Rand"
- expected.force_encoding 'iso-8859-1' if expected.respond_to?(:force_encoding)
- assert_equal expected, b
- end
-
- def test_quote_multibyte_chars
- original = "\303\246 \303\270 and \303\245"
- original.force_encoding('ASCII-8BIT') if original.respond_to?(:force_encoding)
-
- result = execute_in_sandbox(<<-CODE)
- $:.unshift(File.dirname(__FILE__) + "/../lib/")
- if RUBY_VERSION < '1.9'
- $KCODE = 'u'
- end
- require 'action_mailer/quoting'
- include ActionMailer::Quoting
- quoted_printable(#{original.inspect}, "UTF-8")
- CODE
-
- unquoted = Mail::Encodings.unquote_and_convert_to(result, nil)
-
- unquoted.force_encoding(Encoding::ASCII_8BIT) if unquoted.respond_to?(:force_encoding)
- original.force_encoding(Encoding::ASCII_8BIT) if original.respond_to?(:force_encoding)
-
- assert_equal unquoted, original
- end
-
-
- # test an email that has been created using \r\n newlines, instead of
- # \n newlines.
- def test_email_quoted_with_0d0a
- mail = Mail.new(IO.read("#{File.dirname(__FILE__)}/fixtures/raw_email_quoted_with_0d0a"))
- # CHANGED: subject returns an object now
- # assert_match %r{Elapsed time}, mail.body
- assert_match %r{Elapsed time}, mail.body.to_s
- end
-
- def test_email_with_partially_quoted_subject
- mail = Mail.new(IO.read("#{File.dirname(__FILE__)}/fixtures/raw_email_with_partially_quoted_subject"))
- # CHANGED: subject returns an object now
- # assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject
- assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject
- end
-
- private
- # This whole thing *could* be much simpler, but I don't think Tempfile,
- # popen and others exist on all platforms (like Windows).
- def execute_in_sandbox(code)
- test_name = "#{File.dirname(__FILE__)}/am-quoting-test.#{$$}.rb"
- res_name = "#{File.dirname(__FILE__)}/am-quoting-test.#{$$}.out"
-
- File.open(test_name, "w+") do |file|
- file.write(<<-CODE)
- block = Proc.new do
- #{code}
- end
- puts block.call
- CODE
- end
-
- system("ruby #{test_name} > #{res_name}") or raise "could not run test in sandbox"
- File.read(res_name).chomp
- ensure
- File.delete(test_name) rescue nil
- File.delete(res_name) rescue nil
- end
-end
diff --git a/actionmailer/test/test_helper_test.rb b/actionmailer/test/test_helper_test.rb
index 3a38a91c28..440fb868c8 100644
--- a/actionmailer/test/test_helper_test.rb
+++ b/actionmailer/test/test_helper_test.rb
@@ -34,11 +34,7 @@ class TestHelperMailerTest < ActionMailer::TestCase
end
def test_charset_is_utf_8
- assert_equal "utf-8", charset
- end
-
- def test_encode
- assert_equal "=?utf-8?Q?=0Aasdf=0A?=", encode("\nasdf\n")
+ assert_equal "UTF-8", charset
end
def test_assert_emails