提交 2ca056be 编写于 作者: R Ryuta Kamizono

Ensure `reset_table_name` when table name prefix/suffix is changed

Also, `reset_column_information` is unnecessary since `reset_table_name`
does that too.
上级 9d02b1bd
......@@ -22,23 +22,26 @@ def setup
@connection = ActiveRecord::Base.connection
@old_schema_migration_table_name = ActiveRecord::SchemaMigration.table_name
@old_table_name_prefix = ActiveRecord::Base.table_name_prefix
@old_table_name_suffix = ActiveRecord::Base.table_name_suffix
ActiveRecord::Base.table_name_prefix = "p_"
ActiveRecord::Base.table_name_suffix = "_s"
ActiveRecord::SchemaMigration.reset_table_name
ActiveRecord::InternalMetadata.reset_table_name
ActiveRecord::SchemaMigration.delete_all rescue nil
ActiveRecord::SchemaMigration.table_name = "p_schema_migrations_s"
ActiveRecord::Migration.verbose = false
end
def teardown
ActiveRecord::Base.table_name_prefix = @old_table_name_prefix
ActiveRecord::Base.table_name_suffix = @old_table_name_suffix
ActiveRecord::SchemaMigration.delete_all rescue nil
ActiveRecord::Migration.verbose = true
ActiveRecord::SchemaMigration.table_name = @old_schema_migration_table_name
ActiveRecord::Base.table_name_prefix = @old_table_name_prefix
ActiveRecord::Base.table_name_suffix = @old_table_name_suffix
ActiveRecord::SchemaMigration.reset_table_name
ActiveRecord::InternalMetadata.reset_table_name
super
end
......
......@@ -51,11 +51,11 @@ def test_schema_define
assert_equal 7, @connection.migration_context.current_version
end
def test_schema_define_w_table_name_prefix
table_name = ActiveRecord::SchemaMigration.table_name
def test_schema_define_with_table_name_prefix
old_table_name_prefix = ActiveRecord::Base.table_name_prefix
ActiveRecord::Base.table_name_prefix = "nep_"
ActiveRecord::SchemaMigration.table_name = "nep_#{table_name}"
ActiveRecord::SchemaMigration.reset_table_name
ActiveRecord::InternalMetadata.reset_table_name
ActiveRecord::Schema.define(version: 7) do
create_table :fruits do |t|
t.column :color, :string
......@@ -67,7 +67,8 @@ def test_schema_define_w_table_name_prefix
assert_equal 7, @connection.migration_context.current_version
ensure
ActiveRecord::Base.table_name_prefix = old_table_name_prefix
ActiveRecord::SchemaMigration.table_name = table_name
ActiveRecord::SchemaMigration.reset_table_name
ActiveRecord::InternalMetadata.reset_table_name
end
def test_schema_raises_an_error_for_invalid_column_type
......
......@@ -385,6 +385,7 @@ def test_schema_migrations_table_name
assert_equal "changed", ActiveRecord::SchemaMigration.table_name
ensure
ActiveRecord::Base.schema_migrations_table_name = original_schema_migrations_table_name
ActiveRecord::SchemaMigration.reset_table_name
Reminder.reset_table_name
end
......@@ -405,6 +406,7 @@ def test_internal_metadata_table_name
assert_equal "changed", ActiveRecord::InternalMetadata.table_name
ensure
ActiveRecord::Base.internal_metadata_table_name = original_internal_metadata_table_name
ActiveRecord::InternalMetadata.reset_table_name
Reminder.reset_table_name
end
......
......@@ -1001,18 +1001,14 @@ class DatabaseTasksTruncateAllWithPrefixTest < DatabaseTasksTruncateAllTest
ActiveRecord::Base.table_name_prefix = "p_"
SchemaMigration.reset_table_name
SchemaMigration.reset_column_information
InternalMetadata.reset_table_name
InternalMetadata.reset_column_information
end
teardown do
ActiveRecord::Base.table_name_prefix = nil
SchemaMigration.reset_table_name
SchemaMigration.reset_column_information
InternalMetadata.reset_table_name
InternalMetadata.reset_column_information
end
end
......@@ -1021,18 +1017,14 @@ class DatabaseTasksTruncateAllWithSuffixTest < DatabaseTasksTruncateAllTest
ActiveRecord::Base.table_name_suffix = "_s"
SchemaMigration.reset_table_name
SchemaMigration.reset_column_information
InternalMetadata.reset_table_name
InternalMetadata.reset_column_information
end
teardown do
ActiveRecord::Base.table_name_suffix = nil
SchemaMigration.reset_table_name
SchemaMigration.reset_column_information
InternalMetadata.reset_table_name
InternalMetadata.reset_column_information
end
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册