From e627bbe92b569fbd70ea8dc07960cac10ab0bc64 Mon Sep 17 00:00:00 2001 From: Antonio Tapiador del Dujo Date: Tue, 15 Dec 2009 16:40:02 +0100 Subject: [PATCH] Test proving HABTM bug with nested attributes When creating a nested model in a HABTM association, several join records are created --- activerecord/test/cases/nested_attributes_test.rb | 8 ++++++++ 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 59ba9a3..721673c 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -352,6 +352,14 @@ module NestedAttributesOnACollectionAssociationTests assert_respond_to @pirate, association_setter end + def test_should_save_only_one_association_on_create + new_params = { :catchphrase => "yeah!", + association_getter => { 'foo' => { :name => "fooooo" } } + } + new_pirate = Pirate.create!(new_params).reload + assert_equal 1, new_pirate.send(@association_name).count + end + def test_should_take_a_hash_with_string_keys_and_assign_the_attributes_to_the_associated_models @alternate_params[association_getter].stringify_keys! @pirate.update_attributes @alternate_params -- 1.6.5