Permalink
Browse files

Do not require that validation attributes be specified as symbols

  • Loading branch information...
carllerche committed Feb 5, 2011
1 parent b9309b4 commit 7176ade35b4d6b167873991e0851f3fb9d46ae3b
@@ -84,7 +84,6 @@ def validates(*attributes)
validations = defaults.slice!(:if, :unless, :on, :allow_blank, :allow_nil)
raise ArgumentError, "You need to supply at least one attribute" if attributes.empty?
- raise ArgumentError, "Attribute names must be symbols" if attributes.any?{ |attribute| !attribute.is_a?(Symbol) }
raise ArgumentError, "You need to supply at least one validation" if validations.empty?
defaults.merge!(:attributes => attributes)
@@ -118,4 +117,4 @@ def _parse_validates_options(options) #:nodoc:
end
end
end
-end
+end
@@ -21,6 +21,17 @@ def test_validates_with_built_in_validation
assert_equal ['is not a number'], person.errors[:title]
end
+ def test_validates_with_attribute_specified_as_string
+ Person.validates "title", :numericality => true
+ person = Person.new
+ person.valid?
+ assert_equal ['is not a number'], person.errors[:title]
+
+ person = Person.new
+ person.title = 123
+ assert person.valid?
+ end
+
def test_validates_with_built_in_validation_and_options
Person.validates :salary, :numericality => { :message => 'my custom message' }
person = Person.new

0 comments on commit 7176ade

Please sign in to comment.