diff options
author | Olek Janiszewski <olek.janiszewski@gmail.com> | 2011-12-04 23:34:58 +0100 |
---|---|---|
committer | Olek Janiszewski <olek.janiszewski@gmail.com> | 2011-12-05 00:19:21 +0100 |
commit | a8134aceb363d581d6b49aeb08feeadaf474d051 (patch) | |
tree | f0ad9ee7f7ffa69c0281c207ec0baa274f4c88a1 /activerecord/test | |
parent | 4e74bd194beb6f51ee7c4bf06bfaab72d70f1c2c (diff) | |
download | rails-a8134aceb363d581d6b49aeb08feeadaf474d051.tar.gz rails-a8134aceb363d581d6b49aeb08feeadaf474d051.tar.bz2 rails-a8134aceb363d581d6b49aeb08feeadaf474d051.zip |
Do not validate associated records marked for destruction
The main reason for this change is to fix a bug where
`validates_associated` would prevent `accepts_nested_attributes_for`
with `allow_destroy: true` from destroying invalid associated records.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/validations/association_validation_test.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/validations/association_validation_test.rb b/activerecord/test/cases/validations/association_validation_test.rb index 56e345990f..768fbc5b0a 100644 --- a/activerecord/test/cases/validations/association_validation_test.rb +++ b/activerecord/test/cases/validations/association_validation_test.rb @@ -61,6 +61,16 @@ class AssociationValidationTest < ActiveRecord::TestCase assert r.valid? end + def test_validates_associated_marked_for_destruction + Topic.validates_associated(:replies) + Reply.validates_presence_of(:content) + t = Topic.new + t.replies << Reply.new + assert t.invalid? + t.replies.first.mark_for_destruction + assert t.valid? + end + def test_validates_associated_with_custom_message_using_quotes Reply.validates_associated :topic, :message=> "This string contains 'single' and \"double\" quotes" Topic.validates_presence_of :content |