Add test to ensure preloading works as expected with "group", "select" and "includes". #8258

Merged
merged 1 commit into from Nov 18, 2012
Jump to file or symbol
Failed to load files and symbols.
+13 鈭0
Diff settings

Always

Just for now

@@ -1438,4 +1438,17 @@ def test_presence
end
assert_no_queries { relation.to_a }
end
+
+ test 'group with select and includes' do
+ authors_count = Post.select('author_id, COUNT(author_id) AS num_posts').group('author_id').includes(:author).to_a
+
+ assert_no_queries do
+ result = authors_count.map do |post|
+ [post.num_posts, post.author.try(:name)]
+ end
+
+ expected = [[1, nil], [5, "David"], [3, "Mary"], [2, "Bob"]]
+ assert_equal expected, result
+ end
+ end
end