diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-04-13 15:35:53 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-04-14 13:37:39 -0700 |
commit | a0d4c8d1bf2198608e2e319ff833560f88d20855 (patch) | |
tree | 89c102800b139109bd3385ed0fed2d2d84e00c82 /activerecord/test | |
parent | 27f8c57f5f88304212a00cb8e32f8227755a7265 (diff) | |
download | rails-a0d4c8d1bf2198608e2e319ff833560f88d20855.tar.gz rails-a0d4c8d1bf2198608e2e319ff833560f88d20855.tar.bz2 rails-a0d4c8d1bf2198608e2e319ff833560f88d20855.zip |
using the database adapter to typecast before executing prepared statement
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/binary_test.rb | 19 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/test/cases/binary_test.rb b/activerecord/test/cases/binary_test.rb index 8545ba97cc..06c14cb108 100644 --- a/activerecord/test/cases/binary_test.rb +++ b/activerecord/test/cases/binary_test.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 require "cases/helper" # Without using prepared statements, it makes no sense to test @@ -9,6 +10,24 @@ unless current_adapter?(:SybaseAdapter, :DB2Adapter, :FirebirdAdapter) class BinaryTest < ActiveRecord::TestCase FIXTURES = %w(flowers.jpg example.log) + def test_mixed_encoding + str = "\x80" + str.force_encoding('ASCII-8BIT') if str.respond_to?(:force_encoding) + + binary = Binary.new :name => 'いただきます!', :data => str + binary.save! + binary.reload + assert_equal str, binary.data + + name = binary.name + + # Mysql adapter doesn't properly encode things, so we have to do it + if current_adapter?(:MysqlAdapter) + name.force_encoding('UTF-8') if name.respond_to?(:force_encoding) + end + assert_equal 'いただきます!', name + end + def test_load_save Binary.delete_all diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 362475de36..ceadb05644 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -67,6 +67,7 @@ ActiveRecord::Schema.define do end create_table :binaries, :force => true do |t| + t.string :name t.binary :data end |