Permalink
Browse files

Raise an ArgumentError when passing an invalid argument to a validator

  • Loading branch information...
1 parent 3c12ab9 commit dd3afdd33b4dad56e58a46c8a6660379e3741e85 @carllerche carllerche committed Nov 19, 2010
@@ -103,8 +103,10 @@ def _parse_validates_options(options) #:nodoc:
{ :with => options }
when Range, Array
{ :in => options }
+ else
+ raise ArgumentError, "#{options.inspect} is an invalid option. Expecting true, Hash, Regexp, Range, or Array"
end
end
end
end
-end
+end
@@ -60,6 +60,12 @@ def test_validates_with_allow_nil_shared_conditions
assert person.valid?
end
+ def test_validates_raises_error_on_invalid_option
+ assert_raises ArgumentError do
+ Person.validates :karma, :length => 5
+ end
+ end
+
def test_validates_with_regexp
Person.validates :karma, :format => /positive|negative/
person = Person.new

0 comments on commit dd3afdd

Please sign in to comment.