mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
336c2cbb8f
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@522 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
47 lines
1.4 KiB
Ruby
47 lines
1.4 KiB
Ruby
require 'abstract_unit'
|
|
require 'fixtures/binary'
|
|
|
|
class BinaryTest < Test::Unit::TestCase
|
|
def setup
|
|
@data = create_data_fixture
|
|
end
|
|
|
|
def test_load_save
|
|
# Without using prepared statements, it makes no sense to test
|
|
# BLOB data with DB2, because the length of a statement is
|
|
# limited to 32KB.
|
|
if ActiveRecord::ConnectionAdapters.const_defined? :DB2Adapter
|
|
return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::DB2Adapter)
|
|
end
|
|
|
|
if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter
|
|
return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter)
|
|
end
|
|
bin = Binary.new
|
|
bin.data = @data
|
|
|
|
assert bin.data == @data,
|
|
"Assigned data differs from file data"
|
|
|
|
bin.save
|
|
|
|
assert bin.data == @data,
|
|
"Assigned data differs from file data after save"
|
|
|
|
db_bin = Binary.find(bin.id)
|
|
|
|
assert db_bin.data == bin.data,
|
|
"Loaded binary data differs from memory version"
|
|
|
|
assert db_bin.data == File.new(File.dirname(__FILE__)+"/fixtures/associations.png","rb").read,
|
|
"Loaded binary data differs from file version"
|
|
end
|
|
|
|
private
|
|
|
|
def create_data_fixture
|
|
Binary.connection.execute("DELETE FROM binaries")
|
|
File.new(File.dirname(__FILE__)+"/fixtures/associations.png","rb").read
|
|
end
|
|
|
|
end
|