Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
bea3c268
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,发现更多精彩内容 >>
提交
bea3c268
编写于
5月 06, 2010
作者:
S
Santiago Pastorino
提交者:
Jeremy Kemper
5月 12, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make ActiveResource serialize XML correctly when element_name is set.
[#4529] Signed-off-by:
N
Jeremy Kemper
<
jeremy@bitsweat.net
>
上级
f7862b2c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
54 addition
and
7 deletion
+54
-7
activemodel/lib/active_model/serializers/xml.rb
activemodel/lib/active_model/serializers/xml.rb
+1
-1
activemodel/test/cases/serializeration/xml_serialization_test.rb
...odel/test/cases/serializeration/xml_serialization_test.rb
+2
-2
activeresource/lib/active_resource/base.rb
activeresource/lib/active_resource/base.rb
+15
-4
activeresource/test/cases/base_test.rb
activeresource/test/cases/base_test.rb
+36
-0
未找到文件。
activemodel/lib/active_model/serializers/xml.rb
浏览文件 @
bea3c268
...
...
@@ -90,7 +90,7 @@ def serialize
@builder
=
options
[
:builder
]
@builder
.
instruct!
unless
options
[
:skip_instruct
]
root
=
(
options
[
:root
]
||
@serializable
.
class
.
model_name
.
singular
).
to_s
root
=
(
options
[
:root
]
||
@serializable
.
class
.
model_name
.
element
).
to_s
root
=
ActiveSupport
::
XmlMini
.
rename_key
(
root
,
options
)
args
=
[
root
]
...
...
activemodel/test/cases/serializeration/xml_serialization_test.rb
浏览文件 @
bea3c268
...
...
@@ -37,8 +37,8 @@ def setup
test
"should serialize namespaced root"
do
@xml
=
Admin
::
Contact
.
new
(
@contact
.
attributes
).
to_xml
assert_match
%r{^<
admin-
contact>}
,
@xml
assert_match
%r{</
admin-
contact>$}
,
@xml
assert_match
%r{^<contact>}
,
@xml
assert_match
%r{</contact>$}
,
@xml
end
test
"should serialize default root with namespace"
do
...
...
activeresource/lib/active_resource/base.rb
浏览文件 @
bea3c268
...
...
@@ -551,11 +551,22 @@ def headers
@headers
||=
{}
end
# Do not include any modules in the default element name. This makes it easier to seclude ARes objects
# in a separate namespace without having to set element_name repeatedly.
attr_accessor_with_default
(
:element_name
)
{
ActiveSupport
::
Inflector
.
underscore
(
to_s
.
split
(
"::"
).
last
)
}
#:nodoc:
def
element_name
model_name
.
element
end
def
element_name
=
(
value
)
model_name
.
element
=
value
end
def
collection_name
model_name
.
collection
end
def
collection_name
=
(
value
)
model_name
.
collection
=
value
end
attr_accessor_with_default
(
:collection_name
)
{
ActiveSupport
::
Inflector
.
pluralize
(
element_name
)
}
#:nodoc:
attr_accessor_with_default
(
:primary_key
,
'id'
)
#:nodoc:
# Gets the \prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.xml</tt>)
...
...
activeresource/test/cases/base_test.rb
浏览文件 @
bea3c268
...
...
@@ -1018,6 +1018,23 @@ def test_to_xml
assert
xml
.
include?
(
'<id type="integer">1</id>'
)
end
def
test_to_xml_with_element_name
old_elem_name
=
Person
.
element_name
matz
=
Person
.
find
(
1
)
Person
.
element_name
=
'ruby_creator'
encode
=
matz
.
encode
xml
=
matz
.
to_xml
assert
encode
,
xml
assert
xml
.
include?
(
'<?xml version="1.0" encoding="UTF-8"?>'
)
assert
xml
.
include?
(
'<ruby-creator>'
)
assert
xml
.
include?
(
'<name>Matz</name>'
)
assert
xml
.
include?
(
'<id type="integer">1</id>'
)
assert
xml
.
include?
(
'</ruby-creator>'
)
ensure
Person
.
element_name
=
old_elem_name
end
def
test_to_json
Person
.
include_root_in_json
=
true
Person
.
format
=
:json
...
...
@@ -1033,6 +1050,25 @@ def test_to_json
assert_match
%r{
\}\}\}
$}
,
json
end
def
test_to_json_with_element_name
old_elem_name
=
Person
.
element_name
Person
.
include_root_in_json
=
true
Person
.
format
=
:json
joe
=
Person
.
find
(
6
)
Person
.
element_name
=
'ruby_creator'
encode
=
joe
.
encode
json
=
joe
.
to_json
Person
.
format
=
:xml
assert
encode
,
json
assert_match
%r{^
\{
"ruby_creator":
\{
"person":
\{
}
,
json
assert_match
%r{"id":6}
,
json
assert_match
%r{"name":"Joe"}
,
json
assert_match
%r{
\}\}\}
$}
,
json
ensure
Person
.
element_name
=
old_elem_name
end
def
test_to_param_quacks_like_active_record
new_person
=
Person
.
new
assert_nil
new_person
.
to_param
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录