From 5ab20b87bed71b3bfc59cdf1e1148c9cac543cf2 Mon Sep 17 00:00:00 2001 From: Aidan Haran Date: Wed, 2 Oct 2024 10:40:08 +0100 Subject: [PATCH 1/2] Coerce test --- test/cases/coerced_tests.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/cases/coerced_tests.rb b/test/cases/coerced_tests.rb index 3dd00ba38..796b2c4c3 100644 --- a/test/cases/coerced_tests.rb +++ b/test/cases/coerced_tests.rb @@ -702,7 +702,6 @@ def migrate(x) ActiveRecord::Migrator.new(:up, [migration], @schema_migration, @internal_metadata).migrate assert connection.table_exists?(long_table_name[0...-1]) assert_not connection.table_exists?(:more_testings) - assert connection.table_exists?(long_table_name[0...-1]) ensure connection.drop_table(:more_testings) rescue nil connection.drop_table(long_table_name[0...-1]) rescue nil @@ -727,6 +726,28 @@ def migrate(x) assert_match(/Index name \'#{long_index_name}\' on table \'testings\' is too long/i, error.message) end + # SQL Server truncates long table names when renaming. + coerce_tests! test_rename_table_errors_on_too_long_index_name_7_0 + def test_rename_table_errors_on_too_long_index_name_7_0_coerced + long_table_name = "a" * (connection.table_name_length + 1) + + migration = Class.new(ActiveRecord::Migration[7.0]) { + def migrate(x) + add_index :testings, :foo + long_table_name = "a" * (connection.table_name_length + 1) + rename_table :testings, long_table_name + end + }.new + + ActiveRecord::Migrator.new(:up, [migration], @schema_migration, @internal_metadata).migrate + + assert_not connection.table_exists?(:testings) + assert connection.table_exists?(long_table_name[0...-1]) + assert connection.index_exists?(long_table_name[0...-1], :foo) + ensure + connection.drop_table(long_table_name[0...-1], if_exists: true) + end + # SQL Server has a different maximum index name length. coerce_tests! :test_create_table_add_index_errors_on_too_long_name_7_0 def test_create_table_add_index_errors_on_too_long_name_7_0_coerced From 92d2c12f58166e8b1c125667b73139a1e0aaeb12 Mon Sep 17 00:00:00 2001 From: Aidan Haran Date: Wed, 2 Oct 2024 10:46:19 +0100 Subject: [PATCH 2/2] Update coerced_tests.rb --- test/cases/coerced_tests.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cases/coerced_tests.rb b/test/cases/coerced_tests.rb index 796b2c4c3..78b65c52a 100644 --- a/test/cases/coerced_tests.rb +++ b/test/cases/coerced_tests.rb @@ -727,7 +727,7 @@ def migrate(x) end # SQL Server truncates long table names when renaming. - coerce_tests! test_rename_table_errors_on_too_long_index_name_7_0 + coerce_tests! :test_rename_table_errors_on_too_long_index_name_7_0 def test_rename_table_errors_on_too_long_index_name_7_0_coerced long_table_name = "a" * (connection.table_name_length + 1)