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
< ActiveRecord
::TestCase
25 self.use_transactional_fixtures
= false
28 @connection = ActiveRecord
::Base.connection
29 @connection.execute("set lc_monetary = 'C'")
31 @connection.execute("INSERT INTO postgresql_arrays (commission_by_quarter, nicknames) VALUES ( '{35000,21000,18000,17000}', '{foo,bar,baz}' )")
32 @first_array = PostgresqlArray
.find(1)
34 @connection.execute("INSERT INTO postgresql_moneys (wealth) VALUES ('567.89'::money)")
35 @connection.execute("INSERT INTO postgresql_moneys (wealth) VALUES ('-567.89'::money)")
36 @first_money = PostgresqlMoney
.find(1)
37 @second_money = PostgresqlMoney
.find(2)
39 @connection.execute("INSERT INTO postgresql_numbers (single, double) VALUES (123.456, 123456.789)")
40 @first_number = PostgresqlNumber
.find(1)
42 @connection.execute("INSERT INTO postgresql_times (time_interval) VALUES ('1 year 2 days ago')")
43 @first_time = PostgresqlTime
.find(1)
45 @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')")
46 @first_network_address = PostgresqlNetworkAddress
.find(1)
48 @connection.execute("INSERT INTO postgresql_bit_strings (bit_string, bit_string_varying) VALUES (B'00010101', X'15')")
49 @first_bit_string = PostgresqlBitString
.find(1)
51 @connection.execute("INSERT INTO postgresql_oids (obj_id) VALUES (1234)")
52 @first_oid = PostgresqlOid
.find(1)
55 def test_data_type_of_array_types
56 assert_equal
:string, @first_array.column_for_attribute(:commission_by_quarter).type
57 assert_equal
:string, @first_array.column_for_attribute(:nicknames).type
60 def test_data_type_of_money_types
61 assert_equal
:decimal, @first_money.column_for_attribute(:wealth).type
64 def test_data_type_of_number_types
65 assert_equal
:float, @first_number.column_for_attribute(:single).type
66 assert_equal
:float, @first_number.column_for_attribute(:double).type
69 def test_data_type_of_time_types
70 assert_equal
:string, @first_time.column_for_attribute(:time_interval).type
73 def test_data_type_of_network_address_types
74 assert_equal
:string, @first_network_address.column_for_attribute(:cidr_address).type
75 assert_equal
:string, @first_network_address.column_for_attribute(:inet_address).type
76 assert_equal
:string, @first_network_address.column_for_attribute(:mac_address).type
79 def test_data_type_of_bit_string_types
80 assert_equal
:string, @first_bit_string.column_for_attribute(:bit_string).type
81 assert_equal
:string, @first_bit_string.column_for_attribute(:bit_string_varying).type
84 def test_data_type_of_oid_types
85 assert_equal
:integer, @first_oid.column_for_attribute(:obj_id).type
89 assert_equal
'{35000,21000,18000,17000}', @first_array.commission_by_quarter
90 assert_equal
'{foo,bar,baz}', @first_array.nicknames
94 assert_equal
567.89, @first_money.wealth
95 assert_equal
-567.89, @second_money.wealth
98 def test_number_values
99 assert_equal
123.456, @first_number.single
100 assert_equal
123456.789, @first_number.double
104 assert_equal
'-1 years -2 days', @first_time.time_interval
107 def test_network_address_values
108 assert_equal
'192.168.0.0/24', @first_network_address.cidr_address
109 assert_equal
'172.16.1.254', @first_network_address.inet_address
110 assert_equal
'01:23:45:67:89:0a', @first_network_address.mac_address
113 def test_bit_string_values
114 assert_equal
'00010101', @first_bit_string.bit_string
115 assert_equal
'00010101', @first_bit_string.bit_string_varying
119 assert_equal
1234, @first_oid.obj_id
122 def test_update_integer_array
123 new_value
= '{32800,95000,29350,17000}'
124 assert
@first_array.commission_by_quarter
= new_value
125 assert
@first_array.save
126 assert
@first_array.reload
127 assert_equal
@first_array.commission_by_quarter
, new_value
128 assert
@first_array.commission_by_quarter
= new_value
129 assert
@first_array.save
130 assert
@first_array.reload
131 assert_equal
@first_array.commission_by_quarter
, new_value
134 def test_update_text_array
135 new_value
= '{robby,robert,rob,robbie}'
136 assert
@first_array.nicknames
= new_value
137 assert
@first_array.save
138 assert
@first_array.reload
139 assert_equal
@first_array.nicknames
, new_value
140 assert
@first_array.nicknames
= new_value
141 assert
@first_array.save
142 assert
@first_array.reload
143 assert_equal
@first_array.nicknames
, new_value
146 def test_update_money
147 new_value
= BigDecimal
.new('123.45')
148 assert
@first_money.wealth
= new_value
149 assert
@first_money.save
150 assert
@first_money.reload
151 assert_equal new_value
, @first_money.wealth
154 def test_update_number
156 new_double
= 789012.345
157 assert
@first_number.single
= new_single
158 assert
@first_number.double
= new_double
159 assert
@first_number.save
160 assert
@first_number.reload
161 assert_equal
@first_number.single
, new_single
162 assert_equal
@first_number.double
, new_double
166 assert
@first_time.time_interval
= '2 years 3 minutes'
167 assert
@first_time.save
168 assert
@first_time.reload
169 assert_equal
@first_time.time_interval
, '2 years 00:03:00'
172 def test_update_network_address
173 new_cidr_address
= '10.1.2.3/32'
174 new_inet_address
= '10.0.0.0/8'
175 new_mac_address
= 'bc:de:f0:12:34:56'
176 assert
@first_network_address.cidr_address
= new_cidr_address
177 assert
@first_network_address.inet_address
= new_inet_address
178 assert
@first_network_address.mac_address
= new_mac_address
179 assert
@first_network_address.save
180 assert
@first_network_address.reload
181 assert_equal
@first_network_address.cidr_address
, new_cidr_address
182 assert_equal
@first_network_address.inet_address
, new_inet_address
183 assert_equal
@first_network_address.mac_address
, new_mac_address
186 def test_update_bit_string
187 new_bit_string
= '11111111'
188 new_bit_string_varying
= 'FF'
189 assert
@first_bit_string.bit_string
= new_bit_string
190 assert
@first_bit_string.bit_string_varying
= new_bit_string_varying
191 assert
@first_bit_string.save
192 assert
@first_bit_string.reload
193 assert_equal
@first_bit_string.bit_string
, new_bit_string
194 assert_equal
@first_bit_string.bit_string
, @first_bit_string.bit_string_varying
199 assert
@first_oid.obj_id
= new_value
200 assert
@first_oid.save
201 assert
@first_oid.reload
202 assert_equal
@first_oid.obj_id
, new_value