diff options
author | Thiago Almeida <tapgyn@gmail.com> | 2012-03-16 11:04:24 -0300 |
---|---|---|
committer | Thiago Almeida <tapgyn@gmail.com> | 2012-03-16 11:04:24 -0300 |
commit | 4498f93e68bfdc0a02285f683b0c7cdc016f5898 (patch) | |
tree | f435650b95d635a2889eb69623000796690fa649 /activerecord | |
parent | 9d52b45a5b8ccf8744c1b05d70bd00831cb87526 (diff) | |
download | rails-4498f93e68bfdc0a02285f683b0c7cdc016f5898.tar.gz rails-4498f93e68bfdc0a02285f683b0c7cdc016f5898.tar.bz2 rails-4498f93e68bfdc0a02285f683b0c7cdc016f5898.zip |
tests for Relation .present? and .blank? are check cases and shouldn't force sql-count
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 19 |
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..bbd06a1c2c 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 |