git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8185 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
ec93d61fb9
commit
dd27c4e5fb
|
@ -75,7 +75,7 @@ module ActiveRecord
|
||||||
if PGconn.respond_to?(:unescape_bytea)
|
if PGconn.respond_to?(:unescape_bytea)
|
||||||
self.class.module_eval do
|
self.class.module_eval do
|
||||||
define_method(:binary_to_string) do |value|
|
define_method(:binary_to_string) do |value|
|
||||||
if value =~ /\\\\\d{3}/
|
if value =~ /\\\d{3}/
|
||||||
PGconn.unescape_bytea(value)
|
PGconn.unescape_bytea(value)
|
||||||
else
|
else
|
||||||
value
|
value
|
||||||
|
@ -85,7 +85,7 @@ module ActiveRecord
|
||||||
else
|
else
|
||||||
self.class.module_eval do
|
self.class.module_eval do
|
||||||
define_method(:binary_to_string) do |value|
|
define_method(:binary_to_string) do |value|
|
||||||
if value =~ /\\\\\d{3}/
|
if value =~ /\\\d{3}/
|
||||||
result = ''
|
result = ''
|
||||||
i, max = 0, value.size
|
i, max = 0, value.size
|
||||||
while i < max
|
while i < max
|
||||||
|
|
|
@ -1,17 +1,4 @@
|
||||||
require 'abstract_unit'
|
require 'abstract_unit'
|
||||||
require 'fixtures/binary'
|
|
||||||
|
|
||||||
class BinaryTest < Test::Unit::TestCase
|
|
||||||
BINARY_FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures/flowers.jpg'
|
|
||||||
|
|
||||||
def setup
|
|
||||||
Binary.connection.execute 'DELETE FROM binaries'
|
|
||||||
@data = File.read(BINARY_FIXTURE_PATH).freeze
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_truth
|
|
||||||
assert true
|
|
||||||
end
|
|
||||||
|
|
||||||
# Without using prepared statements, it makes no sense to test
|
# Without using prepared statements, it makes no sense to test
|
||||||
# BLOB data with SQL Server, because the length of a statement is
|
# BLOB data with SQL Server, because the length of a statement is
|
||||||
|
@ -21,17 +8,25 @@ class BinaryTest < Test::Unit::TestCase
|
||||||
# BLOB data with DB2 or Firebird, because the length of a statement
|
# BLOB data with DB2 or Firebird, because the length of a statement
|
||||||
# is limited to 32KB.
|
# is limited to 32KB.
|
||||||
unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :DB2Adapter, :FirebirdAdapter)
|
unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :DB2Adapter, :FirebirdAdapter)
|
||||||
|
require 'fixtures/binary'
|
||||||
|
|
||||||
|
class BinaryTest < Test::Unit::TestCase
|
||||||
|
FIXTURES = %w(flowers.jpg example.log)
|
||||||
|
|
||||||
def test_load_save
|
def test_load_save
|
||||||
bin = Binary.new
|
Binary.delete_all
|
||||||
bin.data = @data
|
|
||||||
|
|
||||||
assert @data == bin.data, 'Newly assigned data differs from original'
|
FIXTURES.each do |filename|
|
||||||
|
data = File.read("#{File.dirname(__FILE__)}/fixtures/#{filename}").freeze
|
||||||
|
|
||||||
bin.save
|
bin = Binary.new(:data => data)
|
||||||
assert @data == bin.data, 'Data differs from original after save'
|
assert_equal data, bin.data, 'Newly assigned data differs from original'
|
||||||
|
|
||||||
db_bin = Binary.find(bin.id)
|
bin.save!
|
||||||
assert @data == db_bin.data, 'Reloaded data differs from original'
|
assert_equal data, bin.data, 'Data differs from original after save'
|
||||||
|
|
||||||
|
assert_equal data, bin.reload.data, 'Reloaded data differs from original'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue