Skip to content

Commit

Permalink
Coerce test (#1235)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanharan authored Oct 2, 2024
1 parent 3f87305 commit 0ade39b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0ade39b

Please sign in to comment.