mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
pg tests, get rid of global schema schema_1
.
This commit is contained in:
parent
90e396ce65
commit
780269c732
3 changed files with 51 additions and 53 deletions
|
@ -1,4 +1,5 @@
|
|||
require "cases/helper"
|
||||
require 'models/default'
|
||||
require 'support/schema_dumping_helper'
|
||||
|
||||
class SchemaTest < ActiveRecord::TestCase
|
||||
|
@ -88,7 +89,7 @@ class SchemaTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_schema_names
|
||||
assert_equal ["public", "schema_1", "test_schema", "test_schema2"], @connection.schema_names
|
||||
assert_equal ["public", "test_schema", "test_schema2"], @connection.schema_names
|
||||
end
|
||||
|
||||
def test_create_schema
|
||||
|
@ -460,3 +461,52 @@ class SchemaForeignKeyTest < ActiveRecord::TestCase
|
|||
@connection.execute "DROP SCHEMA IF EXISTS my_schema"
|
||||
end
|
||||
end
|
||||
|
||||
class DefaultsUsingMultipleSchemasAndDomainTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@connection = ActiveRecord::Base.connection
|
||||
@connection.execute "DROP SCHEMA IF EXISTS schema_1 CASCADE"
|
||||
@connection.execute "CREATE SCHEMA schema_1"
|
||||
@connection.execute "CREATE DOMAIN schema_1.text AS text"
|
||||
@connection.execute "CREATE DOMAIN schema_1.varchar AS varchar"
|
||||
@connection.execute "CREATE DOMAIN schema_1.bpchar AS bpchar"
|
||||
|
||||
@old_search_path = @connection.schema_search_path
|
||||
@connection.schema_search_path = "schema_1, pg_catalog"
|
||||
@connection.create_table "defaults" do |t|
|
||||
t.text "text_col", default: "some value"
|
||||
t.string "string_col", default: "some value"
|
||||
end
|
||||
Default.reset_column_information
|
||||
end
|
||||
|
||||
teardown do
|
||||
@connection.schema_search_path = @old_search_path
|
||||
@connection.execute "DROP SCHEMA IF EXISTS schema_1 CASCADE"
|
||||
Default.reset_column_information
|
||||
end
|
||||
|
||||
def test_text_defaults_in_new_schema_when_overriding_domain
|
||||
assert_equal "some value", Default.new.text_col, "Default of text column was not correctly parsed"
|
||||
end
|
||||
|
||||
def test_string_defaults_in_new_schema_when_overriding_domain
|
||||
assert_equal "some value", Default.new.string_col, "Default of string column was not correctly parsed"
|
||||
end
|
||||
|
||||
def test_bpchar_defaults_in_new_schema_when_overriding_domain
|
||||
@connection.execute "ALTER TABLE defaults ADD bpchar_col bpchar DEFAULT 'some value'"
|
||||
Default.reset_column_information
|
||||
assert_equal "some value", Default.new.bpchar_col, "Default of bpchar column was not correctly parsed"
|
||||
end
|
||||
|
||||
def test_text_defaults_after_updating_column_default
|
||||
@connection.execute "ALTER TABLE defaults ALTER COLUMN text_col SET DEFAULT 'some text'::schema_1.text"
|
||||
assert_equal "some text", Default.new.text_col, "Default of text column was not correctly parsed after updating default using '::text' since postgreSQL will add parens to the default in db"
|
||||
end
|
||||
|
||||
def test_default_containing_quote_and_colons
|
||||
@connection.execute "ALTER TABLE defaults ALTER COLUMN string_col SET DEFAULT 'foo''::bar'"
|
||||
assert_equal "foo'::bar", Default.new.string_col
|
||||
end
|
||||
end
|
||||
|
|
|
@ -198,48 +198,3 @@ if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
if current_adapter?(:PostgreSQLAdapter)
|
||||
class DefaultsUsingMultipleSchemasAndDomainTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@connection = ActiveRecord::Base.connection
|
||||
|
||||
@old_search_path = @connection.schema_search_path
|
||||
@connection.schema_search_path = "schema_1, pg_catalog"
|
||||
@connection.create_table "defaults" do |t|
|
||||
t.text "text_col", :default => "some value"
|
||||
t.string "string_col", :default => "some value"
|
||||
end
|
||||
Default.reset_column_information
|
||||
end
|
||||
|
||||
def test_text_defaults_in_new_schema_when_overriding_domain
|
||||
assert_equal "some value", Default.new.text_col, "Default of text column was not correctly parse"
|
||||
end
|
||||
|
||||
def test_string_defaults_in_new_schema_when_overriding_domain
|
||||
assert_equal "some value", Default.new.string_col, "Default of string column was not correctly parse"
|
||||
end
|
||||
|
||||
def test_bpchar_defaults_in_new_schema_when_overriding_domain
|
||||
@connection.execute "ALTER TABLE defaults ADD bpchar_col bpchar DEFAULT 'some value'"
|
||||
Default.reset_column_information
|
||||
assert_equal "some value", Default.new.bpchar_col, "Default of bpchar column was not correctly parse"
|
||||
end
|
||||
|
||||
def test_text_defaults_after_updating_column_default
|
||||
@connection.execute "ALTER TABLE defaults ALTER COLUMN text_col SET DEFAULT 'some text'::schema_1.text"
|
||||
assert_equal "some text", Default.new.text_col, "Default of text column was not correctly parse after updating default using '::text' since postgreSQL will add parens to the default in db"
|
||||
end
|
||||
|
||||
def test_default_containing_quote_and_colons
|
||||
@connection.execute "ALTER TABLE defaults ALTER COLUMN string_col SET DEFAULT 'foo''::bar'"
|
||||
assert_equal "foo'::bar", Default.new.string_col
|
||||
end
|
||||
|
||||
teardown do
|
||||
@connection.schema_search_path = @old_search_path
|
||||
Default.reset_column_information
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,8 +12,6 @@ ActiveRecord::Schema.define do
|
|||
|
||||
execute 'DROP FUNCTION IF EXISTS partitioned_insert_trigger()'
|
||||
|
||||
execute "DROP SCHEMA IF EXISTS schema_1 CASCADE"
|
||||
|
||||
%w(accounts_id_seq developers_id_seq projects_id_seq topics_id_seq customers_id_seq orders_id_seq).each do |seq_name|
|
||||
execute "SELECT setval('#{seq_name}', 100)"
|
||||
end
|
||||
|
@ -37,11 +35,6 @@ ActiveRecord::Schema.define do
|
|||
);
|
||||
_SQL
|
||||
|
||||
execute "CREATE SCHEMA schema_1"
|
||||
execute "CREATE DOMAIN schema_1.text AS text"
|
||||
execute "CREATE DOMAIN schema_1.varchar AS varchar"
|
||||
execute "CREATE DOMAIN schema_1.bpchar AS bpchar"
|
||||
|
||||
execute <<_SQL
|
||||
CREATE TABLE postgresql_times (
|
||||
id SERIAL PRIMARY KEY,
|
||||
|
|
Loading…
Reference in a new issue