From 0077b414db35069b95ef73e51b0c41f29a204721 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sun, 18 Nov 2012 10:17:15 -0800 Subject: Merge pull request #8258 from kommen/eager_loading_with_select_test2 Add test to ensure preloading works as expected with "group", "select" and "includes". Conflicts: activerecord/test/cases/relations_test.rb Chery-pick a739340d3c9e66814429af6f3f410c01ff86810a: Ensure ordering to make the test pass with postgresql Conflicts: activerecord/test/cases/relations_test.rb --- activerecord/test/cases/relations_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'activerecord') diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index b24df47efd..ada4294401 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1185,4 +1185,18 @@ class RelationTest < ActiveRecord::TestCase end assert_equal ['Foo', 'Foo'], query.uniq(true).uniq(false).map(&:name) end + + test 'group with select and includes' do + authors_count = Post.select('author_id, COUNT(author_id) AS num_posts'). + group('author_id').order('author_id').includes(:author).to_a + + assert_no_queries do + result = authors_count.map do |post| + [post.num_posts.to_i, 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