diff options
author | Jan De Poorter <jan@defv.be> | 2008-07-23 12:50:16 +0200 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-07-23 12:02:17 +0100 |
commit | 93e10f9911fb2a096681ee0a0bc82487a9a06c44 (patch) | |
tree | 92bcb41503ea63aeabcd0354da430630cbf3a683 /activerecord/test/cases | |
parent | 2681685450631238511cfc3c2f0fa044c1f8033a (diff) | |
download | rails-93e10f9911fb2a096681ee0a0bc82487a9a06c44.tar.gz rails-93e10f9911fb2a096681ee0a0bc82487a9a06c44.tar.bz2 rails-93e10f9911fb2a096681ee0a0bc82487a9a06c44.zip |
Ensure NamedScope#any? uses COUNT query wherever possible. [#680 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/named_scope_test.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index 0c1eb23428..e21ffbbdba 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -184,6 +184,28 @@ class NamedScopeTest < ActiveRecord::TestCase end end + def test_any_should_not_load_results + topics = Topic.base + assert_queries(1) do + topics.expects(:empty?).returns(true) + assert !topics.any? + end + end + + def test_any_should_call_proxy_found_if_using_a_block + topics = Topic.base + assert_queries(1) do + topics.expects(:empty?).never + topics.any? { true } + end + end + + def test_any_should_not_fire_query_if_named_scope_loaded + topics = Topic.base + topics.collect # force load + assert_no_queries { assert topics.any? } + end + def test_should_build_with_proxy_options topic = Topic.approved.build({}) assert topic.approved |