mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure reset_table_name
when table name prefix/suffix is changed
Also, `reset_column_information` is unnecessary since `reset_table_name` does that too.
This commit is contained in:
parent
9d02b1bd58
commit
2ca056be6f
4 changed files with 15 additions and 17 deletions
|
@ -22,23 +22,26 @@ class PostgresqlExtensionMigrationTest < ActiveRecord::PostgreSQLTestCase
|
|||
|
||||
@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 @@ class ActiveRecordSchemaTest < ActiveRecord::TestCase
|
|||
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 @@ class ActiveRecordSchemaTest < ActiveRecord::TestCase
|
|||
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 @@ class MigrationTest < ActiveRecord::TestCase
|
|||
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 @@ class MigrationTest < ActiveRecord::TestCase
|
|||
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 @@ module ActiveRecord
|
|||
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 @@ module ActiveRecord
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue