forked from jruby/activerecord-jdbc-adapter
/
db2_simple_test.rb
66 lines (56 loc) · 1.8 KB
/
db2_simple_test.rb
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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