From 2bbd36e02f0dacfee2d2d3f9b6d1e46684e3cbd3 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 31 May 2010 17:25:20 +1000 Subject: [PATCH] Attempting to add a failing test for obj->has_one->HABTM ANAF issue. --- activerecord/test/cases/nested_attributes_test.rb | 6 ++++++ activerecord/test/models/cannon.rb | 3 +++ activerecord/test/models/ship.rb | 2 ++ activerecord/test/schema/schema.rb | 9 +++++++++ 4 files changed, 20 insertions(+), 0 deletions(-) create mode 100644 activerecord/test/models/cannon.rb diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 2202714..0e41f6e 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -1,6 +1,7 @@ require "cases/helper" require "models/pirate" require "models/ship" +require "models/cannon" require "models/ship_part" require "models/bird" require "models/parrot" @@ -271,6 +272,11 @@ class TestNestedAttributesOnAHasOneAssociation < ActiveRecord::TestCase end assert_equal 'Mayflower', @ship.reload.name end + + def test_nested_assignment_of_has_and_belongs_to_many_association + @pirate.update_attributes({ :ship_attributes => { :cannons_attributes => { "0" => { "created_at" => Time.now }}}}) + + end end class TestNestedAttributesOnABelongsToAssociation < ActiveRecord::TestCase diff --git a/activerecord/test/models/cannon.rb b/activerecord/test/models/cannon.rb new file mode 100644 index 0000000..1389226 --- /dev/null +++ b/activerecord/test/models/cannon.rb @@ -0,0 +1,3 @@ +class Cannon < ActiveRecord::Base + has_and_belongs_to_many :ships +end \ No newline at end of file diff --git a/activerecord/test/models/ship.rb b/activerecord/test/models/ship.rb index 3da0319..e4a5250 100644 --- a/activerecord/test/models/ship.rb +++ b/activerecord/test/models/ship.rb @@ -4,7 +4,9 @@ class Ship < ActiveRecord::Base belongs_to :pirate belongs_to :update_only_pirate, :class_name => 'Pirate' has_many :parts, :class_name => 'ShipPart' + has_and_belongs_to_many :cannons + accepts_nested_attributes_for :cannons accepts_nested_attributes_for :parts, :allow_destroy => true accepts_nested_attributes_for :pirate, :allow_destroy => true, :reject_if => proc { |attributes| attributes.empty? } accepts_nested_attributes_for :update_only_pirate, :update_only => true diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index c8e652a..b7aef1e 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -73,6 +73,15 @@ ActiveRecord::Schema.define do create_table "CamelCase", :force => true do |t| t.string :name end + + create_table :cannons, :force => true do |t| + t.timestamps + end + + create_table :cannons_ships, :force => true, :id => false do |t| + t.references :cannon + t.references :ship + end create_table :categories, :force => true do |t| t.string :name, :null => false -- 1.6.4.1