aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-06-12 18:50:24 +0100
committerJon Leighton <j@jonathanleighton.com>2011-06-12 18:50:24 +0100
commitc52520166be48299b589dbccd7d1ee22b1095ffb (patch)
tree40fe77cfafd7de58a60ca0b72b5445f3301cada2 /activerecord
parent232c66a1ba3c683655856d277b7227faa37fb8c3 (diff)
downloadrails-c52520166be48299b589dbccd7d1ee22b1095ffb.tar.gz
rails-c52520166be48299b589dbccd7d1ee22b1095ffb.tar.bz2
rails-c52520166be48299b589dbccd7d1ee22b1095ffb.zip
Make assert_no_queries literally enforce that there are no queries. As 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.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/test_case.rb4
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb15
2 files changed, 4 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/test_case.rb b/activerecord/lib/active_record/test_case.rb
index 23e449b67c..ffe9b08dce 100644
--- a/activerecord/lib/active_record/test_case.rb
+++ b/activerecord/lib/active_record/test_case.rb
@@ -50,7 +50,11 @@ module ActiveRecord
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)
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index e16a573a1f..9af1f7249f 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -550,15 +550,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
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 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
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 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
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