提交 50be1d0d 编写于 作者: Y Yves Senn

move PostgreSQL UUID tests from `datatype_test.rb` to `uuid_test.rb`.

上级 be97499b
......@@ -27,9 +27,6 @@ class PostgresqlOid < ActiveRecord::Base
class PostgresqlTimestampWithZone < ActiveRecord::Base
end
class PostgresqlUUID < ActiveRecord::Base
end
class PostgresqlLtree < ActiveRecord::Base
end
......@@ -68,14 +65,11 @@ def setup
@first_oid = PostgresqlOid.find(1)
@connection.execute("INSERT INTO postgresql_timestamp_with_zones (id, time) VALUES (1, '2010-01-01 10:00:00-1')")
@connection.execute("INSERT INTO postgresql_uuids (id, guid, compact_guid) VALUES(1, 'd96c3da0-96c1-012f-1316-64ce8f32c6d8', 'f06c715096c1012f131764ce8f32c6d8')")
@first_uuid = PostgresqlUUID.find(1)
end
def teardown
[PostgresqlArray, PostgresqlTsvector, PostgresqlMoney, PostgresqlNumber, PostgresqlTime, PostgresqlNetworkAddress,
PostgresqlBitString, PostgresqlOid, PostgresqlTimestampWithZone, PostgresqlUUID].each(&:delete_all)
PostgresqlBitString, PostgresqlOid, PostgresqlTimestampWithZone].each(&:delete_all)
end
def test_array_escaping
......@@ -124,10 +118,6 @@ def test_data_type_of_oid_types
assert_equal :integer, @first_oid.column_for_attribute(:obj_id).type
end
def test_data_type_of_uuid_types
assert_equal :uuid, @first_uuid.column_for_attribute(:guid).type
end
def test_array_values
assert_equal [35000,21000,18000,17000], @first_array.commission_by_quarter
assert_equal ['foo','bar','baz'], @first_array.nicknames
......@@ -180,11 +170,6 @@ def test_network_address_values_ipaddr
assert_equal '01:23:45:67:89:0a', @first_network_address.mac_address
end
def test_uuid_values
assert_equal 'd96c3da0-96c1-012f-1316-64ce8f32c6d8', @first_uuid.guid
assert_equal 'f06c7150-96c1-012f-1317-64ce8f32c6d8', @first_uuid.compact_guid
end
def test_bit_string_values
assert_equal '00010101', @first_bit_string.bit_string
assert_equal '00010101', @first_bit_string.bit_string_varying
......
......@@ -5,6 +5,41 @@
require 'active_record/connection_adapters/postgresql_adapter'
class PostgresqlUUIDTest < ActiveRecord::TestCase
class UUIDType < ActiveRecord::Base
self.table_name = "uuid_data_type"
end
def setup
@connection = ActiveRecord::Base.connection
@connection.transaction do
@connection.create_table "uuid_data_type" do |t|
t.uuid 'guid'
end
end
end
def teardown
@connection.execute 'drop table if exists uuid_data_type'
end
def test_data_type_of_uuid_types
assert_equal :uuid, UUIDType.columns_hash["guid"].type
end
def test_uuid_formats
["A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11",
"{a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11}",
"a0eebc999c0b4ef8bb6d6bb9bd380a11",
"a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11",
"{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}"].each do |valid_uuid|
UUIDType.create(guid: valid_uuid)
uuid = UUIDType.last
assert_equal "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", uuid.guid
end
end
end
class PostgresqlUUIDGenerationTest < ActiveRecord::TestCase
class UUID < ActiveRecord::Base
self.table_name = 'pg_uuids'
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册