2005-01-01 13:34:39 -05:00
|
|
|
require 'abstract_unit'
|
|
|
|
require 'fixtures/binary'
|
|
|
|
|
|
|
|
class BinaryTest < Test::Unit::TestCase
|
2005-09-26 16:29:06 -04:00
|
|
|
BINARY_FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures/flowers.jpg'
|
|
|
|
|
2005-01-01 13:34:39 -05:00
|
|
|
def setup
|
2005-09-26 16:29:06 -04:00
|
|
|
Binary.connection.execute 'DELETE FROM binaries'
|
|
|
|
@data = File.read(BINARY_FIXTURE_PATH).freeze
|
2005-01-01 13:34:39 -05:00
|
|
|
end
|
2005-10-17 14:17:05 -04:00
|
|
|
|
|
|
|
def test_truth
|
|
|
|
assert true
|
|
|
|
end
|
2005-07-01 13:20:04 -04:00
|
|
|
|
2005-09-26 16:29:06 -04:00
|
|
|
# Without using prepared statements, it makes no sense to test
|
|
|
|
# BLOB data with SQL Server, because the length of a statement is
|
|
|
|
# limited to 8KB.
|
|
|
|
#
|
|
|
|
# Without using prepared statements, it makes no sense to test
|
2005-11-16 03:18:13 -05:00
|
|
|
# BLOB data with DB2 or Firebird, because the length of a statement
|
|
|
|
# is limited to 32KB.
|
2006-03-17 22:02:32 -05:00
|
|
|
unless %w(SQLServer Sybase DB2 Oracle Firebird).include? ActiveRecord::Base.connection.adapter_name
|
2005-09-26 16:29:06 -04:00
|
|
|
def test_load_save
|
|
|
|
bin = Binary.new
|
|
|
|
bin.data = @data
|
2005-01-01 13:34:39 -05:00
|
|
|
|
2005-09-26 16:29:06 -04:00
|
|
|
assert @data == bin.data, 'Newly assigned data differs from original'
|
|
|
|
|
|
|
|
bin.save
|
|
|
|
assert @data == bin.data, 'Data differs from original after save'
|
2005-01-01 13:34:39 -05:00
|
|
|
|
2005-09-26 16:29:06 -04:00
|
|
|
db_bin = Binary.find(bin.id)
|
|
|
|
assert @data == db_bin.data, 'Reloaded data differs from original'
|
|
|
|
end
|
2005-01-01 13:34:39 -05:00
|
|
|
end
|
2005-01-03 18:00:44 -05:00
|
|
|
end
|