method

assert_sql

Importance_0
v3.2.1 - Show latest stable - 0 notes - Class: ActiveRecord::TestCase
assert_sql(*patterns_to_match) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/test_case.rb, line 33
    def assert_sql(*patterns_to_match)
      ActiveRecord::SQLCounter.log = []
      yield
      ActiveRecord::SQLCounter.log
    ensure
      failed_patterns = []
      patterns_to_match.each do |pattern|
        failed_patterns << pattern unless ActiveRecord::SQLCounter.log.any?{ |sql| pattern === sql }
      end
      assert failed_patterns.empty?, "Query pattern(s) #{failed_patterns.map{ |p| p.inspect }.join(', ')} not found.#{ActiveRecord::SQLCounter.log.size == 0 ? '' : "\nQueries:\n#{ActiveRecord::SQLCounter.log.join("\n")}"}"
    end
Register or log in to add new notes.