aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2004-12-10 13:11:13 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2004-12-10 13:11:13 +0000
commit0b92b7de2f752bee6c4c950ac9090e5bce3b63bf (patch)
treee0f809f62691f9a73461dfa2b725c52adf2ed39a /activerecord/test
parent8712652dd9728a1df9c9f095da03318d804ebac2 (diff)
downloadrails-0b92b7de2f752bee6c4c950ac9090e5bce3b63bf.tar.gz
rails-0b92b7de2f752bee6c4c950ac9090e5bce3b63bf.tar.bz2
rails-0b92b7de2f752bee6c4c950ac9090e5bce3b63bf.zip
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
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/validations_test.rb27
1 files changed, 20 insertions, 7 deletions
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