Skip to content
Browse files

Merge pull request #5469 from yakko/master

tests for Relation .present? .blank?
  • Loading branch information...
2 parents 5245eb3 + 964ed6e commit 8d87d5c94708c2d93010083f97244748f96bb9dc @josevalim josevalim committed Mar 16, 2012
Showing with 19 additions and 0 deletions.
  1. +19 −0 activerecord/test/cases/relations_test.rb
View
19 activerecord/test/cases/relations_test.rb
@@ -1234,4 +1234,23 @@ def test_automatically_added_order_references
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

0 comments on commit 8d87d5c

Please sign in to comment.
Something went wrong with that request. Please try again.