aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-09-01 14:26:13 +0000
committerJamis Buck <jamis@37signals.com>2005-09-01 14:26:13 +0000
commitca410998abb8ed14bdc5edf0734eb8f83bf12317 (patch)
tree1cb45d607e4cdfa5f5ee2fa7d1050dea795f7143 /actionmailer/test
parent2fed808ee4d572da5d86cb91c704e569589bd7cc (diff)
downloadrails-ca410998abb8ed14bdc5edf0734eb8f83bf12317.tar.gz
rails-ca410998abb8ed14bdc5edf0734eb8f83bf12317.tar.bz2
rails-ca410998abb8ed14bdc5edf0734eb8f83bf12317.zip
Encode multibyte characters correctly #1894
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2088 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer/test')
-rw-r--r--actionmailer/test/quoting_test.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/actionmailer/test/quoting_test.rb b/actionmailer/test/quoting_test.rb
new file mode 100644
index 0000000000..6291cd3db6
--- /dev/null
+++ b/actionmailer/test/quoting_test.rb
@@ -0,0 +1,48 @@
+$:.unshift(File.dirname(__FILE__) + "/../lib/")
+$:.unshift(File.dirname(__FILE__) + "/../lib/action_mailer/vendor")
+
+require 'test/unit'
+require 'tmail'
+require 'tempfile'
+
+class QuotingTest < Test::Unit::TestCase
+ def test_quote_multibyte_chars
+ original = "\303\246 \303\270 and \303\245"
+
+ result = execute_in_sandbox(<<-CODE)
+ $:.unshift(File.dirname(__FILE__) + "/../lib/")
+ $KCODE = 'u'
+ require 'jcode'
+ require 'action_mailer/quoting'
+ include ActionMailer::Quoting
+ quoted_printable(#{original.inspect}, "UTF-8")
+ CODE
+
+ unquoted = TMail::Unquoter.unquote_and_convert_to(result, nil)
+ assert_equal unquoted, original
+ 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)
+ ensure
+ File.delete(test_name) rescue nil
+ File.delete(res_name) rescue nil
+ end
+end