Permalink
Browse files

Make assert_no_queries literally enforce that there are no queries. A…

…s in, not a single line of SQL should be sent to the database, not even stuff that is ignored by assert_queries. The argument being that if you write assert_no_queries, you really do not want there to be any queries.
  • Loading branch information...
jonleighton committed Jun 12, 2011
1 parent 232c66a commit c52520166be48299b589dbccd7d1ee22b1095ffb
@@ -50,7 +50,11 @@ def assert_queries(num = 1)
end
def assert_no_queries(&block)
+ prev_ignored_sql = ActiveRecord::SQLCounter.ignored_sql
+ ActiveRecord::SQLCounter.ignored_sql = []
assert_queries(0, &block)
+ ensure
+ ActiveRecord::SQLCounter.ignored_sql = prev_ignored_sql
end
def with_kcode(kcode)
@@ -550,15 +550,10 @@ def test_transactions_when_adding_to_persisted
end
def test_transactions_when_adding_to_new_record
- prev_ignored_sql = ActiveRecord::SQLCounter.ignored_sql
- ActiveRecord::SQLCounter.ignored_sql = []
-
assert_no_queries do
firm = Firm.new
firm.clients_of_firm.concat(Client.new("name" => "Natural Company"))
end
- ensure
- ActiveRecord::SQLCounter.ignored_sql = prev_ignored_sql
end
def test_new_aliased_to_build
@@ -817,17 +812,12 @@ def test_transaction_when_deleting_persisted
end
def test_transaction_when_deleting_new_record
- prev_ignored_sql = ActiveRecord::SQLCounter.ignored_sql
- ActiveRecord::SQLCounter.ignored_sql = []
-
assert_no_queries do
firm = Firm.new
client = Client.new("name" => "New Client")
firm.clients_of_firm << client
firm.clients_of_firm.destroy(client)
end
- ensure
- ActiveRecord::SQLCounter.ignored_sql = prev_ignored_sql
end
def test_clearing_an_association_collection
@@ -1178,15 +1168,10 @@ def test_transactions_when_replacing_on_persisted
end
def test_transactions_when_replacing_on_new_record
- prev_ignored_sql = ActiveRecord::SQLCounter.ignored_sql
- ActiveRecord::SQLCounter.ignored_sql = []
-
assert_no_queries do
firm = Firm.new
firm.clients_of_firm = [Client.new("name" => "New Client")]
end
- ensure
- ActiveRecord::SQLCounter.ignored_sql = prev_ignored_sql
end
def test_get_ids

0 comments on commit c525201

Please sign in to comment.