Skip to content

Commit 2ca056b

Browse files
committed
Ensure reset_table_name when table name prefix/suffix is changed
Also, `reset_column_information` is unnecessary since `reset_table_name` does that too.
1 parent 9d02b1b commit 2ca056b

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

activerecord/test/cases/adapters/postgresql/extension_migration_test.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,26 @@ def setup
2222

2323
@connection = ActiveRecord::Base.connection
2424

25-
@old_schema_migration_table_name = ActiveRecord::SchemaMigration.table_name
2625
@old_table_name_prefix = ActiveRecord::Base.table_name_prefix
2726
@old_table_name_suffix = ActiveRecord::Base.table_name_suffix
2827

2928
ActiveRecord::Base.table_name_prefix = "p_"
3029
ActiveRecord::Base.table_name_suffix = "_s"
30+
ActiveRecord::SchemaMigration.reset_table_name
31+
ActiveRecord::InternalMetadata.reset_table_name
32+
3133
ActiveRecord::SchemaMigration.delete_all rescue nil
32-
ActiveRecord::SchemaMigration.table_name = "p_schema_migrations_s"
3334
ActiveRecord::Migration.verbose = false
3435
end
3536

3637
def teardown
37-
ActiveRecord::Base.table_name_prefix = @old_table_name_prefix
38-
ActiveRecord::Base.table_name_suffix = @old_table_name_suffix
3938
ActiveRecord::SchemaMigration.delete_all rescue nil
4039
ActiveRecord::Migration.verbose = true
41-
ActiveRecord::SchemaMigration.table_name = @old_schema_migration_table_name
40+
41+
ActiveRecord::Base.table_name_prefix = @old_table_name_prefix
42+
ActiveRecord::Base.table_name_suffix = @old_table_name_suffix
43+
ActiveRecord::SchemaMigration.reset_table_name
44+
ActiveRecord::InternalMetadata.reset_table_name
4245

4346
super
4447
end

activerecord/test/cases/ar_schema_test.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ def test_schema_define
5151
assert_equal 7, @connection.migration_context.current_version
5252
end
5353

54-
def test_schema_define_w_table_name_prefix
55-
table_name = ActiveRecord::SchemaMigration.table_name
54+
def test_schema_define_with_table_name_prefix
5655
old_table_name_prefix = ActiveRecord::Base.table_name_prefix
5756
ActiveRecord::Base.table_name_prefix = "nep_"
58-
ActiveRecord::SchemaMigration.table_name = "nep_#{table_name}"
57+
ActiveRecord::SchemaMigration.reset_table_name
58+
ActiveRecord::InternalMetadata.reset_table_name
5959
ActiveRecord::Schema.define(version: 7) do
6060
create_table :fruits do |t|
6161
t.column :color, :string
@@ -67,7 +67,8 @@ def test_schema_define_w_table_name_prefix
6767
assert_equal 7, @connection.migration_context.current_version
6868
ensure
6969
ActiveRecord::Base.table_name_prefix = old_table_name_prefix
70-
ActiveRecord::SchemaMigration.table_name = table_name
70+
ActiveRecord::SchemaMigration.reset_table_name
71+
ActiveRecord::InternalMetadata.reset_table_name
7172
end
7273

7374
def test_schema_raises_an_error_for_invalid_column_type

activerecord/test/cases/migration_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ def test_schema_migrations_table_name
385385
assert_equal "changed", ActiveRecord::SchemaMigration.table_name
386386
ensure
387387
ActiveRecord::Base.schema_migrations_table_name = original_schema_migrations_table_name
388+
ActiveRecord::SchemaMigration.reset_table_name
388389
Reminder.reset_table_name
389390
end
390391

@@ -405,6 +406,7 @@ def test_internal_metadata_table_name
405406
assert_equal "changed", ActiveRecord::InternalMetadata.table_name
406407
ensure
407408
ActiveRecord::Base.internal_metadata_table_name = original_internal_metadata_table_name
409+
ActiveRecord::InternalMetadata.reset_table_name
408410
Reminder.reset_table_name
409411
end
410412

activerecord/test/cases/tasks/database_tasks_test.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,18 +1001,14 @@ class DatabaseTasksTruncateAllWithPrefixTest < DatabaseTasksTruncateAllTest
10011001
ActiveRecord::Base.table_name_prefix = "p_"
10021002

10031003
SchemaMigration.reset_table_name
1004-
SchemaMigration.reset_column_information
10051004
InternalMetadata.reset_table_name
1006-
InternalMetadata.reset_column_information
10071005
end
10081006

10091007
teardown do
10101008
ActiveRecord::Base.table_name_prefix = nil
10111009

10121010
SchemaMigration.reset_table_name
1013-
SchemaMigration.reset_column_information
10141011
InternalMetadata.reset_table_name
1015-
InternalMetadata.reset_column_information
10161012
end
10171013
end
10181014

@@ -1021,18 +1017,14 @@ class DatabaseTasksTruncateAllWithSuffixTest < DatabaseTasksTruncateAllTest
10211017
ActiveRecord::Base.table_name_suffix = "_s"
10221018

10231019
SchemaMigration.reset_table_name
1024-
SchemaMigration.reset_column_information
10251020
InternalMetadata.reset_table_name
1026-
InternalMetadata.reset_column_information
10271021
end
10281022

10291023
teardown do
10301024
ActiveRecord::Base.table_name_suffix = nil
10311025

10321026
SchemaMigration.reset_table_name
1033-
SchemaMigration.reset_column_information
10341027
InternalMetadata.reset_table_name
1035-
InternalMetadata.reset_column_information
10361028
end
10371029
end
10381030
end

0 commit comments

Comments
 (0)