rails/rails — pull request #6683 by stevecj (2012-06-08 18:41:00+00:00)
Title: Fix fragile #assert_queries implementation and usages.

Several tests that passed when run in the order they are loaded by rake test were failing when run in different sequences due to problems with the implementation of #assert_queries and #assert_no_queries as well as incorrect assumptions made about how many queries might be executed by a database adapter in various cases.

#assert_no_queries was simply broken (but happened to not fail in `rake test` because of caching, etc.) because it tried to temporarily change SQLCounter.ignored_sql, but at that point, the instance of SQLCounter was already using a regular expression built from the original value of SQLCounter.ignored_sql.

Ignoring SQL was also not really working with mysql or postgresql either, because not all of the necessary SQL was being ignored for those adapters.

Some tests were trying to avoid counting metadata queries by invoking .columns, but this was unreliable. Needed to depend on SQL-ignoring instead.

Some tests thought they knew exactly how many queries the connection adapter would perform in order to retrieve metadata, but the assumptions were unwarranted. Needed to assert >=1 queries vs no queries around specific statements instead.