Permalink
Browse files

Merge pull request #1837 from msgehard/3-0-stable

Fix for empty string assigned to _type column of polymorphic association
  • Loading branch information...
spastorino committed Jul 6, 2011
2 parents 2f3eb7a + 5a44c70 commit 9e4d1565ad311599318a8ad05f59a89ecf2f55d1
@@ -75,7 +75,7 @@ def record_id(record)
end
def association_class
- @owner[@reflection.options[:foreign_type]] ? @owner[@reflection.options[:foreign_type]].constantize : nil
+ @owner[@reflection.options[:foreign_type]].present? ? @owner[@reflection.options[:foreign_type]].constantize : nil
end
end
end
@@ -161,6 +161,13 @@ def test_with_polymorphic_and_condition
assert_nil sponsor.sponsorable_with_conditions
end
+ def test_polymorphic_with_empty_string_for_type
+ sponsor = Sponsor.create
+ sponsor.sponsorable_type = ""
+
+ assert_nil sponsor.sponsorable
+ end
+
def test_with_select
assert_equal Company.find(2).firm_with_select.attributes.size, 1
assert_equal Company.find(2, :include => :firm_with_select ).firm_with_select.attributes.size, 1

0 comments on commit 9e4d156

Please sign in to comment.