diff options
author | Rick Olson <technoweenie@gmail.com> | 2006-03-19 00:53:24 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2006-03-19 00:53:24 +0000 |
commit | 57af961a80ee01d1876dfc50d93544906a995617 (patch) | |
tree | 571058edf37e0903d5bf72bea16925d36a486eda /activerecord/test | |
parent | 49efa02b9e8d868b2d28a3db76269d8b8fcde0a6 (diff) | |
download | rails-57af961a80ee01d1876dfc50d93544906a995617.tar.gz rails-57af961a80ee01d1876dfc50d93544906a995617.tar.bz2 rails-57af961a80ee01d1876dfc50d93544906a995617.zip |
Raise error when trying to select many polymorphic objects with has_many :through or :include (closes #4226) [josh@hasmanythrough.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3961 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/associations_join_model_test.rb | 11 | ||||
-rw-r--r-- | activerecord/test/fixtures/tag.rb | 5 |
2 files changed, 13 insertions, 3 deletions
diff --git a/activerecord/test/associations_join_model_test.rb b/activerecord/test/associations_join_model_test.rb index 9477e69e55..f53a7669f4 100644 --- a/activerecord/test/associations_join_model_test.rb +++ b/activerecord/test/associations_join_model_test.rb @@ -213,7 +213,7 @@ class AssociationsJoinModelTest < Test::Unit::TestCase end def test_unavailable_through_reflection - assert_raises (ActiveRecord::ActiveRecordError) { authors(:david).nothings } + assert_raises (ActiveRecord::HasManyThroughAssociationNotFoundError) { authors(:david).nothings } end def test_has_many_through_join_model_with_conditions @@ -221,6 +221,15 @@ class AssociationsJoinModelTest < Test::Unit::TestCase assert_equal [], posts(:welcome).invalid_tags end + def test_has_many_polymorphic + assert_raises ActiveRecord::HasManyThroughAssociationPolymorphicError do + assert_equal [posts(:welcome), posts(:thinking)], tags(:general).taggables + end + assert_raises ActiveRecord::EagerLoadPolymorphicError do + assert_equal [posts(:welcome), posts(:thinking)], tags(:general).taggings.find(:all, :include => :taggable) + end + end + private # create dynamic Post models to allow different dependency options def find_post_with_dependency(post_id, association, association_name, dependency) diff --git a/activerecord/test/fixtures/tag.rb b/activerecord/test/fixtures/tag.rb index 78b6f6666c..ed3c6ce34a 100644 --- a/activerecord/test/fixtures/tag.rb +++ b/activerecord/test/fixtures/tag.rb @@ -1,4 +1,5 @@ class Tag < ActiveRecord::Base - has_many :taggings, :as => :taggable - has_one :tagging, :as => :taggable + has_many :taggings, :as => :taggable + has_many :taggables, :through => :taggings + has_one :tagging, :as => :taggable end
\ No newline at end of file |