提交 017f5d53 编写于 作者: J José Valim

Fix typo by renaming :genre to :gender.

上级 93898b38
......@@ -54,7 +54,7 @@ module ClassMethods
# The validators hash can also handle regular expressions, ranges and arrays:
#
# validates :email, :format => /@/
# validates :genre, :inclusion => %w(mail female)
# validates :gender, :inclusion => %w(mail female)
# validates :password, :length => 6..20
#
# Finally, the options :if, :unless, :on, :allow_blank and :allow_nil can be given
......
......@@ -70,20 +70,20 @@ def test_validates_with_regexp
end
def test_validates_with_array
Person.validates :genre, :inclusion => %w(m f)
Person.validates :gender, :inclusion => %w(m f)
person = Person.new
assert person.invalid?
assert_equal ['is not included in the list'], person.errors[:genre]
person.genre = "m"
assert_equal ['is not included in the list'], person.errors[:gender]
person.gender = "m"
assert person.valid?
end
def test_validates_with_range
Person.validates :password, :length => 6..20
Person.validates :karma, :length => 6..20
person = Person.new
assert person.invalid?
assert_equal ['is too short (minimum is 6 characters)'], person.errors[:password]
person.password = '123456'
assert_equal ['is too short (minimum is 6 characters)'], person.errors[:karma]
person.karma = 'something'
assert person.valid?
end
......
......@@ -2,7 +2,7 @@ class Person
include ActiveModel::Validations
extend ActiveModel::Translation
attr_accessor :title, :karma, :salary, :genre, :password
attr_accessor :title, :karma, :salary, :gender
def condition_is_true
true
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册