aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-12-03 04:29:55 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-12-03 04:29:55 +0000
commit6abda696b5df14a9ab132c34311daaabe12030e6 (patch)
treeeb0cfad7daa4d46848e6ea10e1abd90ed93a3368 /activerecord/test
parent57b7532b910f9258cad4111db79349d2d63be6d4 (diff)
downloadrails-6abda696b5df14a9ab132c34311daaabe12030e6.tar.gz
rails-6abda696b5df14a9ab132c34311daaabe12030e6.tar.bz2
rails-6abda696b5df14a9ab132c34311daaabe12030e6.zip
Added preliminary support for join models [DHH] Added preliminary support for polymorphic associations [DHH] Refactored associations to use reflections to get DRYer, beware, major refactoring -- double check before deploying anything with this (all tests pass, but..)
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3213 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/associations_join_model_test.rb (renamed from activerecord/test/associations_interface_test.rb)10
-rw-r--r--activerecord/test/fixtures/post.rb1
-rw-r--r--activerecord/test/reflection_test.rb7
3 files changed, 11 insertions, 7 deletions
diff --git a/activerecord/test/associations_interface_test.rb b/activerecord/test/associations_join_model_test.rb
index 5f9447294a..303c33679f 100644
--- a/activerecord/test/associations_interface_test.rb
+++ b/activerecord/test/associations_join_model_test.rb
@@ -4,14 +4,18 @@ require 'fixtures/tagging'
require 'fixtures/post'
require 'fixtures/comment'
-class AssociationsInterfaceTest < Test::Unit::TestCase
+class AssociationsJoinModelTest < Test::Unit::TestCase
fixtures :posts, :comments, :tags, :taggings
- def test_post_having_a_single_tag_through_has_many
+ def test_polymorphic_has_many
assert_equal taggings(:welcome_general), posts(:welcome).taggings.first
end
- def test_post_having_a_single_tag_through_belongs_to
+ def test_polymorphic_belongs_to
assert_equal posts(:welcome), posts(:welcome).taggings.first.taggable
end
+
+ def test_polymorphic_has_many_going_through_join_model
+ assert_equal tags(:general), posts(:welcome).tags.first
+ end
end
diff --git a/activerecord/test/fixtures/post.rb b/activerecord/test/fixtures/post.rb
index 61249c43e0..97b25179f5 100644
--- a/activerecord/test/fixtures/post.rb
+++ b/activerecord/test/fixtures/post.rb
@@ -21,6 +21,7 @@ class Post < ActiveRecord::Base
has_and_belongs_to_many :special_categories, :join_table => "categories_posts"
has_many :taggings, :as => :taggable
+ has_many :tags, :through => :taggings
def self.what_are_you
'a post...'
diff --git a/activerecord/test/reflection_test.rb b/activerecord/test/reflection_test.rb
index c3117b8c5d..7af9e8c70d 100644
--- a/activerecord/test/reflection_test.rb
+++ b/activerecord/test/reflection_test.rb
@@ -60,10 +60,9 @@ class ReflectionTest < Test::Unit::TestCase
:composed_of, :gps_location, { }, Customer
)
- assert_equal(
- [ reflection_for_address, reflection_for_balance, reflection_for_gps_location ],
- Customer.reflect_on_all_aggregations
- )
+ assert Customer.reflect_on_all_aggregations.include?(reflection_for_gps_location)
+ assert Customer.reflect_on_all_aggregations.include?(reflection_for_balance)
+ assert Customer.reflect_on_all_aggregations.include?(reflection_for_address)
assert_equal reflection_for_address, Customer.reflect_on_aggregation(:address)