Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 9e4d156
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit 9e4d156

Please sign in to comment.