aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/validations/format_validation_test.rb
diff options
context:
space:
mode:
authorElliot Winkler <elliot.winkler@gmail.com>2009-08-09 21:47:32 -0500
committerPratik Naik <pratiknaik@gmail.com>2009-08-10 15:22:31 +0100
commitcccb0e6b9327fb562b72007a012933c9c61a33fa (patch)
tree7542b875b241afc4493dca3c7f74412400c0a3f3 /activemodel/test/cases/validations/format_validation_test.rb
parent600a89f2082beadf4af9fe140a1a2ae56386cd49 (diff)
downloadrails-cccb0e6b9327fb562b72007a012933c9c61a33fa.tar.gz
rails-cccb0e6b9327fb562b72007a012933c9c61a33fa.tar.bz2
rails-cccb0e6b9327fb562b72007a012933c9c61a33fa.zip
Add validates_format_of :without => /regexp/ option [Elliot Winkler, Peer Allan]
[#430 state:resolved] Example : validates_format_of :subdomain, :without => /www|admin|mail/ Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activemodel/test/cases/validations/format_validation_test.rb')
-rw-r--r--activemodel/test/cases/validations/format_validation_test.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/activemodel/test/cases/validations/format_validation_test.rb b/activemodel/test/cases/validations/format_validation_test.rb
index 2c06a9dd02..e19e4bf7b3 100644
--- a/activemodel/test/cases/validations/format_validation_test.rb
+++ b/activemodel/test/cases/validations/format_validation_test.rb
@@ -71,6 +71,35 @@ class PresenceValidationTest < ActiveModel::TestCase
assert_equal ["can't be Invalid title"], t.errors[:title]
end
+ def test_validate_format_with_not_option
+ Topic.validates_format_of(:title, :without => /foo/, :message => "should not contain foo")
+ t = Topic.new
+
+ t.title = "foobar"
+ t.valid?
+ assert_equal ["should not contain foo"], t.errors[:title]
+
+ t.title = "something else"
+ t.valid?
+ assert_equal [], t.errors[:title]
+ end
+
+ def test_validate_format_of_without_any_regexp_should_raise_error
+ assert_raise(ArgumentError) { Topic.validates_format_of(:title) }
+ end
+
+ def test_validates_format_of_with_both_regexps_should_raise_error
+ assert_raise(ArgumentError) { Topic.validates_format_of(:title, :with => /this/, :without => /that/) }
+ end
+
+ def test_validates_format_of_when_with_isnt_a_regexp_should_raise_error
+ assert_raise(ArgumentError) { Topic.validates_format_of(:title, :with => "clearly not a regexp") }
+ end
+
+ def test_validates_format_of_when_not_isnt_a_regexp_should_raise_error
+ assert_raise(ArgumentError) { Topic.validates_format_of(:title, :without => "clearly not a regexp") }
+ end
+
def test_validates_format_of_with_custom_error_using_quotes
repair_validations(Developer) do
Developer.validates_format_of :name, :with => /^(A-Z*)$/, :message=> "format 'single' and \"double\" quotes"