aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/binary_test.rb
blob: 38a5d509354add1b0eec5518debb2e78baa5d7f0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
  # 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 %w(SQLServer Sybase DB2 Oracle Firebird).include? ActiveRecord::Base.connection.adapter_name
    def test_load_save
      bin = Binary.new
      bin.data = @data

      assert @data == bin.data, 'Newly assigned data differs from original'
          
      bin.save
      assert @data == bin.data, 'Data differs from original after save'

      db_bin = Binary.find(bin.id)
      assert @data == db_bin.data, 'Reloaded data differs from original'
    end
  end
end