aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-11-18 10:17:15 -0800
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-11-18 10:17:15 -0800
commit5e7919cd63fdc09403ed0dcadbc1c18c5f1fa881 (patch)
tree8dd9deb7584fdf17720abcdeec135b18017fdb98
parent5a3e258370ebebf5377897703ad9625de72cbcf8 (diff)
parent22ed92dbae24481b951ef5f4926c85af8f101b6b (diff)
downloadrails-5e7919cd63fdc09403ed0dcadbc1c18c5f1fa881.tar.gz
rails-5e7919cd63fdc09403ed0dcadbc1c18c5f1fa881.tar.bz2
rails-5e7919cd63fdc09403ed0dcadbc1c18c5f1fa881.zip
Merge pull request #8258 from kommen/eager_loading_with_select_test2
Add test to ensure preloading works as expected with "group", "select" and "includes".
-rw-r--r--activerecord/test/cases/relations_test.rb13
1 files changed, 13 insertions, 0 deletions
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