diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-11-18 10:17:15 -0800 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-11-19 20:28:33 -0200 |
commit | 0077b414db35069b95ef73e51b0c41f29a204721 (patch) | |
tree | d1a212b51352574f7acdb9fe53cb2ffdea6cb93d /activerecord/test/cases/relations_test.rb | |
parent | db6765220de3e0d6334cf6a6f8ac86ea43c48bd2 (diff) | |
download | rails-0077b414db35069b95ef73e51b0c41f29a204721.tar.gz rails-0077b414db35069b95ef73e51b0c41f29a204721.tar.bz2 rails-0077b414db35069b95ef73e51b0c41f29a204721.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".
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
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 14 |
1 files changed, 14 insertions, 0 deletions
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 |