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

Changeset 9218

Show
Ignore:
Timestamp:
04/03/08 17:28:05 (8 months ago)
Author:
bitsweat
Message:

Ruby 1.9 compat: compare with same encoding

Files:

Legend:

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

    r9165 r9218  
    841841    mail = TMail::Mail.parse(fixture) 
    842842    attachment = mail.attachments.last 
    843     assert_equal "01 Quien Te Dij\212at. Pitbull.mp3", attachment.original_filename 
     843 
     844    expected = "01 Quien Te Dij\212at. Pitbull.mp3" 
     845    expected.force_encoding(Encoding::ASCII_8BIT) if expected.respond_to?(:force_encoding) 
     846 
     847    assert_equal expected, attachment.original_filename 
    844848  end 
    845849 
  • trunk/actionmailer/test/quoting_test.rb

    r9184 r9218  
    7474  end 
    7575 
    76   def test_decode 
    77     encoded, decoded = expected_base64_strings 
     76  def test_base64_encoding 
     77    encoded = read_fixture('raw_base64_encoded_string') 
     78    decoded = read_fixture('raw_base64_decoded_string') 
     79 
     80    assert_equal encoded, TMail::Base64.encode(decoded) 
    7881    assert_equal decoded, TMail::Base64.decode(encoded) 
    7982  end 
    8083 
    81   def test_encode 
    82     encoded, decoded = expected_base64_strings 
    83     assert_equal encoded.length, TMail::Base64.encode(decoded).length 
    84   end 
    85  
    8684  private 
    87  
    8885    # This whole thing *could* be much simpler, but I don't think Tempfile, 
    8986    # popen and others exist on all platforms (like Windows). 
     
    108105    end 
    109106 
    110     def expected_base64_strings 
    111       [ File.read("#{File.dirname(__FILE__)}/fixtures/raw_base64_encoded_string"), File.read("#{File.dirname(__FILE__)}/fixtures/raw_base64_decoded_string") ] 
     107    if RUBY_VERSION >= '1.9' 
     108      def read_fixture(name) 
     109        File.open("#{File.dirname(__FILE__)}/fixtures/raw_base64_encoded_string", 'r:ascii-8bit') { |f| f.read } 
     110      end 
     111    else 
     112      def read_fixture(name) 
     113        File.read("#{File.dirname(__FILE__)}/fixtures/raw_base64_encoded_string") 
     114      end 
    112115    end 
    113116end