Permalink
Browse files

Test for circular reference while saving has_many relationship

  • Loading branch information...
tom-kuca committed Apr 8, 2012
1 parent 206974a commit 8a0e1a3a1ca2ffd9c350e66690ba387aec9b8c03
@@ -1,4 +1,5 @@
require 'cases/helper'
+require 'models/article'
require 'models/bird'
require 'models/company'
require 'models/customer'
@@ -11,6 +12,7 @@
require 'models/pirate'
require 'models/post'
require 'models/reader'
+require 'models/section'
require 'models/ship'
require 'models/ship_part'
require 'models/tag'
@@ -1299,6 +1301,16 @@ def setup
include AutosaveAssociationOnACollectionAssociationTests
end
+class TestAutosaveInverseAssociationOnAHasManyAssociation < ActiveRecord::TestCase
+
+ self.use_transactional_fixtures = false
+
+ def test_should_save_the_inverse_association_model
+ Article.create(:sections_attributes => [{:name => 'First'}, {:name => 'Last'}])
+ end
+
+end
+
class TestAutosaveAssociationOnAHasAndBelongsToManyAssociation < ActiveRecord::TestCase
self.use_transactional_fixtures = false unless supports_savepoints?
@@ -0,0 +1,4 @@
+class Article < ActiveRecord::Base
+ has_many :sections, :inverse_of => :article
+ accepts_nested_attributes_for :sections
+end
@@ -0,0 +1,4 @@
+class Section < ActiveRecord::Base
+ belongs_to :article
+ accepts_nested_attributes_for :article
+end
@@ -46,6 +46,10 @@ def create_table(*args, &block)
t.string :name
end
+ create_table :articles, :force => true do |t|
+ t.string :name
+ end
+
create_table :audit_logs, :force => true do |t|
t.column :message, :string, :null=>false
t.column :developer_id, :integer, :null=>false
@@ -548,6 +552,11 @@ def create_table(*args, &block)
t.integer :lock_version, :default => 0
end
+ create_table :sections, :force => true do |t|
+ t.string :name
+ t.integer :article_id
+ end
+
create_table :shape_expressions, :force => true do |t|
t.string :paint_type
t.integer :paint_id

0 comments on commit 8a0e1a3

Please sign in to comment.