From a9fb1544b0e7e6412e4cb64702585024e24276bf Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Wed, 5 Apr 2006 17:01:56 +0000 Subject: Added support for eagerly including polymorphic has_one associations. (closes #4525) [Rick] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4170 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/associations_join_model_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'activerecord/test/associations_join_model_test.rb') diff --git a/activerecord/test/associations_join_model_test.rb b/activerecord/test/associations_join_model_test.rb index b7f0af173b..4a11d4c5eb 100644 --- a/activerecord/test/associations_join_model_test.rb +++ b/activerecord/test/associations_join_model_test.rb @@ -208,6 +208,14 @@ class AssociationsJoinModelTest < Test::Unit::TestCase end end + def test_include_polymorphic_has_one + post = Post.find_by_id(posts(:welcome).id, :include => :tagging) + tagging = taggings(:welcome_general) + assert_no_queries do + assert_equal tagging, post.tagging + end + end + def test_include_polymorphic_has_many_through posts = Post.find(:all, :order => 'posts.id') posts_with_tags = Post.find(:all, :include => :tags, :order => 'posts.id') @@ -303,6 +311,14 @@ class AssociationsJoinModelTest < Test::Unit::TestCase assert_equal [taggings(:welcome_general), taggings(:thinking_general)], authors(:david).taggings.uniq.sort_by { |t| t.id } end + def test_has_many_through_polymorphic_has_many_with_eager_loading + author = Author.find_by_id(authors(:david).id, :include => :taggings) + expected_taggings = [taggings(:welcome_general), taggings(:thinking_general)] + assert_no_queries do + assert_equal expected_taggings, author.taggings.uniq.sort_by { |t| t.id } + end + end + def test_has_many_through_has_many_through assert_raise(ActiveRecord::HasManyThroughSourceAssociationMacroError) { authors(:david).tags } end -- cgit v1.2.3