Permalink
Browse files

Add test to ensure preloading works as expected with "select" and "in…

…cludes".

This didn't work in rails 3.1. See #2303 for more information and original pull request.
  • Loading branch information...
1 parent aff1872 commit 22ed92dbae24481b951ef5f4926c85af8f101b6b @kommen kommen committed Nov 18, 2012
Showing with 13 additions and 0 deletions.
  1. +13 −0 activerecord/test/cases/relations_test.rb
View
13 activerecord/test/cases/relations_test.rb
@@ -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

0 comments on commit 22ed92d

Please sign in to comment.