aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/relations_test.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 91bc407d42..515f0b9d04 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -1234,4 +1234,23 @@ class RelationTest < ActiveRecord::TestCase
scope = Post.order('foo(comments.body)')
assert_equal [], scope.references_values
end
+
+ 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
+
+ assert topics.loaded?
+ end
end