aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDieter Komendera <dieter@komendera.com>2012-11-18 12:16:00 +0100
committerDieter Komendera <dieter@komendera.com>2012-11-18 13:17:11 +0100
commit22ed92dbae24481b951ef5f4926c85af8f101b6b (patch)
treeeaf2c6e5d8082b0fd5976abc1afb3c1b85ee8026
parentaff1872a87e0227c99f1902ed1dc317e97bd58d3 (diff)
downloadrails-22ed92dbae24481b951ef5f4926c85af8f101b6b.tar.gz
rails-22ed92dbae24481b951ef5f4926c85af8f101b6b.tar.bz2
rails-22ed92dbae24481b951ef5f4926c85af8f101b6b.zip
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.
-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