| 1 |
require 'abstract_unit' |
|---|
| 2 |
|
|---|
| 3 |
class PostgresqlArray < ActiveRecord::Base |
|---|
| 4 |
end |
|---|
| 5 |
|
|---|
| 6 |
class PostgresqlMoney < ActiveRecord::Base |
|---|
| 7 |
end |
|---|
| 8 |
|
|---|
| 9 |
class PostgresqlNumber < ActiveRecord::Base |
|---|
| 10 |
end |
|---|
| 11 |
|
|---|
| 12 |
class PostgresqlTime < ActiveRecord::Base |
|---|
| 13 |
end |
|---|
| 14 |
|
|---|
| 15 |
class PostgresqlNetworkAddress < ActiveRecord::Base |
|---|
| 16 |
end |
|---|
| 17 |
|
|---|
| 18 |
class PostgresqlBitString < ActiveRecord::Base |
|---|
| 19 |
end |
|---|
| 20 |
|
|---|
| 21 |
class PostgresqlOid < ActiveRecord::Base |
|---|
| 22 |
end |
|---|
| 23 |
|
|---|
| 24 |
class PostgresqlDataTypeTest < Test::Unit::TestCase |
|---|
| 25 |
self.use_transactional_fixtures = false |
|---|
| 26 |
|
|---|
| 27 |
def setup |
|---|
| 28 |
@connection = ActiveRecord::Base.connection |
|---|
| 29 |
|
|---|
| 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) |
|---|
| 32 |
|
|---|
| 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) |
|---|
| 37 |
|
|---|
| 38 |
@connection.execute("INSERT INTO postgresql_numbers (single, double) VALUES (123.456, 123456.789)") |
|---|
| 39 |
@first_number = PostgresqlNumber.find(1) |
|---|
| 40 |
|
|---|
| 41 |
@connection.execute("INSERT INTO postgresql_times (time_interval) VALUES ('1 year 2 days ago')") |
|---|
| 42 |
@first_time = PostgresqlTime.find(1) |
|---|
| 43 |
|
|---|
| 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) |
|---|
| 46 |
|
|---|
| 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) |
|---|
| 49 |
|
|---|
| 50 |
@connection.execute("INSERT INTO postgresql_oids (obj_id) VALUES (1234)") |
|---|
| 51 |
@first_oid = PostgresqlOid.find(1) |
|---|
| 52 |
end |
|---|
| 53 |
|
|---|
| 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 |
|---|
| 57 |
end |
|---|
| 58 |
|
|---|
| 59 |
def test_data_type_of_money_types |
|---|
| 60 |
assert_equal :decimal, @first_money.column_for_attribute(:wealth).type |
|---|
| 61 |
end |
|---|
| 62 |
|
|---|
| 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 |
|---|
| 66 |
end |
|---|
| 67 |
|
|---|
| 68 |
def test_data_type_of_time_types |
|---|
| 69 |
assert_equal :string, @first_time.column_for_attribute(:time_interval).type |
|---|
| 70 |
end |
|---|
| 71 |
|
|---|
| 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 |
|---|
| 76 |
end |
|---|
| 77 |
|
|---|
| 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 |
|---|
| 81 |
end |
|---|
| 82 |
|
|---|
| 83 |
def test_data_type_of_oid_types |
|---|
| 84 |
assert_equal :integer, @first_oid.column_for_attribute(:obj_id).type |
|---|
| 85 |
end |
|---|
| 86 |
|
|---|
| 87 |
def test_array_values |
|---|
| 88 |
assert_equal '{35000,21000,18000,17000}', @first_array.commission_by_quarter |
|---|
| 89 |
assert_equal '{foo,bar,baz}', @first_array.nicknames |
|---|
| 90 |
end |
|---|
| 91 |
|
|---|
| 92 |
def test_money_values |
|---|
| 93 |
assert_equal 567.89, @first_money.wealth |
|---|
| 94 |
assert_equal -567.89, @second_money.wealth |
|---|
| 95 |
end |
|---|
| 96 |
|
|---|
| 97 |
def test_number_values |
|---|
| 98 |
assert_equal 123.456, @first_number.single |
|---|
| 99 |
assert_equal 123456.789, @first_number.double |
|---|
| 100 |
end |
|---|
| 101 |
|
|---|
| 102 |
def test_time_values |
|---|
| 103 |
assert_equal '-1 years -2 days', @first_time.time_interval |
|---|
| 104 |
end |
|---|
| 105 |
|
|---|
| 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 |
|---|
| 110 |
end |
|---|
| 111 |
|
|---|
| 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 |
|---|
| 115 |
end |
|---|
| 116 |
|
|---|
| 117 |
def test_oid_values |
|---|
| 118 |
assert_equal 1234, @first_oid.obj_id |
|---|
| 119 |
end |
|---|
| 120 |
|
|---|
| 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 |
|---|
| 131 |
end |
|---|
| 132 |
|
|---|
| 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 |
|---|
| 143 |
end |
|---|
| 144 |
|
|---|
| 145 |
def test_update_money |
|---|
| 146 |
new_value = 123.45 |
|---|
| 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 |
|---|
| 151 |
end |
|---|
| 152 |
|
|---|
| 153 |
def test_update_number |
|---|
| 154 |
new_single = 789.012 |
|---|
| 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 |
|---|
| 162 |
end |
|---|
| 163 |
|
|---|
| 164 |
def test_update_time |
|---|
| 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' |
|---|
| 169 |
end |
|---|
| 170 |
|
|---|
| 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 |
|---|
| 183 |
end |
|---|
| 184 |
|
|---|
| 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 |
|---|
| 194 |
end |
|---|
| 195 |
|
|---|
| 196 |
def test_update_oid |
|---|
| 197 |
new_value = 567890 |
|---|
| 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 |
|---|
| 202 |
end |
|---|
| 203 |
end |
|---|