Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 373
- Log:
Initial import of Radiant 0.9.1, which is now packaged as a gem. This is an
import of the tagged 0.9.1 source checked out from GitHub, which isn't quite
the same as the gem distribution - but it doesn't seem to be available in an
archived form and the installed gem already has modifications, so this is
the closest I can get.
- Author:
- rool
- Date:
- Mon Mar 21 13:40:05 +0000 2011
- Size:
- 7063 Bytes
1 | require "cases/helper" |
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 < ActiveRecord::TestCase |
25 | self.use_transactional_fixtures = false |
26 | |
27 | def setup |
28 | @connection = ActiveRecord::Base.connection |
29 | @connection.execute("set lc_monetary = 'C'") |
30 | |
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) |
33 | |
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) |
38 | |
39 | @connection.execute("INSERT INTO postgresql_numbers (single, double) VALUES (123.456, 123456.789)") |
40 | @first_number = PostgresqlNumber.find(1) |
41 | |
42 | @connection.execute("INSERT INTO postgresql_times (time_interval) VALUES ('1 year 2 days ago')") |
43 | @first_time = PostgresqlTime.find(1) |
44 | |
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) |
47 | |
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) |
50 | |
51 | @connection.execute("INSERT INTO postgresql_oids (obj_id) VALUES (1234)") |
52 | @first_oid = PostgresqlOid.find(1) |
53 | end |
54 | |
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 |
58 | end |
59 | |
60 | def test_data_type_of_money_types |
61 | assert_equal :decimal, @first_money.column_for_attribute(:wealth).type |
62 | end |
63 | |
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 |
67 | end |
68 | |
69 | def test_data_type_of_time_types |
70 | assert_equal :string, @first_time.column_for_attribute(:time_interval).type |
71 | end |
72 | |
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 |
77 | end |
78 | |
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 |
82 | end |
83 | |
84 | def test_data_type_of_oid_types |
85 | assert_equal :integer, @first_oid.column_for_attribute(:obj_id).type |
86 | end |
87 | |
88 | def test_array_values |
89 | assert_equal '{35000,21000,18000,17000}', @first_array.commission_by_quarter |
90 | assert_equal '{foo,bar,baz}', @first_array.nicknames |
91 | end |
92 | |
93 | def test_money_values |
94 | assert_equal 567.89, @first_money.wealth |
95 | assert_equal -567.89, @second_money.wealth |
96 | end |
97 | |
98 | def test_number_values |
99 | assert_equal 123.456, @first_number.single |
100 | assert_equal 123456.789, @first_number.double |
101 | end |
102 | |
103 | def test_time_values |
104 | assert_equal '-1 years -2 days', @first_time.time_interval |
105 | end |
106 | |
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 |
111 | end |
112 | |
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 |
116 | end |
117 | |
118 | def test_oid_values |
119 | assert_equal 1234, @first_oid.obj_id |
120 | end |
121 | |
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 |
132 | end |
133 | |
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 |
144 | end |
145 | |
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 |
152 | end |
153 | |
154 | def test_update_number |
155 | new_single = 789.012 |
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 |
163 | end |
164 | |
165 | def test_update_time |
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' |
170 | end |
171 | |
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 |
184 | end |
185 | |
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 |
195 | end |
196 | |
197 | def test_update_oid |
198 | new_value = 567890 |
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 |
203 | end |
204 | end |