Sha256: 11be716eb6966d11dcdfcea2dc3030085a0979f0b7b069a6c474f65c5383b2d8

Contents?: true

Size: 1.8 KB

Versions: 27

Compression:

Stored size: 1.8 KB

Contents

require 'jdbc_common'
require 'db/db2'

class DB2SimpleTest < Test::Unit::TestCase
  include SimpleTestMethods

  # For backwards compatibility with how the DB2 code in
  # jdbc_adapter 0.9.x handled booleans.
  #
  # The old DB2 jdbc_db2.rb driver was broken enough that
  # applications were exposed to the underlying type (was DECIMAL)
  # and used 0 and 1 as false and true, respectively.
  #
  # This driver now uses SMALLINT as a boolean, and properly
  # type cast's it to a Ruby boolean. Need to make sure we don't
  # break existing apps!
  def test_boolean_as_integer
    e = DbType.find(:first)

    # true
    e.sample_boolean = 1
    assert_equal true, e.sample_boolean
    assert_equal true, e.sample_boolean?
    e.save!

    e = DbType.find(:first)
    assert_equal true, e.sample_boolean
    assert_equal true, e.sample_boolean?

    # false
    e.sample_boolean = 0
    assert_equal false, e.sample_boolean
    assert_equal false, e.sample_boolean?
    e.save!

    e = DbType.find(:first)
    assert_equal false, e.sample_boolean
    assert_equal false, e.sample_boolean?
  end
end

class DB2HasManyThroughTest < Test::Unit::TestCase
  include HasManyThroughMethods
end

class DB2Test < Test::Unit::TestCase
  def setup
    @inst = Object.new
    @inst.extend ArJdbc::DB2
    @column = Object.new
    class << @column
      attr_accessor :type
    end
  end

  def test_quote_decimal
    assert_equal %q{'123.45'}, @inst.quote("123.45")
    @column.type = :decimal
    assert_equal %q{123.45}, @inst.quote("123.45", @column), "decimal columns should not have quotes"
  end

  def test_primary_key_generation
    @column.type = :primary_key
    assert_equal 'int not null generated by default as identity (start with 1) primary key', @inst.modify_types({:string => {}, :integer => {}, :boolean => {}})[:primary_key]
  end
end

Version data entries

27 entries across 27 versions & 7 rubygems

Version Path
activerecord-jdbc-adapter-1.1.1 test/db2_simple_test.rb
activerecord-jdbc-adapter-1.1.0 test/db2_simple_test.rb
activerecord-jdbc-adapter-1.0.3-java test/db2_simple_test.rb
activerecord-jdbc-adapter-1.0.2-java test/db2_simple_test.rb
activerecord-jdbc-adapter-1.0.1-java test/db2_simple_test.rb
activerecord-jdbc-adapter-1.0.0-java test/db2_simple_test.rb
activerecord-jdbc-adapter-1.0.0.beta2-java test/db2_simple_test.rb