1 require 'abstract_unit'
3 class PostgresqlArray < ActiveRecord::Base
6 class PostgresqlMoney < ActiveRecord::Base
9 class PostgresqlNumber < ActiveRecord::Base
12 class PostgresqlTime < ActiveRecord::Base
15 class PostgresqlNetworkAddress < ActiveRecord::Base
18 class PostgresqlBitString < ActiveRecord::Base
21 class PostgresqlOid < ActiveRecord::Base
24 class PostgresqlDataTypeTest < Test::Unit::TestCase
25 self.use_transactional_fixtures = false
28 @connection = ActiveRecord::Base.connection
30 @connection.execute("INSERT INTO postgresql_arrays (commission_by_quarter, nicknames) VALUES ( '{35000,21000,18000,17000}', '{foo,bar,baz}' )")
31 @first_array = PostgresqlArray.find(1)
33 @connection.execute("INSERT INTO postgresql_moneys (wealth) VALUES ('$567.89')")
34 @connection.execute("INSERT INTO postgresql_moneys (wealth) VALUES ('-$567.89')")
35 @first_money = PostgresqlMoney.find(1)
36 @second_money = PostgresqlMoney.find(2)
38 @connection.execute("INSERT INTO postgresql_numbers (single, double) VALUES (123.456, 123456.789)")
39 @first_number = PostgresqlNumber.find(1)
41 @connection.execute("INSERT INTO postgresql_times (time_interval) VALUES ('1 year 2 days ago')")
42 @first_time = PostgresqlTime.find(1)
44 @connection.execute("INSERT INTO postgresql_network_addresses (cidr_address, inet_address, mac_address) VALUES('192.168.0/24', '172.16.1.254/32', '01:23:45:67:89:0a')")
45 @first_network_address = PostgresqlNetworkAddress.find(1)
47 @connection.execute("INSERT INTO postgresql_bit_strings (bit_string, bit_string_varying) VALUES (B'00010101', X'15')")
48 @first_bit_string = PostgresqlBitString.find(1)
50 @connection.execute("INSERT INTO postgresql_oids (obj_id) VALUES (1234)")
51 @first_oid = PostgresqlOid.find(1)
54 def test_data_type_of_array_types
55 assert_equal :string, @first_array.column_for_attribute(:commission_by_quarter).type
56 assert_equal :string, @first_array.column_for_attribute(:nicknames).type
59 def test_data_type_of_money_types
60 assert_equal :decimal, @first_money.column_for_attribute(:wealth).type
63 def test_data_type_of_number_types
64 assert_equal :float, @first_number.column_for_attribute(:single).type
65 assert_equal :float, @first_number.column_for_attribute(:double).type
68 def test_data_type_of_time_types
69 assert_equal :string, @first_time.column_for_attribute(:time_interval).type
72 def test_data_type_of_network_address_types
73 assert_equal :string, @first_network_address.column_for_attribute(:cidr_address).type
74 assert_equal :string, @first_network_address.column_for_attribute(:inet_address).type
75 assert_equal :string, @first_network_address.column_for_attribute(:mac_address).type
78 def test_data_type_of_bit_string_types
79 assert_equal :string, @first_bit_string.column_for_attribute(:bit_string).type
80 assert_equal :string, @first_bit_string.column_for_attribute(:bit_string_varying).type
83 def test_data_type_of_oid_types
84 assert_equal :integer, @first_oid.column_for_attribute(:obj_id).type
88 assert_equal '{35000,21000,18000,17000}', @first_array.commission_by_quarter
89 assert_equal '{foo,bar,baz}', @first_array.nicknames
93 assert_equal 567.89, @first_money.wealth
94 assert_equal -567.89, @second_money.wealth
97 def test_number_values
98 assert_equal 123.456, @first_number.single
99 assert_equal 123456.789, @first_number.double
103 assert_equal '-1 years -2 days', @first_time.time_interval
106 def test_network_address_values
107 assert_equal '192.168.0.0/24', @first_network_address.cidr_address
108 assert_equal '172.16.1.254', @first_network_address.inet_address
109 assert_equal '01:23:45:67:89:0a', @first_network_address.mac_address
112 def test_bit_string_values
113 assert_equal '00010101', @first_bit_string.bit_string
114 assert_equal '00010101', @first_bit_string.bit_string_varying
118 assert_equal 1234, @first_oid.obj_id
121 def test_update_integer_array
122 new_value = '{32800,95000,29350,17000}'
123 assert @first_array.commission_by_quarter = new_value
124 assert @first_array.save
125 assert @first_array.reload
126 assert_equal @first_array.commission_by_quarter, new_value
127 assert @first_array.commission_by_quarter = new_value
128 assert @first_array.save
129 assert @first_array.reload
130 assert_equal @first_array.commission_by_quarter, new_value
133 def test_update_text_array
134 new_value = '{robby,robert,rob,robbie}'
135 assert @first_array.nicknames = new_value
136 assert @first_array.save
137 assert @first_array.reload
138 assert_equal @first_array.nicknames, new_value
139 assert @first_array.nicknames = new_value
140 assert @first_array.save
141 assert @first_array.reload
142 assert_equal @first_array.nicknames, new_value
145 def test_update_money
147 assert @first_money.wealth = new_value
148 assert @first_money.save
149 assert @first_money.reload
150 assert_equal @first_money.wealth, new_value
153 def test_update_number
155 new_double = 789012.345
156 assert @first_number.single = new_single
157 assert @first_number.double = new_double
158 assert @first_number.save
159 assert @first_number.reload
160 assert_equal @first_number.single, new_single
161 assert_equal @first_number.double, new_double
165 assert @first_time.time_interval = '2 years 3 minutes'
166 assert @first_time.save
167 assert @first_time.reload
168 assert_equal @first_time.time_interval, '2 years 00:03:00'
171 def test_update_network_address
172 new_cidr_address = '10.1.2.3/32'
173 new_inet_address = '10.0.0.0/8'
174 new_mac_address = 'bc:de:f0:12:34:56'
175 assert @first_network_address.cidr_address = new_cidr_address
176 assert @first_network_address.inet_address = new_inet_address
177 assert @first_network_address.mac_address = new_mac_address
178 assert @first_network_address.save
179 assert @first_network_address.reload
180 assert_equal @first_network_address.cidr_address, new_cidr_address
181 assert_equal @first_network_address.inet_address, new_inet_address
182 assert_equal @first_network_address.mac_address, new_mac_address
185 def test_update_bit_string
186 new_bit_string = '11111111'
187 new_bit_string_varying = 'FF'
188 assert @first_bit_string.bit_string = new_bit_string
189 assert @first_bit_string.bit_string_varying = new_bit_string_varying
190 assert @first_bit_string.save
191 assert @first_bit_string.reload
192 assert_equal @first_bit_string.bit_string, new_bit_string
193 assert_equal @first_bit_string.bit_string, @first_bit_string.bit_string_varying
198 assert @first_oid.obj_id = new_value
199 assert @first_oid.save
200 assert @first_oid.reload
201 assert_equal @first_oid.obj_id, new_value