diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-16 01:32:35 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-16 01:32:35 +0000 |
commit | 1579f3b45db4b5717984174689c41b1e7f679d1b (patch) | |
tree | bce997d63c557eee0a5fd3ed7fa66515ca8a612e /activerecord/test/validations_test.rb | |
parent | 01e9b7c3058122ea22946be70dc796dd1aaaf7a5 (diff) | |
download | rails-1579f3b45db4b5717984174689c41b1e7f679d1b.tar.gz rails-1579f3b45db4b5717984174689c41b1e7f679d1b.tar.bz2 rails-1579f3b45db4b5717984174689c41b1e7f679d1b.zip |
Added Base.validates_format_of that Validates whether the value of the specified attribute is of the correct form by matching it against the regular expression provided. [Marcel]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@174 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/validations_test.rb')
-rwxr-xr-x | activerecord/test/validations_test.rb | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb index af7c975de1..d4c77d9953 100755 --- a/activerecord/test/validations_test.rb +++ b/activerecord/test/validations_test.rb @@ -191,7 +191,7 @@ class ValidationsTest < Test::Unit::TestCase end def test_validate_boundaries - Topic.validates_boundries_of(:title, :content, :within => 3..5) + Topic.validates_boundaries_of(:title, :content, :within => 3..5) t = Topic.create("title" => "a!", "content" => "I'm ooooooooh so very long") assert !t.save @@ -203,4 +203,21 @@ class ValidationsTest < Test::Unit::TestCase assert t.save end -end
\ No newline at end of file + + def test_validate_format + Topic.validates_format_of(:title, :content, :with => /^Validation macros rule!$/, :message => "is bad data") + + t = Topic.create("title" => "i'm incorrect", "content" => "Validation macros rule!") + assert !t.valid?, "Shouldn't be valid" + assert !t.save, "Shouldn't save because it's invalid" + assert_equal "is bad data", t.errors.on(:title) + assert_nil t.errors.on(:content) + + t.title = "Validation macros rule!" + + assert t.save + assert_nil t.errors.on(:title) + + assert_raise(ArgumentError) { Topic.validates_format_of(:title, :content) } + end +end |