diff options
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index ac586e2a63..680e1d50cf 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -673,6 +673,32 @@ class RelationTest < ActiveRecord::TestCase assert_equal expected, posts.count end + def test_empty + posts = Post.scoped + + assert_queries(1) { assert_equal false, posts.empty? } + assert ! posts.loaded? + + no_posts = posts.where(:title => "") + assert_queries(1) { assert_equal true, no_posts.empty? } + assert ! no_posts.loaded? + + best_posts = posts.where(:comments_count => 0) + best_posts.to_a # force load + assert_no_queries { assert_equal false, best_posts.empty? } + end + + def test_empty_complex_chained_relations + posts = Post.select("comments_count").where("id is not null").group("author_id").where("comments_count > 0") + + assert_queries(1) { assert_equal false, posts.empty? } + assert ! posts.loaded? + + no_posts = posts.where(:title => "") + assert_queries(1) { assert_equal true, no_posts.empty? } + assert ! no_posts.loaded? + end + def test_any posts = Post.scoped |