diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-03-25 15:58:23 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-12-30 10:25:58 +0100 |
commit | 2b12288139f9bad6cf6d058d93af66cdf598dda9 (patch) | |
tree | 439daa4ce91c71baf46906561196ff0323707292 /activerecord/test | |
parent | ecb1981bfd3ffaca3a3efd110fc85380ece8191d (diff) | |
download | rails-2b12288139f9bad6cf6d058d93af66cdf598dda9.tar.gz rails-2b12288139f9bad6cf6d058d93af66cdf598dda9.tar.bz2 rails-2b12288139f9bad6cf6d058d93af66cdf598dda9.zip |
AR specific length validator to respect `marked_for_destruction`.
Closes #7247.
Conflicts:
activerecord/CHANGELOG.md
activerecord/test/models/owner.rb
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/validations/length_validation_test.rb | 18 | ||||
-rw-r--r-- | activerecord/test/models/owner.rb | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/test/cases/validations/length_validation_test.rb b/activerecord/test/cases/validations/length_validation_test.rb index 4a92da38ce..2c0e282761 100644 --- a/activerecord/test/cases/validations/length_validation_test.rb +++ b/activerecord/test/cases/validations/length_validation_test.rb @@ -2,6 +2,7 @@ require "cases/helper" require 'models/owner' require 'models/pet' +require 'models/person' class LengthValidationTest < ActiveRecord::TestCase fixtures :owners @@ -44,4 +45,21 @@ class LengthValidationTest < ActiveRecord::TestCase assert o.valid? end end + + def test_validates_size_of_reprects_records_marked_for_destruction + assert_nothing_raised { Owner.validates_size_of :pets, minimum: 1 } + owner = Owner.new + assert_not owner.save + assert owner.errors[:pets].any? + pet = owner.pets.build + assert owner.valid? + assert owner.save + + pet_count = Pet.count + assert_not owner.update_attributes pets_attributes: [ {_destroy: 1, id: pet.id} ] + assert_not owner.valid? + assert owner.errors[:pets].any? + assert_equal pet_count, Pet.count + end + end diff --git a/activerecord/test/models/owner.rb b/activerecord/test/models/owner.rb index 2e3a9a3681..cedb774b10 100644 --- a/activerecord/test/models/owner.rb +++ b/activerecord/test/models/owner.rb @@ -17,6 +17,8 @@ class Owner < ActiveRecord::Base after_commit :execute_blocks + accepts_nested_attributes_for :pets, allow_destroy: true + def blocks @blocks ||= [] end |