Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add test to ensure preloading works as expected with "group", "select" and "includes". #8258

Merged
merged 1 commit into from

3 participants

@kommen

Rebased and adapted #2303 onto master as requested buy @steveklabnik.

This test case failed with rails 3.1, but it works with 3.2 and current master. :beers:

@kommen kommen Add test to ensure preloading works as expected with "select" and "in…
…cludes".

This didn't work in rails 3.1. See #2303 for more information and original pull request.
22ed92d
@steveklabnik
Collaborator

Neat, thanks. I'd imagine a regression test is useful. We'll see what others say.

@carlosantoniodasilva carlosantoniodasilva merged commit 5e7919c into rails:master
@carlosantoniodasilva

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 18, 2012
  1. @kommen

    Add test to ensure preloading works as expected with "select" and "in…

    kommen authored
    …cludes".
    
    This didn't work in rails 3.1. See #2303 for more information and original pull request.
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 0 deletions.
  1. +13 −0 activerecord/test/cases/relations_test.rb
View
13 activerecord/test/cases/relations_test.rb
@@ -1438,4 +1438,17 @@ def test_presence
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
Something went wrong with that request. Please try again.