From 22ed92dbae24481b951ef5f4926c85af8f101b6b Mon Sep 17 00:00:00 2001 From: Dieter Komendera Date: Sun, 18 Nov 2012 12:16:00 +0100 Subject: Add test to ensure preloading works as expected with "select" and "includes". This didn't work in rails 3.1. See #2303 for more information and original pull request. --- activerecord/test/cases/relations_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index bc6cac0c6c..9d2229e733 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1438,4 +1438,17 @@ class RelationTest < ActiveRecord::TestCase 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 -- cgit v1.2.3