Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
aeaab06c
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,发现更多精彩内容 >>
提交
aeaab06c
编写于
7月 30, 2010
作者:
A
Alex Le
提交者:
José Valim
8月 02, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ActiveModel::Errors json serialization to work as Rails 3b4 [#5254 state:resolved]
Signed-off-by:
N
José Valim
<
jose.valim@gmail.com
>
上级
59cf514a
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
22 addition
and
6 deletion
+22
-6
activemodel/lib/active_model/errors.rb
activemodel/lib/active_model/errors.rb
+2
-2
activemodel/test/cases/serializeration/json_serialization_test.rb
...del/test/cases/serializeration/json_serialization_test.rb
+15
-1
activemodel/test/cases/validations_test.rb
activemodel/test/cases/validations_test.rb
+5
-3
未找到文件。
activemodel/lib/active_model/errors.rb
浏览文件 @
aeaab06c
...
...
@@ -169,9 +169,9 @@ def to_xml(options={})
to_a
.
to_xml
options
.
reverse_merge
(
:root
=>
"errors"
,
:skip_types
=>
true
)
end
# Returns an
array as
JSON representation for this object.
# Returns an
ActiveSupport::OrderedHash that can be used as the
JSON representation for this object.
def
as_json
(
options
=
nil
)
to_a
self
end
# Adds +message+ to the error messages on +attribute+, which will be returned on a call to
...
...
activemodel/test/cases/serializeration/json_serialization_test.rb
浏览文件 @
aeaab06c
...
...
@@ -89,7 +89,7 @@ def setup
assert_match
%r{"preferences":
\{
"shows":"anime"
\}
}
,
json
end
test
"methds are called on object"
do
test
"meth
o
ds are called on object"
do
# Define methods on fixture.
def
@contact
.
label
;
"Has cheezburger"
;
end
def
@contact
.
favorite_quote
;
"Constraints are liberating"
;
end
...
...
@@ -102,4 +102,18 @@ def @contact.favorite_quote; "Constraints are liberating"; end
assert_match
%r{"label":"Has cheezburger"}
,
methods_json
assert_match
%r{"favorite_quote":"Constraints are liberating"}
,
methods_json
end
test
"should return OrderedHash for errors"
do
car
=
Automobile
.
new
# run the validation
car
.
valid?
hash
=
ActiveSupport
::
OrderedHash
.
new
hash
[
:make
]
=
"can't be blank"
hash
[
:model
]
=
"is too short (minimum is 2 characters)"
assert_equal
hash
.
to_json
,
car
.
errors
.
to_json
end
end
activemodel/test/cases/validations_test.rb
浏览文件 @
aeaab06c
...
...
@@ -171,8 +171,10 @@ def test_errors_conversions
assert_match
%r{<error>Title can't be blank</error>}
,
xml
assert_match
%r{<error>Content can't be blank</error>}
,
xml
json
=
t
.
errors
.
to_json
assert_equal
t
.
errors
.
to_a
.
to_json
,
json
hash
=
ActiveSupport
::
OrderedHash
.
new
hash
[
:title
]
=
"can't be blank"
hash
[
:content
]
=
"can't be blank"
assert_equal
t
.
errors
.
to_json
,
hash
.
to_json
end
def
test_validation_order
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录