mirror of https://github.com/rails/rails
tests, move schema shorthand assertions into pg specific tests.
This commit is contained in:
parent
bcf5b281a8
commit
af7c6e493c
|
@ -1,7 +1,9 @@
|
|||
# encoding: utf-8
|
||||
require "cases/helper"
|
||||
require 'support/schema_dumping_helper'
|
||||
|
||||
class PostgresqlArrayTest < ActiveRecord::TestCase
|
||||
include SchemaDumpingHelper
|
||||
include InTimeZone
|
||||
OID = ActiveRecord::ConnectionAdapters::PostgreSQL::OID
|
||||
|
||||
|
@ -108,6 +110,12 @@ class PostgresqlArrayTest < ActiveRecord::TestCase
|
|||
assert_equal([1, 2], x.ratings)
|
||||
end
|
||||
|
||||
def test_schema_dump_with_shorthand
|
||||
output = dump_table_schema "pg_arrays"
|
||||
assert_match %r[t.string\s+"tags",\s+array: true], output
|
||||
assert_match %r[t.integer\s+"ratings",\s+array: true], output
|
||||
end
|
||||
|
||||
def test_select_with_strings
|
||||
@connection.execute "insert into pg_arrays (tags) VALUES ('{1,2,3}')"
|
||||
x = PgArray.first
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
# encoding: utf-8
|
||||
require 'cases/helper'
|
||||
require 'support/schema_dumping_helper'
|
||||
|
||||
if ActiveRecord::Base.connection.supports_extensions?
|
||||
class PostgresqlCitextTest < ActiveRecord::TestCase
|
||||
include SchemaDumpingHelper
|
||||
class Citext < ActiveRecord::Base
|
||||
self.table_name = 'citexts'
|
||||
end
|
||||
|
@ -67,5 +69,10 @@ if ActiveRecord::Base.connection.supports_extensions?
|
|||
x = Citext.where(cival: 'cased text').first
|
||||
assert_equal 'Cased Text', x.cival
|
||||
end
|
||||
|
||||
def test_schema_dump_with_shorthand
|
||||
output = dump_table_schema("citexts")
|
||||
assert_match %r[t.citext "cival"], output
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,24 @@
|
|||
# encoding: utf-8
|
||||
require "cases/helper"
|
||||
require 'support/schema_dumping_helper'
|
||||
|
||||
class PostgresqlFullTextTest < ActiveRecord::TestCase
|
||||
class PostgresqlTsvector < ActiveRecord::Base; end
|
||||
include SchemaDumpingHelper
|
||||
class Tsvector < ActiveRecord::Base; end
|
||||
|
||||
setup do
|
||||
@connection = ActiveRecord::Base.connection
|
||||
@connection.create_table('tsvectors') do |t|
|
||||
t.tsvector 'text_vector'
|
||||
end
|
||||
end
|
||||
|
||||
teardown do
|
||||
@connection.execute 'DROP TABLE IF EXISTS tsvectors;'
|
||||
end
|
||||
|
||||
def test_tsvector_column
|
||||
column = PostgresqlTsvector.columns_hash["text_vector"]
|
||||
column = Tsvector.columns_hash["text_vector"]
|
||||
assert_equal :tsvector, column.type
|
||||
assert_equal "tsvector", column.sql_type
|
||||
assert_not column.number?
|
||||
|
@ -14,8 +27,8 @@ class PostgresqlFullTextTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_update_tsvector
|
||||
PostgresqlTsvector.create text_vector: "'text' 'vector'"
|
||||
tsvector = PostgresqlTsvector.first
|
||||
Tsvector.create text_vector: "'text' 'vector'"
|
||||
tsvector = Tsvector.first
|
||||
assert_equal "'text' 'vector'", tsvector.text_vector
|
||||
|
||||
tsvector.text_vector = "'new' 'text' 'vector'"
|
||||
|
@ -23,4 +36,9 @@ class PostgresqlFullTextTest < ActiveRecord::TestCase
|
|||
assert tsvector.reload
|
||||
assert_equal "'new' 'text' 'vector'", tsvector.text_vector
|
||||
end
|
||||
|
||||
def test_schema_dump_with_shorthand
|
||||
output = dump_table_schema("tsvectors")
|
||||
assert_match %r{t.tsvector "text_vector"}, output
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
# encoding: utf-8
|
||||
require "cases/helper"
|
||||
require 'support/schema_dumping_helper'
|
||||
|
||||
if ActiveRecord::Base.connection.supports_extensions?
|
||||
class PostgresqlHstoreTest < ActiveRecord::TestCase
|
||||
include SchemaDumpingHelper
|
||||
class Hstore < ActiveRecord::Base
|
||||
self.table_name = 'hstores'
|
||||
|
||||
|
@ -313,6 +315,11 @@ if ActiveRecord::Base.connection.supports_extensions?
|
|||
assert_equal({"one" => "two"}, dupe.tags.to_hash)
|
||||
end
|
||||
|
||||
def test_schema_dump_with_shorthand
|
||||
output = dump_table_schema("hstores")
|
||||
assert_match %r[t.hstore "tags",\s+default: {}], output
|
||||
end
|
||||
|
||||
private
|
||||
def assert_array_cycle(array)
|
||||
# test creation
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
# encoding: utf-8
|
||||
require "cases/helper"
|
||||
require 'support/schema_dumping_helper'
|
||||
|
||||
class PostgresqlLtreeTest < ActiveRecord::TestCase
|
||||
include SchemaDumpingHelper
|
||||
class Ltree < ActiveRecord::Base
|
||||
self.table_name = 'ltrees'
|
||||
end
|
||||
|
@ -43,4 +45,9 @@ class PostgresqlLtreeTest < ActiveRecord::TestCase
|
|||
ltree = Ltree.first
|
||||
assert_equal '1.2.3', ltree.path
|
||||
end
|
||||
|
||||
def test_schema_dump_with_shorthand
|
||||
output = dump_table_schema("ltrees")
|
||||
assert_match %r[t.ltree "path"], output
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,22 @@
|
|||
# encoding: utf-8
|
||||
require "cases/helper"
|
||||
require 'support/schema_dumping_helper'
|
||||
|
||||
class PostgresqlNetworkTest < ActiveRecord::TestCase
|
||||
class PostgresqlNetworkAddress < ActiveRecord::Base
|
||||
include SchemaDumpingHelper
|
||||
class PostgresqlNetworkAddress < ActiveRecord::Base; end
|
||||
|
||||
setup do
|
||||
@connection = ActiveRecord::Base.connection
|
||||
@connection.create_table('postgresql_network_addresses') do |t|
|
||||
t.inet 'inet_address', default: "192.168.1.1"
|
||||
t.cidr 'cidr_address', default: "192.168.1.0/24"
|
||||
t.macaddr 'mac_address', default: "ff:ff:ff:ff:ff:ff"
|
||||
end
|
||||
end
|
||||
|
||||
teardown do
|
||||
@connection.execute 'DROP TABLE IF EXISTS postgresql_network_addresses'
|
||||
end
|
||||
|
||||
def test_cidr_column
|
||||
|
@ -68,4 +82,11 @@ class PostgresqlNetworkTest < ActiveRecord::TestCase
|
|||
assert_nil invalid_address.cidr_address_before_type_cast
|
||||
assert_nil invalid_address.inet_address_before_type_cast
|
||||
end
|
||||
|
||||
def test_schema_dump_with_shorthand
|
||||
output = dump_table_schema("postgresql_network_addresses")
|
||||
assert_match %r{t.inet\s+"inet_address",\s+default: "192.168.1.1"}, output
|
||||
assert_match %r{t.cidr\s+"cidr_address",\s+default: "192.168.1.0/24"}, output
|
||||
assert_match %r{t.macaddr\s+"mac_address",\s+default: "ff:ff:ff:ff:ff:ff"}, output
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,6 +14,7 @@ end
|
|||
|
||||
class PostgresqlUUIDTest < ActiveRecord::TestCase
|
||||
include PostgresqlUUIDHelper
|
||||
include SchemaDumpingHelper
|
||||
|
||||
class UUIDType < ActiveRecord::Base
|
||||
self.table_name = "uuid_data_type"
|
||||
|
@ -106,6 +107,11 @@ class PostgresqlUUIDTest < ActiveRecord::TestCase
|
|||
assert_equal "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", uuid.guid
|
||||
end
|
||||
end
|
||||
|
||||
def test_schema_dump_with_shorthand
|
||||
output = dump_table_schema "uuid_data_type"
|
||||
assert_match %r{t.uuid "guid"}, output
|
||||
end
|
||||
end
|
||||
|
||||
class PostgresqlLargeKeysTest < ActiveRecord::TestCase
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
# encoding: utf-8
|
||||
require 'cases/helper'
|
||||
require 'support/schema_dumping_helper'
|
||||
|
||||
class PostgresqlXMLTest < ActiveRecord::TestCase
|
||||
include SchemaDumpingHelper
|
||||
class XmlDataType < ActiveRecord::Base
|
||||
self.table_name = 'xml_data_type'
|
||||
end
|
||||
|
@ -45,4 +47,9 @@ class PostgresqlXMLTest < ActiveRecord::TestCase
|
|||
XmlDataType.update_all(payload: "<bar>baz</bar>")
|
||||
assert_equal "<bar>baz</bar>", data.reload.payload
|
||||
end
|
||||
|
||||
def test_schema_dump_with_shorthand
|
||||
output = dump_table_schema("xml_data_type")
|
||||
assert_match %r{t.xml "payload"}, output
|
||||
end
|
||||
end
|
||||
|
|
|
@ -253,77 +253,6 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|||
assert_no_match %r{enable_extension}, output
|
||||
end
|
||||
end
|
||||
|
||||
def test_schema_dump_includes_xml_shorthand_definition
|
||||
output = standard_dump
|
||||
if %r{create_table "postgresql_xml_data_type"} =~ output
|
||||
assert_match %r{t.xml "data"}, output
|
||||
end
|
||||
end
|
||||
|
||||
def test_schema_dump_includes_inet_shorthand_definition
|
||||
output = standard_dump
|
||||
if %r{create_table "postgresql_network_addresses"} =~ output
|
||||
assert_match %r{t.inet\s+"inet_address",\s+default: "192.168.1.1"}, output
|
||||
end
|
||||
end
|
||||
|
||||
def test_schema_dump_includes_cidr_shorthand_definition
|
||||
output = standard_dump
|
||||
if %r{create_table "postgresql_network_addresses"} =~ output
|
||||
assert_match %r{t.cidr\s+"cidr_address",\s+default: "192.168.1.0/24"}, output
|
||||
end
|
||||
end
|
||||
|
||||
def test_schema_dump_includes_macaddr_shorthand_definition
|
||||
output = standard_dump
|
||||
if %r{create_table "postgresql_network_addresses"} =~ output
|
||||
assert_match %r{t.macaddr\s+"mac_address",\s+default: "ff:ff:ff:ff:ff:ff"}, output
|
||||
end
|
||||
end
|
||||
|
||||
def test_schema_dump_includes_uuid_shorthand_definition
|
||||
output = standard_dump
|
||||
if %r{create_table "postgresql_uuids"} =~ output
|
||||
assert_match %r{t.uuid "guid"}, output
|
||||
end
|
||||
end
|
||||
|
||||
def test_schema_dump_includes_hstores_shorthand_definition
|
||||
output = standard_dump
|
||||
if %r{create_table "postgresql_hstores"} =~ output
|
||||
assert_match %r[t.hstore "hash_store", default: {}], output
|
||||
end
|
||||
end
|
||||
|
||||
def test_schema_dump_includes_citext_shorthand_definition
|
||||
output = standard_dump
|
||||
if %r{create_table "postgresql_citext"} =~ output
|
||||
assert_match %r[t.citext "text_citext"], output
|
||||
end
|
||||
end
|
||||
|
||||
def test_schema_dump_includes_ltrees_shorthand_definition
|
||||
output = standard_dump
|
||||
if %r{create_table "postgresql_ltrees"} =~ output
|
||||
assert_match %r[t.ltree "path"], output
|
||||
end
|
||||
end
|
||||
|
||||
def test_schema_dump_includes_arrays_shorthand_definition
|
||||
output = standard_dump
|
||||
if %r{create_table "postgresql_arrays"} =~ output
|
||||
assert_match %r[t.text\s+"nicknames",\s+array: true], output
|
||||
assert_match %r[t.integer\s+"commission_by_quarter",\s+array: true], output
|
||||
end
|
||||
end
|
||||
|
||||
def test_schema_dump_includes_tsvector_shorthand_definition
|
||||
output = standard_dump
|
||||
if %r{create_table "postgresql_tsvectors"} =~ output
|
||||
assert_match %r{t.tsvector "text_vector"}, output
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_schema_dump_keeps_large_precision_integer_columns_as_decimal
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
ActiveRecord::Schema.define do
|
||||
|
||||
%w(postgresql_tsvectors postgresql_hstores postgresql_arrays postgresql_moneys postgresql_numbers postgresql_times
|
||||
postgresql_network_addresses postgresql_uuids postgresql_ltrees postgresql_oids postgresql_xml_data_type defaults
|
||||
geometrics postgresql_timestamp_with_zones postgresql_partitioned_table postgresql_partitioned_table_parent
|
||||
postgresql_citext).each do |table_name|
|
||||
%w(postgresql_arrays postgresql_numbers postgresql_times
|
||||
postgresql_oids defaults postgresql_timestamp_with_zones
|
||||
postgresql_partitioned_table postgresql_partitioned_table_parent).each do |table_name|
|
||||
execute "DROP TABLE IF EXISTS #{quote_table_name table_name}"
|
||||
end
|
||||
|
||||
|
@ -52,48 +51,6 @@ _SQL
|
|||
);
|
||||
_SQL
|
||||
|
||||
execute <<_SQL
|
||||
CREATE TABLE postgresql_uuids (
|
||||
id SERIAL PRIMARY KEY,
|
||||
guid uuid,
|
||||
compact_guid uuid
|
||||
);
|
||||
_SQL
|
||||
|
||||
execute <<_SQL
|
||||
CREATE TABLE postgresql_tsvectors (
|
||||
id SERIAL PRIMARY KEY,
|
||||
text_vector tsvector
|
||||
);
|
||||
_SQL
|
||||
|
||||
if 't' == select_value("select 'hstore'=ANY(select typname from pg_type)")
|
||||
execute <<_SQL
|
||||
CREATE TABLE postgresql_hstores (
|
||||
id SERIAL PRIMARY KEY,
|
||||
hash_store hstore default ''::hstore
|
||||
);
|
||||
_SQL
|
||||
end
|
||||
|
||||
if 't' == select_value("select 'ltree'=ANY(select typname from pg_type)")
|
||||
execute <<_SQL
|
||||
CREATE TABLE postgresql_ltrees (
|
||||
id SERIAL PRIMARY KEY,
|
||||
path ltree
|
||||
);
|
||||
_SQL
|
||||
end
|
||||
|
||||
if 't' == select_value("select 'citext'=ANY(select typname from pg_type)")
|
||||
execute <<_SQL
|
||||
CREATE TABLE postgresql_citext (
|
||||
id SERIAL PRIMARY KEY,
|
||||
text_citext citext default ''::citext
|
||||
);
|
||||
_SQL
|
||||
end
|
||||
|
||||
execute <<_SQL
|
||||
CREATE TABLE postgresql_numbers (
|
||||
id SERIAL PRIMARY KEY,
|
||||
|
@ -110,15 +67,6 @@ _SQL
|
|||
);
|
||||
_SQL
|
||||
|
||||
execute <<_SQL
|
||||
CREATE TABLE postgresql_network_addresses (
|
||||
id SERIAL PRIMARY KEY,
|
||||
cidr_address CIDR default '192.168.1.0/24',
|
||||
inet_address INET default '192.168.1.1',
|
||||
mac_address MACADDR default 'ff:ff:ff:ff:ff:ff'
|
||||
);
|
||||
_SQL
|
||||
|
||||
execute <<_SQL
|
||||
CREATE TABLE postgresql_oids (
|
||||
id SERIAL PRIMARY KEY,
|
||||
|
|
Loading…
Reference in New Issue