aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-03-16 07:37:13 -0700
committerJosé Valim <jose.valim@gmail.com>2012-03-16 07:37:13 -0700
commit8d87d5c94708c2d93010083f97244748f96bb9dc (patch)
tree146b49ad042fc7dcd74434e5717d2e9c19bb16e6
parent5245eb30b144380d9c8c48538a978fb8facb71c0 (diff)
parent964ed6e802018005f6ffc9a95d13dea68f26fdb7 (diff)
downloadrails-8d87d5c94708c2d93010083f97244748f96bb9dc.tar.gz
rails-8d87d5c94708c2d93010083f97244748f96bb9dc.tar.bz2
rails-8d87d5c94708c2d93010083f97244748f96bb9dc.zip
Merge pull request #5469 from yakko/master
tests for Relation .present? .blank?
-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