Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
83555a53
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,发现更多精彩内容 >>
提交
83555a53
编写于
5月 25, 2011
作者:
S
Sidu Ponnappa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Issue #636 - Parsing an xml file with multiple records and extra attributes (besides type) fails
上级
b1bb9d17
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
50 addition
and
1 deletion
+50
-1
activesupport/lib/active_support/core_ext/hash/conversions.rb
...vesupport/lib/active_support/core_ext/hash/conversions.rb
+1
-1
activesupport/test/core_ext/hash_ext_test.rb
activesupport/test/core_ext/hash_ext_test.rb
+49
-0
未找到文件。
activesupport/lib/active_support/core_ext/hash/conversions.rb
浏览文件 @
83555a53
...
@@ -95,7 +95,7 @@ def typecast_xml_value(value)
...
@@ -95,7 +95,7 @@ def typecast_xml_value(value)
case
value
.
class
.
to_s
case
value
.
class
.
to_s
when
'Hash'
when
'Hash'
if
value
[
'type'
]
==
'array'
if
value
[
'type'
]
==
'array'
_
,
entries
=
Array
.
wrap
(
value
.
detect
{
|
k
,
v
|
k
!=
'type'
})
_
,
entries
=
Array
.
wrap
(
value
.
detect
{
|
k
,
v
|
not
v
.
is_a?
(
String
)
})
if
entries
.
nil?
||
(
c
=
value
[
'__content__'
]
&&
c
.
blank?
)
if
entries
.
nil?
||
(
c
=
value
[
'__content__'
]
&&
c
.
blank?
)
[]
[]
else
else
...
...
activesupport/test/core_ext/hash_ext_test.rb
浏览文件 @
83555a53
...
@@ -670,6 +670,55 @@ def test_timezoned_attributes
...
@@ -670,6 +670,55 @@ def test_timezoned_attributes
assert_match
%r{<local-created-at type=
\"
datetime
\"
>1999-02-01T19:00:00-05:00</local-created-at>}
,
xml
assert_match
%r{<local-created-at type=
\"
datetime
\"
>1999-02-01T19:00:00-05:00</local-created-at>}
,
xml
end
end
def
test_multiple_records_from_xml_with_attributes_other_than_type_ignores_them_without_exploding
topics_xml
=
<<-
EOT
<topics type="array" page="1" page-count="1000" per-page="2">
<topic>
<title>The First Topic</title>
<author-name>David</author-name>
<id type="integer">1</id>
<approved type="boolean">false</approved>
<replies-count type="integer">0</replies-count>
<replies-close-in type="integer">2592000000</replies-close-in>
<written-on type="date">2003-07-16</written-on>
<viewed-at type="datetime">2003-07-16T09:28:00+0000</viewed-at>
<content>Have a nice day</content>
<author-email-address>david@loudthinking.com</author-email-address>
<parent-id nil="true"></parent-id>
</topic>
<topic>
<title>The Second Topic</title>
<author-name>Jason</author-name>
<id type="integer">1</id>
<approved type="boolean">false</approved>
<replies-count type="integer">0</replies-count>
<replies-close-in type="integer">2592000000</replies-close-in>
<written-on type="date">2003-07-16</written-on>
<viewed-at type="datetime">2003-07-16T09:28:00+0000</viewed-at>
<content>Have a nice day</content>
<author-email-address>david@loudthinking.com</author-email-address>
<parent-id></parent-id>
</topic>
</topics>
EOT
expected_topic_hash
=
{
:title
=>
"The First Topic"
,
:author_name
=>
"David"
,
:id
=>
1
,
:approved
=>
false
,
:replies_count
=>
0
,
:replies_close_in
=>
2592000000
,
:written_on
=>
Date
.
new
(
2003
,
7
,
16
),
:viewed_at
=>
Time
.
utc
(
2003
,
7
,
16
,
9
,
28
),
:content
=>
"Have a nice day"
,
:author_email_address
=>
"david@loudthinking.com"
,
:parent_id
=>
nil
}.
stringify_keys
assert_equal
expected_topic_hash
,
Hash
.
from_xml
(
topics_xml
)[
"topics"
].
first
end
def
test_single_record_from_xml
def
test_single_record_from_xml
topic_xml
=
<<-
EOT
topic_xml
=
<<-
EOT
<topic>
<topic>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录