method

assert_queries_count

rails latest stable - Class: ActiveRecord::Assertions::QueryAssertions

Method not available on this version

This method is only available on newer versions. The first available version (v7.2.3) is shown here.

assert_queries_count(count = nil, include_schema: false, &block)
public

Asserts that the number of SQL queries executed in the given block matches the expected count.

# Check for exact number of queries
assert_queries_count(1) { Post.first }

# Check for any number of queries
assert_queries_count { Post.first }

If the :include_schema option is provided, any queries (including schema related) are counted.

assert_queries_count(1, include_schema: true) { Post.columns }