Permalink
Browse files

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 a739340:
Ensure ordering to make the test pass with postgresql

Conflicts:
	activerecord/test/cases/relations_test.rb
  • Loading branch information...
1 parent db67652 commit 0077b414db35069b95ef73e51b0c41f29a204721 @carlosantoniodasilva committed Nov 18, 2012
Showing with 14 additions and 0 deletions.
  1. +14 −0 activerecord/test/cases/relations_test.rb
@@ -1185,4 +1185,18 @@ def test_uniq
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

0 comments on commit 0077b41

Please sign in to comment.