Skip to content

Commit 4498f93

Browse files
committed
tests for Relation .present? and .blank? are check cases and shouldn't force sql-count
1 parent 9d52b45 commit 4498f93

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

activerecord/test/cases/relations_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,4 +1234,23 @@ def test_automatically_added_order_references
12341234
scope = Post.order('foo(comments.body)')
12351235
assert_equal [], scope.references_values
12361236
end
1237+
1238+
def test_presence
1239+
topics = Topic.scoped
1240+
1241+
assert_queries(1) do
1242+
#checking if there are topics is used before you actually display them,
1243+
#thus it shouldn't invoke an extra count query
1244+
assert topics.present?
1245+
assert !topics.blank?
1246+
1247+
#shows count of topics and loops after loading the query should not trigger extra queries either
1248+
assert_no_queries topics.size
1249+
assert_no_queries topics.count
1250+
assert_no_queries topics.length
1251+
assert_no_queries topics.each
1252+
end
1253+
1254+
assert topics.loaded?
1255+
end
12371256
end

0 commit comments

Comments
 (0)