Skip to content

Updated test cases relying on capture_sql #1165

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 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
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
36 changes: 4 additions & 32 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,15 @@ def test_select_avg_with_joins_and_group_by_as_virtual_attribute_with_ar_coerced
# Match SQL Server limit implementation
coerce_tests! :test_limit_is_kept
def test_limit_is_kept_coerced
queries = capture_sql_ss { Account.limit(1).count }
queries = capture_sql { Account.limit(1).count }
assert_equal 1, queries.length
assert_match(/ORDER BY \[accounts\]\.\[id\] ASC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.*@0 = 1/, queries.first)
end

# Match SQL Server limit implementation
coerce_tests! :test_limit_with_offset_is_kept
def test_limit_with_offset_is_kept_coerced
queries = capture_sql_ss { Account.limit(1).offset(1).count }
queries = capture_sql { Account.limit(1).offset(1).count }
assert_equal 1, queries.length
assert_match(/ORDER BY \[accounts\]\.\[id\] ASC OFFSET @0 ROWS FETCH NEXT @1 ROWS ONLY.*@0 = 1, @1 = 1/, queries.first)
end
Expand Down Expand Up @@ -1337,30 +1337,6 @@ def test_cache_does_not_wrap_results_in_arrays_coerced
assert_equal 2, Task.lease_connection.select_value("SELECT count(*) AS count_all FROM tasks")
end
end

# Same as original test except that we expect one query to be performed to retrieve the table's primary key
# and we don't call `reload_type_map` because SQL Server adapter doesn't support it.
# When we generate the SQL for the `find` it includes ordering on the primary key. If we reset the column
# information then the primary key needs to be retrieved from the database again to generate the SQL causing the
# original test's `assert_no_queries` assertion to fail. Assert that the query was to get the primary key.
coerce_tests! :test_query_cached_even_when_types_are_reset
def test_query_cached_even_when_types_are_reset_coerced
Task.cache do
# Warm the cache
Task.find(1)

# Clear places where type information is cached
Task.reset_column_information
Task.initialize_find_by_cache
Task.define_attribute_methods

assert_queries_count(1, include_schema: true) do
Task.find(1)
end

assert_includes ActiveRecord::SQLCounter.log_all.first, "TC.CONSTRAINT_TYPE = N''PRIMARY KEY''"
end
end
end

require "models/post"
Expand Down Expand Up @@ -1648,7 +1624,7 @@ def test_releasing_named_savepoints_coerced
def test_nested_transactions_after_disable_lazy_transactions_coerced
Topic.lease_connection.disable_lazy_transactions!

capture_sql do
actual_queries = capture_sql(include_schema: true) do
# RealTransaction (begin..commit)
Topic.transaction(requires_new: true) do
# ResetParentTransaction (no queries)
Expand All @@ -1666,8 +1642,6 @@ def test_nested_transactions_after_disable_lazy_transactions_coerced
end
end

actual_queries = ActiveRecord::SQLCounter.log_all

expected_queries = [
/BEGIN/i,
/DELETE/i,
Expand All @@ -1685,7 +1659,7 @@ def test_nested_transactions_after_disable_lazy_transactions_coerced
# SQL Server does not have query for release_savepoint.
coerce_tests! :test_nested_transactions_skip_excess_savepoints
def test_nested_transactions_skip_excess_savepoints_coerced
capture_sql do
actual_queries = capture_sql(include_schema: true) do
# RealTransaction (begin..commit)
Topic.transaction(requires_new: true) do
# ResetParentTransaction (no queries)
Expand All @@ -1703,8 +1677,6 @@ def test_nested_transactions_skip_excess_savepoints_coerced
end
end

actual_queries = ActiveRecord::SQLCounter.log_all

expected_queries = [
/BEGIN/i,
/DELETE/i,
Expand Down
2 changes: 0 additions & 2 deletions test/cases/helper_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
require "cases/helper"
require "support/load_schema_sqlserver"
require "support/coerceable_test_sqlserver"
require "support/sql_counter_sqlserver"
require "support/connection_reflection"
require "mocha/minitest"

Expand All @@ -20,7 +19,6 @@ class TestCase < ActiveSupport::TestCase

include ARTest::SQLServer::CoerceableTest,
ARTest::SQLServer::ConnectionReflection,
ARTest::SQLServer::SqlCounterSqlserver,
ActiveSupport::Testing::Stream

let(:logger) { ActiveRecord::Base.logger }
Expand Down
14 changes: 0 additions & 14 deletions test/support/sql_counter_sqlserver.rb

This file was deleted.

Loading