提交 7176ade3 编写于 作者: C Carl Lerche

Do not require that validation attributes be specified as symbols

上级 b9309b47
......@@ -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
\ No newline at end of file
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册