Skip to content

Commit b6f48af

Browse files
authored
Updated test cases relying on capture_sql (#1165)
1 parent 0569c31 commit b6f48af

File tree

3 files changed

+4
-48
lines changed

3 files changed

+4
-48
lines changed

test/cases/coerced_tests.rb

+4-32
Original file line numberDiff line numberDiff line change
@@ -473,15 +473,15 @@ def test_select_avg_with_joins_and_group_by_as_virtual_attribute_with_ar_coerced
473473
# Match SQL Server limit implementation
474474
coerce_tests! :test_limit_is_kept
475475
def test_limit_is_kept_coerced
476-
queries = capture_sql_ss { Account.limit(1).count }
476+
queries = capture_sql { Account.limit(1).count }
477477
assert_equal 1, queries.length
478478
assert_match(/ORDER BY \[accounts\]\.\[id\] ASC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.*@0 = 1/, queries.first)
479479
end
480480

481481
# Match SQL Server limit implementation
482482
coerce_tests! :test_limit_with_offset_is_kept
483483
def test_limit_with_offset_is_kept_coerced
484-
queries = capture_sql_ss { Account.limit(1).offset(1).count }
484+
queries = capture_sql { Account.limit(1).offset(1).count }
485485
assert_equal 1, queries.length
486486
assert_match(/ORDER BY \[accounts\]\.\[id\] ASC OFFSET @0 ROWS FETCH NEXT @1 ROWS ONLY.*@0 = 1, @1 = 1/, queries.first)
487487
end
@@ -1337,30 +1337,6 @@ def test_cache_does_not_wrap_results_in_arrays_coerced
13371337
assert_equal 2, Task.lease_connection.select_value("SELECT count(*) AS count_all FROM tasks")
13381338
end
13391339
end
1340-
1341-
# Same as original test except that we expect one query to be performed to retrieve the table's primary key
1342-
# and we don't call `reload_type_map` because SQL Server adapter doesn't support it.
1343-
# When we generate the SQL for the `find` it includes ordering on the primary key. If we reset the column
1344-
# information then the primary key needs to be retrieved from the database again to generate the SQL causing the
1345-
# original test's `assert_no_queries` assertion to fail. Assert that the query was to get the primary key.
1346-
coerce_tests! :test_query_cached_even_when_types_are_reset
1347-
def test_query_cached_even_when_types_are_reset_coerced
1348-
Task.cache do
1349-
# Warm the cache
1350-
Task.find(1)
1351-
1352-
# Clear places where type information is cached
1353-
Task.reset_column_information
1354-
Task.initialize_find_by_cache
1355-
Task.define_attribute_methods
1356-
1357-
assert_queries_count(1, include_schema: true) do
1358-
Task.find(1)
1359-
end
1360-
1361-
assert_includes ActiveRecord::SQLCounter.log_all.first, "TC.CONSTRAINT_TYPE = N''PRIMARY KEY''"
1362-
end
1363-
end
13641340
end
13651341

13661342
require "models/post"
@@ -1648,7 +1624,7 @@ def test_releasing_named_savepoints_coerced
16481624
def test_nested_transactions_after_disable_lazy_transactions_coerced
16491625
Topic.lease_connection.disable_lazy_transactions!
16501626

1651-
capture_sql do
1627+
actual_queries = capture_sql(include_schema: true) do
16521628
# RealTransaction (begin..commit)
16531629
Topic.transaction(requires_new: true) do
16541630
# ResetParentTransaction (no queries)
@@ -1666,8 +1642,6 @@ def test_nested_transactions_after_disable_lazy_transactions_coerced
16661642
end
16671643
end
16681644

1669-
actual_queries = ActiveRecord::SQLCounter.log_all
1670-
16711645
expected_queries = [
16721646
/BEGIN/i,
16731647
/DELETE/i,
@@ -1685,7 +1659,7 @@ def test_nested_transactions_after_disable_lazy_transactions_coerced
16851659
# SQL Server does not have query for release_savepoint.
16861660
coerce_tests! :test_nested_transactions_skip_excess_savepoints
16871661
def test_nested_transactions_skip_excess_savepoints_coerced
1688-
capture_sql do
1662+
actual_queries = capture_sql(include_schema: true) do
16891663
# RealTransaction (begin..commit)
16901664
Topic.transaction(requires_new: true) do
16911665
# ResetParentTransaction (no queries)
@@ -1703,8 +1677,6 @@ def test_nested_transactions_skip_excess_savepoints_coerced
17031677
end
17041678
end
17051679

1706-
actual_queries = ActiveRecord::SQLCounter.log_all
1707-
17081680
expected_queries = [
17091681
/BEGIN/i,
17101682
/DELETE/i,

test/cases/helper_sqlserver.rb

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
require "cases/helper"
1111
require "support/load_schema_sqlserver"
1212
require "support/coerceable_test_sqlserver"
13-
require "support/sql_counter_sqlserver"
1413
require "support/connection_reflection"
1514
require "mocha/minitest"
1615

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

2120
include ARTest::SQLServer::CoerceableTest,
2221
ARTest::SQLServer::ConnectionReflection,
23-
ARTest::SQLServer::SqlCounterSqlserver,
2422
ActiveSupport::Testing::Stream
2523

2624
let(:logger) { ActiveRecord::Base.logger }

test/support/sql_counter_sqlserver.rb

-14
This file was deleted.

0 commit comments

Comments
 (0)