Skip to content

Commit c8c8a0a

Browse files
committed
Ensure type map queries are counted by assert_queries_count
1 parent a28d2e4 commit c8c8a0a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

activerecord/lib/active_record/testing/query_assertions.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@ module QueryAssertions
1111
# # Check for any number of queries
1212
# assert_queries_count { Post.first }
1313
#
14-
# If the +:include_schema+ option is provided, any queries (including schema related) are counted.
14+
# Any unmaterialized transactions will be materialized to ensure only
15+
# queries attempted intside the block are counted.
16+
#
17+
# If the +:include_schema+ option is provided, any queries (including
18+
# schema related) are counted. Setting this option also skips leasing a
19+
# connection to materialize pending transactions since we want to count
20+
# queries executed at connection open (e.g., type map).
1521
#
1622
# assert_queries_count(1, include_schema: true) { Post.columns }
1723
#
1824
def assert_queries_count(count = nil, include_schema: false, &block)
19-
ActiveRecord::Base.lease_connection.materialize_transactions
25+
ActiveRecord::Base.lease_connection.materialize_transactions unless include_schema
2026

2127
counter = SQLCounter.new
2228
ActiveSupport::Notifications.subscribed(counter, "sql.active_record") do

0 commit comments

Comments
 (0)