aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-02-09 19:37:05 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-02-09 19:37:05 +0000
commitb3065a51a927ded6b22835837598e92df606eaed (patch)
tree5436f083affe38e328447bd2187cf7020524b920 /activerecord/test
parentc326851e4db8a41d76cf05a8db71bc853fa08821 (diff)
downloadrails-b3065a51a927ded6b22835837598e92df606eaed.tar.gz
rails-b3065a51a927ded6b22835837598e92df606eaed.tar.bz2
rails-b3065a51a927ded6b22835837598e92df606eaed.zip
Polymorphic join support for has_one associations (has_one :foo, :as => :bar). Closes #3785.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3558 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/associations_join_model_test.rb11
-rw-r--r--activerecord/test/fixtures/post.rb2
-rw-r--r--activerecord/test/fixtures/tag.rb1
3 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/test/associations_join_model_test.rb b/activerecord/test/associations_join_model_test.rb
index 61488900d6..5437e049a3 100644
--- a/activerecord/test/associations_join_model_test.rb
+++ b/activerecord/test/associations_join_model_test.rb
@@ -26,6 +26,10 @@ class AssociationsJoinModelTest < Test::Unit::TestCase
def test_polymorphic_has_many
assert_equal taggings(:welcome_general), posts(:welcome).taggings.first
end
+
+ def test_polymorphic_has_one
+ assert_equal taggings(:welcome_general), posts(:welcome).tagging
+ end
def test_polymorphic_belongs_to
assert_equal posts(:welcome), posts(:welcome).taggings.first.taggable
@@ -46,7 +50,12 @@ class AssociationsJoinModelTest < Test::Unit::TestCase
tagging = tags(:misc).taggings.create(:taggable => post)
assert_equal "Post", tagging.taggable_type
end
-
+
+ def test_polymorphic_has_one_create_model_with_inheritance
+ tagging = tags(:misc).create_tagging(:taggable => posts(:thinking))
+ assert_equal "Post", tagging.taggable_type
+ end
+
def test_has_many_with_piggyback
assert_equal "2", categories(:sti_test).authors.first.post_id.to_s
end
diff --git a/activerecord/test/fixtures/post.rb b/activerecord/test/fixtures/post.rb
index ada18af115..4c2ccb3f43 100644
--- a/activerecord/test/fixtures/post.rb
+++ b/activerecord/test/fixtures/post.rb
@@ -23,6 +23,8 @@ class Post < ActiveRecord::Base
has_many :taggings, :as => :taggable
has_many :tags, :through => :taggings
+ has_one :tagging, :as => :taggable
+
has_many :categorizations, :foreign_key => :category_id
has_many :authors, :through => :categorizations
diff --git a/activerecord/test/fixtures/tag.rb b/activerecord/test/fixtures/tag.rb
index d54f3cd680..78b6f6666c 100644
--- a/activerecord/test/fixtures/tag.rb
+++ b/activerecord/test/fixtures/tag.rb
@@ -1,3 +1,4 @@
class Tag < ActiveRecord::Base
has_many :taggings, :as => :taggable
+ has_one :tagging, :as => :taggable
end \ No newline at end of file