diff options
author | Lance Ivy <lance@cainlevy.net> | 2009-07-11 15:09:09 +0200 |
---|---|---|
committer | Eloy Duran <eloy.de.enige@gmail.com> | 2009-09-12 15:40:45 +0200 |
commit | a44a1257d879311d88c2d10c366ab0d6561f903a (patch) | |
tree | e61e24e8dfbd243dfc9b9aa59dbea8f7956b4f86 /activerecord/test | |
parent | bcd0ef710ec6d2cc6b880c39de0dfacc07df85e4 (diff) | |
download | rails-a44a1257d879311d88c2d10c366ab0d6561f903a.tar.gz rails-a44a1257d879311d88c2d10c366ab0d6561f903a.tar.bz2 rails-a44a1257d879311d88c2d10c366ab0d6561f903a.zip |
Don't cascade autosave validation to destroyed children. [#2761 state:resolved]
Signed-off-by: Eloy Duran <eloy.de.enige@gmail.com>
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/autosave_association_test.rb | 11 | ||||
-rwxr-xr-x | activerecord/test/cases/base_test.rb | 2 |
2 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index 271086af8e..00e64ca51f 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -563,6 +563,17 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase children.each { |child| child.mark_for_destruction } assert_difference("#{association_name.classify}.count", -2) { @pirate.save! } end + + define_method("test_should_skip_validation_on_the_#{association_name}_association_if_destroyed") do + @pirate.send(association_name).create!(:name => "#{association_name}_1") + children = @pirate.send(association_name) + + children.each { |child| child.name = '' } + assert !@pirate.valid? + + children.each { |child| child.destroy } + assert @pirate.valid? + 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}") } diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 8421a8fb07..3f61e1148d 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -529,6 +529,7 @@ class BasicsTest < ActiveRecord::TestCase topic = Topic.find(1) assert_equal topic, topic.delete, 'topic.delete did not return self' assert topic.frozen?, 'topic not frozen after delete' + assert topic.destroyed?, 'topic not marked as being destroyed' assert_raise(ActiveRecord::RecordNotFound) { Topic.find(topic.id) } end @@ -541,6 +542,7 @@ class BasicsTest < ActiveRecord::TestCase topic = Topic.find(1) assert_equal topic, topic.destroy, 'topic.destroy did not return self' assert topic.frozen?, 'topic not frozen after destroy' + assert topic.destroyed?, 'topic not marked as being destroyed' assert_raise(ActiveRecord::RecordNotFound) { Topic.find(topic.id) } end |