Skip to content

Coerce test #1235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading