diff options
author | Pavel Forkert <fxposter@gmail.com> | 2011-02-27 23:40:10 +0200 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-04-22 12:06:15 -0500 |
commit | 96acdd3ec48594635314e768bf18805af6a40dde (patch) | |
tree | 9c3ca5bfd4a841f0d69afa3c113c999776301291 /activerecord/test | |
parent | fe4932b531ec9b593085c4bb115c13f0852c3fbb (diff) | |
download | rails-96acdd3ec48594635314e768bf18805af6a40dde.tar.gz rails-96acdd3ec48594635314e768bf18805af6a40dde.tar.bz2 rails-96acdd3ec48594635314e768bf18805af6a40dde.zip |
Added test case and fix for proper eager loading associations
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 40c82f2fb8..9bc7910fc6 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -170,6 +170,16 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_equal [comment], category.posts[0].comments end end + + def test_associations_loaded_for_all_records + post = Post.create!(:title => 'foo', :body => "I like cars!") + comment = SpecialComment.create!(:body => 'Come on!', :post => post) + first_category = Category.create! :name => 'First!', :posts => [post] + second_category = Category.create! :name => 'Second!', :posts => [post] + + categories = Category.where(:id => [first_category.id, second_category.id]).includes(:posts => :special_comments) + assert_equal categories.map { |category| category.posts.first.special_comments.loaded? }, [true, true] + end def test_finding_with_includes_on_has_many_association_with_same_include_includes_only_once author_id = authors(:david).id |