aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/autosave_association_test.rb
diff options
context:
space:
mode:
authorEloy Duran <eloy.de.enige@gmail.com>2009-07-11 20:52:03 +0200
committerEloy Duran <eloy.de.enige@gmail.com>2009-09-12 16:04:07 +0200
commit65f98951ac5fe75191c6fde996b9e0f9b765414f (patch)
treec5ecf346361463edee98aa7d83b56eb8862c73ac /activerecord/test/cases/autosave_association_test.rb
parentc01be9de322ba846923340e41e69821d01541610 (diff)
downloadrails-65f98951ac5fe75191c6fde996b9e0f9b765414f.tar.gz
rails-65f98951ac5fe75191c6fde996b9e0f9b765414f.tar.bz2
rails-65f98951ac5fe75191c6fde996b9e0f9b765414f.zip
During autosave, ignore records that already have been destroyed. [#2537 state:resolved]
Diffstat (limited to 'activerecord/test/cases/autosave_association_test.rb')
-rw-r--r--activerecord/test/cases/autosave_association_test.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb
index d51c4398d4..29b199cf04 100644
--- a/activerecord/test/cases/autosave_association_test.rb
+++ b/activerecord/test/cases/autosave_association_test.rb
@@ -548,6 +548,13 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase
assert_difference('Ship.count', -1) { @pirate.save! }
end
+ def test_a_child_marked_for_destruction_should_not_be_destroyed_twice
+ @pirate.ship.mark_for_destruction
+ assert @pirate.save
+ @pirate.ship.expects(:destroy).never
+ assert @pirate.save
+ end
+
def test_should_rollback_destructions_if_an_exception_occurred_while_saving_a_child
# Stub the save method of the @pirate.ship instance to destroy and then raise an exception
class << @pirate.ship
@@ -586,6 +593,13 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase
assert_difference('Pirate.count', -1) { @ship.save! }
end
+ def test_a_parent_marked_for_destruction_should_not_be_destroyed_twice
+ @ship.pirate.mark_for_destruction
+ assert @ship.save
+ @ship.pirate.expects(:destroy).never
+ assert @ship.save
+ end
+
def test_should_rollback_destructions_if_an_exception_occurred_while_saving_a_parent
# Stub the save method of the @ship.pirate instance to destroy and then raise an exception
class << @ship.pirate
@@ -644,6 +658,16 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase
assert @pirate.valid?
end
+ define_method("test_a_child_marked_for_destruction_should_not_be_destroyed_twice_while_saving_#{association_name}") do
+ @pirate.send(association_name).create!(:name => "#{association_name}_1")
+ children = @pirate.send(association_name)
+
+ children.each { |child| child.mark_for_destruction }
+ assert @pirate.save
+ children.each { |child| child.expects(:destroy).never }
+ assert @pirate.save
+ end
+
define_method("test_should_rollback_destructions_if_an_exception_occurred_while_saving_#{association_name}") do
2.times { |i| @pirate.send(association_name).create!(:name => "#{association_name}_#{i}") }
before = @pirate.send(association_name).map { |c| c }