提交 d011c74d 编写于 作者: A Akira Matsuda

Properly repair validations when dynamically added

上级 6c32badd
......@@ -10,29 +10,33 @@
class AssociationValidationTest < ActiveRecord::TestCase
fixtures :topics, :owners
repair_validations(Topic, Reply, Owner)
repair_validations(Topic, Reply)
def test_validates_size_of_association
assert_nothing_raised { Owner.validates_size_of :pets, :minimum => 1 }
o = Owner.new('name' => 'nopets')
assert !o.save
assert o.errors[:pets].any?
o.pets.build('name' => 'apet')
assert o.valid?
repair_validations Owner do
assert_nothing_raised { Owner.validates_size_of :pets, :minimum => 1 }
o = Owner.new('name' => 'nopets')
assert !o.save
assert o.errors[:pets].any?
o.pets.build('name' => 'apet')
assert o.valid?
end
end
def test_validates_size_of_association_using_within
assert_nothing_raised { Owner.validates_size_of :pets, :within => 1..2 }
o = Owner.new('name' => 'nopets')
assert !o.save
assert o.errors[:pets].any?
o.pets.build('name' => 'apet')
assert o.valid?
2.times { o.pets.build('name' => 'apet') }
assert !o.save
assert o.errors[:pets].any?
repair_validations Owner do
assert_nothing_raised { Owner.validates_size_of :pets, :within => 1..2 }
o = Owner.new('name' => 'nopets')
assert !o.save
assert o.errors[:pets].any?
o.pets.build('name' => 'apet')
assert o.valid?
2.times { o.pets.build('name' => 'apet') }
assert !o.save
assert o.errors[:pets].any?
end
end
def test_validates_associated_many
......@@ -91,12 +95,14 @@ def test_validates_associated_missing
end
def test_validates_size_of_association_utf8
assert_nothing_raised { Owner.validates_size_of :pets, :minimum => 1 }
o = Owner.new('name' => 'あいうえおかきくけこ')
assert !o.save
assert o.errors[:pets].any?
o.pets.build('name' => 'あいうえおかきくけこ')
assert o.valid?
repair_validations Owner do
assert_nothing_raised { Owner.validates_size_of :pets, :minimum => 1 }
o = Owner.new('name' => 'あいうえおかきくけこ')
assert !o.save
assert o.errors[:pets].any?
o.pets.build('name' => 'あいうえおかきくけこ')
assert o.valid?
end
end
def test_validates_presence_of_belongs_to_association__parent_is_new_record
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册