class ActiveRecord::TestCase

:nodoc:
Defines some test assertions to test against SQL queries.
= Active Record Test Case

def assert_date_from_db(expected, actual, message = nil)

def assert_date_from_db(expected, actual, message = nil)
  # SybaseAdapter doesn't have a separate column type just for dates,
  # so the time is in the string and incorrectly formatted
  if current_adapter?(:SybaseAdapter)
    assert_equal expected.to_s, actual.to_date.to_s, message
  else
    assert_equal expected.to_s, actual.to_s, message
  end
end

def assert_no_queries(&block)

def assert_no_queries(&block)
  assert_queries(0, :ignore_none => true, &block)
end

def assert_queries(num = 1, options = {})

def assert_queries(num = 1, options = {})
  ignore_none = options.fetch(:ignore_none) { num == :any }
  SQLCounter.clear_log
  yield
ensure
  the_log = ignore_none ? SQLCounter.log_all : SQLCounter.log
  if num == :any
    assert_operator the_log.size, :>=, 1, "1 or more queries expected, but none were executed."
  else
    mesg = "#{the_log.size} instead of #{num} queries were executed.#{the_log.size == 0 ? '' : "\nQueries:\n#{the_log.join("\n")}"}"
    assert_equal num, the_log.size, mesg
  end
end

def assert_sql(*patterns_to_match)

def assert_sql(*patterns_to_match)
  SQLCounter.clear_log
  yield
  SQLCounter.log_all
ensure
  failed_patterns = []
  patterns_to_match.each do |pattern|
    failed_patterns << pattern unless SQLCounter.log_all.any?{ |sql| pattern === sql }
  end
  assert failed_patterns.empty?, "Query pattern(s) #{failed_patterns.map{ |p| p.inspect }.join(', ')} not found.#{SQLCounter.log.size == 0 ? '' : "\nQueries:\n#{SQLCounter.log.join("\n")}"}"
end

def teardown

:nodoc:
Defines some test assertions to test against SQL queries.

= Active Record Test Case
def teardown
  SQLCounter.clear_log
end