1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

move AR length validation tests into separate test-case.

Conflicts:
	activerecord/test/cases/validations/association_validation_test.rb
This commit is contained in:
Yves Senn 2013-03-25 16:00:24 +01:00
parent 960707aeda
commit 7fe5ae8d23
2 changed files with 48 additions and 42 deletions

View file

@ -1,44 +1,14 @@
# encoding: utf-8
require "cases/helper"
require 'models/topic'
require 'models/reply'
require 'models/owner'
require 'models/pet'
require 'models/man'
require 'models/interest'
class AssociationValidationTest < ActiveRecord::TestCase
fixtures :topics, :owners
fixtures :topics
repair_validations(Topic, Reply)
def test_validates_size_of_association
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
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
Topic.validates_associated(:replies)
Reply.validates_presence_of(:content)
@ -94,17 +64,6 @@ class AssociationValidationTest < ActiveRecord::TestCase
assert r.valid?
end
def test_validates_size_of_association_utf8
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
repair_validations(Interest) do
# Note that Interest and Man have the :inverse_of option set

View file

@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
require "cases/helper"
require 'models/owner'
require 'models/pet'
class LengthValidationTest < ActiveRecord::TestCase
fixtures :owners
repair_validations(Owner)
def test_validates_size_of_association
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
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_size_of_association_utf8
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
end