From 0b92b7de2f752bee6c4c950ac9090e5bce3b63bf Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 10 Dec 2004 13:11:13 +0000 Subject: Added Base.validate_presence as an alternative to implementing validate and doing errors.add_on_empty yourself. Added _on_create and _on_update versions for all the new validations git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@107 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/validations_test.rb | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb index 8e25453fae..2d6c795d92 100755 --- a/activerecord/test/validations_test.rb +++ b/activerecord/test/validations_test.rb @@ -7,6 +7,11 @@ require 'fixtures/developer' class ValidationsTest < Test::Unit::TestCase fixtures :topics, :developers + def teardown + Topic.write_inheritable_attribute("validate", []) + Topic.write_inheritable_attribute("validate_on_create", []) + end + def test_single_field_validation r = Reply.new r.title = "There's no content!" @@ -129,12 +134,10 @@ class ValidationsTest < Test::Unit::TestCase t.title_confirmation = "We should be confirmed" assert t.save - - Topic.write_inheritable_attribute("validate_on_create", []) end def test_terms_of_service_agreement - Topic.validate_acceptance(:terms_of_service) + Topic.validate_acceptance_on_create(:terms_of_service) t = Topic.create("title" => "We should be confirmed") assert !t.save @@ -142,13 +145,11 @@ class ValidationsTest < Test::Unit::TestCase t.terms_of_service = "1" assert t.save - - Topic.write_inheritable_attribute("validate_on_create", []) end def test_eula - Topic.validate_acceptance(:eula, "must be abided") + Topic.validate_acceptance_on_create(:eula, "must be abided") t = Topic.create("title" => "We should be confirmed") assert !t.save @@ -156,7 +157,19 @@ class ValidationsTest < Test::Unit::TestCase t.eula = "1" assert t.save + end + + def test_validate_presences + Topic.validate_presence(:title, :content) - Topic.write_inheritable_attribute("validate_on_create", []) + t = Topic.create + assert !t.save + assert_equal "can't be empty", t.errors.on(:title) + assert_equal "can't be empty", t.errors.on(:content) + + t.title = "something" + t.content = "another" + + assert t.save end end \ No newline at end of file -- cgit v1.2.3