Skip to content
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
60 changes: 60 additions & 0 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,56 @@ def test_value_limit_violations_are_translated_to_specific_exception_coerced
end
end

module ActiveRecord
class AdapterTestWithoutTransaction < ActiveRecord::TestCase
# SQL Server does not allow truncation of tables that are referenced by foreign key
# constraints. So manually remove/add foreign keys in test.
coerce_tests! :test_truncate_tables, :test_truncate_tables_with_query_cache
def test_truncate_tables_coerced
# Remove foreign key constraint to allow truncation.
@connection.remove_foreign_key :authors, :author_addresses

assert_operator Post.count, :>, 0
assert_operator Author.count, :>, 0
assert_operator AuthorAddress.count, :>, 0

@connection.truncate_tables("author_addresses", "authors", "posts")

assert_equal 0, Post.count
assert_equal 0, Author.count
assert_equal 0, AuthorAddress.count
ensure
reset_fixtures("posts", "authors", "author_addresses")

# Restore foreign key constraint.
@connection.add_foreign_key :authors, :author_addresses
end

def test_truncate_tables_with_query_cache
# Remove foreign key constraint to allow truncation.
@connection.remove_foreign_key :authors, :author_addresses

@connection.enable_query_cache!

assert_operator Post.count, :>, 0
assert_operator Author.count, :>, 0
assert_operator AuthorAddress.count, :>, 0

@connection.truncate_tables("author_addresses", "authors", "posts")

assert_equal 0, Post.count
assert_equal 0, Author.count
assert_equal 0, AuthorAddress.count
ensure
reset_fixtures("posts", "authors", "author_addresses")
@connection.disable_query_cache!

# Restore foreign key constraint.
@connection.add_foreign_key :authors, :author_addresses
end
end
end




Expand Down Expand Up @@ -1181,3 +1231,13 @@ class EagerLoadingTooManyIdsTest < ActiveRecord::TestCase
# Temporarily coerce this test due to https://github.com/rails/rails/issues/34945
coerce_tests! :test_eager_loading_too_may_ids
end


module ActiveRecord
class DatabaseTasksTruncateAllTest < ActiveRecord::TestCase
# SQL Server does not allow truncation of tables that are referenced by foreign key
# constraints. As this test truncates all tables we would need to remove all foreign
# key constraints and then restore them afterwards to get this test to pass.
coerce_tests! :test_truncate_tables
end
end