Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 9184

Show
Ignore:
Timestamp:
04/01/08 05:32:11 (3 months ago)
Author:
bitsweat
Message:

force_encoding to ascii-8bit instead of nil

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionmailer/test/quoting_test.rb

    r8666 r9184  
    55 
    66class QuotingTest < Test::Unit::TestCase 
    7    
    87  # Move some tests from TMAIL here 
    98  def test_unquote_quoted_printable 
    10     a ="=?ISO-8859-1?Q?[166417]_Bekr=E6ftelse_fra_Rejsefeber?="  
     9    a ="=?ISO-8859-1?Q?[166417]_Bekr=E6ftelse_fra_Rejsefeber?=" 
    1110    b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8') 
    1211    assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b 
     
    2019 
    2120  def test_unquote_without_charset 
    22     a ="[166417]_Bekr=E6ftelse_fra_Rejsefeber"  
     21    a ="[166417]_Bekr=E6ftelse_fra_Rejsefeber" 
    2322    b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8') 
    2423    assert_equal "[166417]_Bekr=E6ftelse_fra_Rejsefeber", b 
    25   end   
    26    
     24  end 
     25 
    2726  def test_unqoute_multiple 
    28     a ="=?utf-8?q?Re=3A_=5B12=5D_=23137=3A_Inkonsistente_verwendung_von_=22Hin?==?utf-8?b?enVmw7xnZW4i?="  
     27    a ="=?utf-8?q?Re=3A_=5B12=5D_=23137=3A_Inkonsistente_verwendung_von_=22Hin?==?utf-8?b?enVmw7xnZW4i?=" 
    2928    b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8') 
    3029    assert_equal "Re: [12] #137: Inkonsistente verwendung von \"Hinzuf\303\274gen\"", b 
    3130  end 
    32    
     31 
    3332  def test_unqoute_in_the_middle 
    34     a ="Re: Photos =?ISO-8859-1?Q?Brosch=FCre_Rand?="  
     33    a ="Re: Photos =?ISO-8859-1?Q?Brosch=FCre_Rand?=" 
    3534    b = TMail::Unquoter.unquote_and_convert_to(a, 'utf-8') 
    3635    assert_equal "Re: Photos Brosch\303\274re Rand", b 
    3736  end 
    38    
     37 
    3938  def test_unqoute_iso 
    40     a ="=?ISO-8859-1?Q?Brosch=FCre_Rand?="  
     39    a ="=?ISO-8859-1?Q?Brosch=FCre_Rand?=" 
    4140    b = TMail::Unquoter.unquote_and_convert_to(a, 'iso-8859-1') 
    4241    expected = "Brosch\374re Rand" 
     
    4443    assert_equal expected, b 
    4544  end 
    46      
     45 
    4746  def test_quote_multibyte_chars 
    4847    original = "\303\246 \303\270 and \303\245" 
    49     original.force_encoding nil if original.respond_to?(:force_encoding) 
     48    original.force_encoding('ASCII-8BIT') if original.respond_to?(:force_encoding) 
    5049 
    5150    result = execute_in_sandbox(<<-CODE) 
     
    6160    assert_equal unquoted, original 
    6261  end 
    63    
    64    
     62 
     63 
    6564  # test an email that has been created using \r\n newlines, instead of 
    6665  # \n newlines. 
     
    7473    assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject 
    7574  end 
    76    
     75 
    7776  def test_decode 
    7877    encoded, decoded = expected_base64_strings 
    7978    assert_equal decoded, TMail::Base64.decode(encoded) 
    8079  end 
    81    
     80 
    8281  def test_encode 
    8382    encoded, decoded = expected_base64_strings 
    8483    assert_equal encoded.length, TMail::Base64.encode(decoded).length 
    8584  end 
    86    
     85 
    8786  private 
    88      
     87 
    8988    # This whole thing *could* be much simpler, but I don't think Tempfile, 
    9089    # popen and others exist on all platforms (like Windows). 
     
    108107      File.delete(res_name) rescue nil 
    109108    end 
    110      
     109 
    111110    def expected_base64_strings 
    112111      [ File.read("#{File.dirname(__FILE__)}/fixtures/raw_base64_encoded_string"), File.read("#{File.dirname(__FILE__)}/fixtures/raw_base64_decoded_string") ] 
    113112    end 
    114113end 
    115