Permalink
Browse files

When you add a record to a polymorphic has_one, you should be able to…

… access the owner from the associated record
  • Loading branch information...
1 parent a1e78cf commit 4f5f6a3257862c0893c89a69321025e5873585dc @jonleighton jonleighton committed Jun 7, 2011
@@ -141,7 +141,7 @@ def load_target
@target ||= find_target
end
end
- loaded!
+ loaded! unless loaded?
target
rescue ActiveRecord::RecordNotFound
reset
@@ -14,8 +14,8 @@ def replace(record, save = true)
end
if record
- set_inverse_instance(record)
set_owner_attributes(record)
+ set_inverse_instance(record)
if owner.persisted? && save && !record.save
nullify_owner_attributes(record)
@@ -139,7 +139,10 @@ def test_set_polymorphic_has_many
def test_set_polymorphic_has_one
tagging = tags(:misc).taggings.create
posts(:thinking).tagging = tagging
- assert_equal "Post", tagging.taggable_type
+
+ assert_equal "Post", tagging.taggable_type
+ assert_equal posts(:thinking).id, tagging.taggable_id
+ assert_equal posts(:thinking), tagging.taggable
end
def test_create_polymorphic_has_many_with_scope

0 comments on commit 4f5f6a3

Please sign in to comment.