From f34d57e2d2fcc3357e7b4076d23bed3bfbd35ce3 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 29 Mar 2008 17:53:44 +0000 Subject: Fixed that validates_size_of :within works in associations (closes #11295, #10019) [cavalle] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9129 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/cases/validations_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index 34d55dbcf6..3d83b8d4d1 100755 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -806,6 +806,20 @@ class ValidationsTest < ActiveRecord::TestCase reply = t.replies.build('title' => 'areply', 'content' => 'whateveragain') assert t.valid? end + + def test_validates_size_of_association_using_within + assert_nothing_raised { Topic.validates_size_of :replies, :within => 1..2 } + t = Topic.new('title' => 'noreplies', 'content' => 'whatever') + assert !t.save + assert t.errors.on(:replies) + + reply = t.replies.build('title' => 'areply', 'content' => 'whateveragain') + assert t.valid? + + 2.times { t.replies.build('title' => 'areply', 'content' => 'whateveragain') } + assert !t.save + assert t.errors.on(:replies) + end def test_validates_length_of_nasty_params assert_raise(ArgumentError) { Topic.validates_length_of(:title, :minimum=>6, :maximum=>9) } -- cgit v1.2.3