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

Fix typo by renaming :genre to :gender.

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