aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorMike Breen <hardbap@gmail.com>2009-07-11 14:30:35 +0200
committerEloy Duran <eloy.de.enige@gmail.com>2009-09-12 15:37:54 +0200
commitbcd0ef710ec6d2cc6b880c39de0dfacc07df85e4 (patch)
tree9bce1073883ad4facad446b06f8d2cd53d224358 /activerecord/test/cases
parent3180619c0d228812c119e9704ac5956cbcad8614 (diff)
downloadrails-bcd0ef710ec6d2cc6b880c39de0dfacc07df85e4.tar.gz
rails-bcd0ef710ec6d2cc6b880c39de0dfacc07df85e4.tar.bz2
rails-bcd0ef710ec6d2cc6b880c39de0dfacc07df85e4.zip
Raise an exception with friendlier error message when attempting to build a polymorphic belongs_to with accepts_nested_attributes_for. [#2318 state:resolved]
Signed-off-by: Eloy Duran <eloy.de.enige@gmail.com>
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/nested_attributes_test.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb
index d033c1e760..b1a6f13111 100644
--- a/activerecord/test/cases/nested_attributes_test.rb
+++ b/activerecord/test/cases/nested_attributes_test.rb
@@ -81,11 +81,19 @@ class TestNestedAttributesInGeneral < ActiveRecord::TestCase
end
class TestNestedAttributesOnAHasOneAssociation < ActiveRecord::TestCase
+ include AssertRaiseWithMessage
+
def setup
@pirate = Pirate.create!(:catchphrase => "Don' botharrr talkin' like one, savvy?")
@ship = @pirate.create_ship(:name => 'Nights Dirty Lightning')
end
+ def test_should_raise_argument_error_if_trying_to_build_polymorphic_belongs_to
+ assert_raise_with_message ArgumentError, "Cannot build association looter. Are you trying to build a polymorphic one-to-one association?" do
+ Treasure.new(:name => 'pearl', :looter_attributes => {:catchphrase => "Arrr"})
+ end
+ end
+
def test_should_define_an_attribute_writer_method_for_the_association
assert_respond_to @pirate, :ship_attributes=
end