@@ -702,7 +702,6 @@ def migrate(x)
702702 ActiveRecord ::Migrator . new ( :up , [ migration ] , @schema_migration , @internal_metadata ) . migrate
703703 assert connection . table_exists? ( long_table_name [ 0 ...-1 ] )
704704 assert_not connection . table_exists? ( :more_testings )
705- assert connection . table_exists? ( long_table_name [ 0 ...-1 ] )
706705 ensure
707706 connection . drop_table ( :more_testings ) rescue nil
708707 connection . drop_table ( long_table_name [ 0 ...-1 ] ) rescue nil
@@ -727,6 +726,28 @@ def migrate(x)
727726 assert_match ( /Index name \' #{ long_index_name } \' on table \' testings\' is too long/i , error . message )
728727 end
729728
729+ # SQL Server truncates long table names when renaming.
730+ coerce_tests! :test_rename_table_errors_on_too_long_index_name_7_0
731+ def test_rename_table_errors_on_too_long_index_name_7_0_coerced
732+ long_table_name = "a" * ( connection . table_name_length + 1 )
733+
734+ migration = Class . new ( ActiveRecord ::Migration [ 7.0 ] ) {
735+ def migrate ( x )
736+ add_index :testings , :foo
737+ long_table_name = "a" * ( connection . table_name_length + 1 )
738+ rename_table :testings , long_table_name
739+ end
740+ } . new
741+
742+ ActiveRecord ::Migrator . new ( :up , [ migration ] , @schema_migration , @internal_metadata ) . migrate
743+
744+ assert_not connection . table_exists? ( :testings )
745+ assert connection . table_exists? ( long_table_name [ 0 ...-1 ] )
746+ assert connection . index_exists? ( long_table_name [ 0 ...-1 ] , :foo )
747+ ensure
748+ connection . drop_table ( long_table_name [ 0 ...-1 ] , if_exists : true )
749+ end
750+
730751 # SQL Server has a different maximum index name length.
731752 coerce_tests! :test_create_table_add_index_errors_on_too_long_name_7_0
732753 def test_create_table_add_index_errors_on_too_long_name_7_0_coerced
0 commit comments