aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/associations_join_model_test.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-04-05 17:01:56 +0000
committerRick Olson <technoweenie@gmail.com>2006-04-05 17:01:56 +0000
commita9fb1544b0e7e6412e4cb64702585024e24276bf (patch)
tree6f9b5c099d3304184c284aa0219add424be6e2b6 /activerecord/test/associations_join_model_test.rb
parent4d232025b7260834dc4a4403b2b9effd043215c4 (diff)
downloadrails-a9fb1544b0e7e6412e4cb64702585024e24276bf.tar.gz
rails-a9fb1544b0e7e6412e4cb64702585024e24276bf.tar.bz2
rails-a9fb1544b0e7e6412e4cb64702585024e24276bf.zip
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
Diffstat (limited to 'activerecord/test/associations_join_model_test.rb')
-rw-r--r--activerecord/test/associations_join_model_test.rb16
1 files changed, 16 insertions, 0 deletions
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