diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 515f0b9d04992046a3900e20ded07f3974965a12..63d47f5162cc5236b3b3bc1ab6021973aa681fc6 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1238,18 +1238,21 @@ def test_automatically_added_order_references def test_presence topics = Topic.scoped - assert_queries(1) do - #checking if there are topics is used before you actually display them, - #thus it shouldn't invoke an extra count query - assert topics.present? - assert !topics.blank? - - #shows count of topics and loops after loading the query should not trigger extra queries either - assert_no_queries { topics.size } - assert_no_queries { topics.count } - assert_no_queries { topics.length } - assert_no_queries { topics.each } - end + # the fist query is triggered because there are no topics yet. + assert_queries(1) { assert topics.present? } + + # checking if there are topics is used before you actually display them, + # thus it shouldn't invoke an extra count query. + assert_no_queries { assert topics.present? } + assert_no_queries { assert !topics.blank? } + + # shows count of topics and loops after loading the query should not trigger extra queries either. + assert_no_queries { topics.size } + assert_no_queries { topics.length } + assert_no_queries { topics.each } + + # count always trigger the COUNT query. + assert_queries(1) { topics.count } assert topics.loaded? end