2008-01-21 12:20:51 -05:00
|
|
|
require "cases/helper"
|
2005-01-01 13:34:39 -05:00
|
|
|
|
2007-11-21 20:29:19 -05: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
|
|
|
|
# BLOB data with DB2 or Firebird, because the length of a statement
|
|
|
|
# is limited to 32KB.
|
|
|
|
unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :DB2Adapter, :FirebirdAdapter)
|
2008-01-18 02:31:37 -05:00
|
|
|
require 'models/binary'
|
2005-09-26 16:29:06 -04:00
|
|
|
|
2008-01-21 12:20:51 -05:00
|
|
|
class BinaryTest < ActiveRecord::TestCase
|
2007-11-21 20:29:19 -05:00
|
|
|
FIXTURES = %w(flowers.jpg example.log)
|
2005-07-01 13:20:04 -04:00
|
|
|
|
2005-09-26 16:29:06 -04:00
|
|
|
def test_load_save
|
2007-11-21 20:29:19 -05:00
|
|
|
Binary.delete_all
|
|
|
|
|
|
|
|
FIXTURES.each do |filename|
|
2008-04-01 02:58:52 -04:00
|
|
|
data = File.read(ASSETS_ROOT + "/#{filename}")
|
|
|
|
data.force_encoding('ASCII-8BIT') if data.respond_to?(:force_encoding)
|
|
|
|
data.freeze
|
2007-11-21 20:29:19 -05:00
|
|
|
|
|
|
|
bin = Binary.new(:data => data)
|
|
|
|
assert_equal data, bin.data, 'Newly assigned data differs from original'
|
2005-01-01 13:34:39 -05:00
|
|
|
|
2007-11-21 20:29:19 -05:00
|
|
|
bin.save!
|
|
|
|
assert_equal data, bin.data, 'Data differs from original after save'
|
2005-01-01 13:34:39 -05:00
|
|
|
|
2007-11-21 20:29:19 -05:00
|
|
|
assert_equal data, bin.reload.data, 'Reloaded data differs from original'
|
|
|
|
end
|
2005-09-26 16:29:06 -04:00
|
|
|
end
|
2005-01-01 13:34:39 -05:00
|
|
|
end
|
2005-01-03 18:00:44 -05:00
|
|
|
end
|