Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
49b63cc4
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
49b63cc4
编写于
6月 27, 2015
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #20556 from radanskoric/improve-validation-helpers
Improve Validation Helpers' documentation comments and tests
上级
e67386a8
e5a78aaa
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
41 addition
and
7 deletion
+41
-7
activemodel/lib/active_model/validations/acceptance.rb
activemodel/lib/active_model/validations/acceptance.rb
+4
-3
activemodel/lib/active_model/validations/exclusion.rb
activemodel/lib/active_model/validations/exclusion.rb
+3
-1
activemodel/lib/active_model/validations/inclusion.rb
activemodel/lib/active_model/validations/inclusion.rb
+3
-3
activemodel/test/cases/validations/acceptance_validation_test.rb
...odel/test/cases/validations/acceptance_validation_test.rb
+14
-0
activemodel/test/cases/validations/exclusion_validation_test.rb
...model/test/cases/validations/exclusion_validation_test.rb
+17
-0
未找到文件。
activemodel/lib/active_model/validations/acceptance.rb
浏览文件 @
49b63cc4
...
...
@@ -42,9 +42,10 @@ module HelperMethods
# Configuration options:
# * <tt>:message</tt> - A custom error message (default is: "must be
# accepted").
# * <tt>:accept</tt> - Specifies value that is considered accepted.
# The default value is a string "1", which makes it easy to relate to
# an HTML checkbox. This should be set to +true+ if you are validating
# * <tt>:accept</tt> - Specifies a value that is considered accepted.
# Also accepts an array of possible values. The default value is
# an array ["1", true], which makes it easy to relate to an HTML
# checkbox. This should be set to, or include, +true+ if you are validating
# a database column, since the attribute is typecast from "1" to +true+
# before validation.
#
...
...
activemodel/lib/active_model/validations/exclusion.rb
浏览文件 @
49b63cc4
...
...
@@ -29,7 +29,9 @@ module HelperMethods
# Configuration options:
# * <tt>:in</tt> - An enumerable object of items that the value shouldn't
# be part of. This can be supplied as a proc, lambda or symbol which returns an
# enumerable. If the enumerable is a range the test is performed with
# enumerable. If the enumerable is a numerical, time or datetime range the test
# is performed with <tt>Range#cover?</tt>, otherwise with <tt>include?</tt>. When
# using a proc or lambda the instance under validation is passed as an argument.
# * <tt>:within</tt> - A synonym(or alias) for <tt>:in</tt>
# <tt>Range#cover?</tt>, otherwise with <tt>include?</tt>.
# * <tt>:message</tt> - Specifies a custom error message (default is: "is
...
...
activemodel/lib/active_model/validations/inclusion.rb
浏览文件 @
49b63cc4
...
...
@@ -28,9 +28,9 @@ module HelperMethods
# Configuration options:
# * <tt>:in</tt> - An enumerable object of available items. This can be
# supplied as a proc, lambda or symbol which returns an enumerable. If the
# enumerable is a numerical
range the test is performed with <tt>Range#cover?</tt>,
#
otherwise with <tt>include?</tt>. When using a proc or lambda the instance
# under validation is passed as an argument.
# enumerable is a numerical
, time or datetime range the test is performed
#
with <tt>Range#cover?</tt>, otherwise with <tt>include?</tt>. When using
#
a proc or lambda the instance
under validation is passed as an argument.
# * <tt>:within</tt> - A synonym(or alias) for <tt>:in</tt>
# * <tt>:message</tt> - Specifies a custom error message (default is: "is
# not included in the list").
...
...
activemodel/test/cases/validations/acceptance_validation_test.rb
浏览文件 @
49b63cc4
...
...
@@ -50,6 +50,20 @@ def test_terms_of_service_agreement_with_accept_value
assert
t
.
valid?
end
def
test_terms_of_service_agreement_with_multiple_accept_values
Topic
.
validates_acceptance_of
(
:terms_of_service
,
accept:
[
1
,
"I concur."
])
t
=
Topic
.
new
(
"title"
=>
"We should be confirmed"
,
"terms_of_service"
=>
""
)
assert
t
.
invalid?
assert_equal
[
"must be accepted"
],
t
.
errors
[
:terms_of_service
]
t
.
terms_of_service
=
1
assert
t
.
valid?
t
.
terms_of_service
=
"I concur."
assert
t
.
valid?
end
def
test_validates_acceptance_of_for_ruby_class
Person
.
validates_acceptance_of
:karma
...
...
activemodel/test/cases/validations/exclusion_validation_test.rb
浏览文件 @
49b63cc4
require
'cases/helper'
require
'active_support/core_ext/numeric/time'
require
'models/topic'
require
'models/person'
...
...
@@ -64,6 +65,22 @@ def test_validates_exclusion_of_with_lambda
assert
t
.
valid?
end
def
test_validates_exclusion_of_with_range
Topic
.
validates_exclusion_of
:content
,
in:
(
"a"
..
"g"
)
assert
Topic
.
new
(
content:
'g'
).
invalid?
assert
Topic
.
new
(
content:
'h'
).
valid?
end
def
test_validates_exclusion_of_with_time_range
Topic
.
validates_exclusion_of
:created_at
,
in:
6
.
days
.
ago
..
2
.
days
.
ago
assert
Topic
.
new
(
created_at:
5
.
days
.
ago
).
invalid?
assert
Topic
.
new
(
created_at:
3
.
days
.
ago
).
invalid?
assert
Topic
.
new
(
created_at:
7
.
days
.
ago
).
valid?
assert
Topic
.
new
(
created_at:
1
.
day
.
ago
).
valid?
end
def
test_validates_inclusion_of_with_symbol
Person
.
validates_exclusion_of
:karma
,
in: :reserved_karmas
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录