Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
22506570
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,发现更多精彩内容 >>
提交
22506570
编写于
6月 09, 2008
作者:
L
Luis Hurtado
提交者:
Jeremy Kemper
6月 09, 2008
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes parsing deep nested resources from XML. [#380 state:resolved]
上级
16a9787b
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
56 addition
and
1 deletion
+56
-1
activeresource/lib/active_resource/base.rb
activeresource/lib/active_resource/base.rb
+5
-1
activeresource/test/base_test.rb
activeresource/test/base_test.rb
+48
-0
activeresource/test/fixtures/customer.rb
activeresource/test/fixtures/customer.rb
+3
-0
未找到文件。
activeresource/lib/active_resource/base.rb
浏览文件 @
22506570
...
...
@@ -988,7 +988,11 @@ def find_or_create_resource_for(name)
self
.
class
.
const_get
(
resource_name
)
end
rescue
NameError
if
self
.
class
.
const_defined?
(
resource_name
)
resource
=
self
.
class
.
const_get
(
resource_name
)
else
resource
=
self
.
class
.
const_set
(
resource_name
,
Class
.
new
(
ActiveResource
::
Base
))
end
resource
.
prefix
=
self
.
class
.
prefix
resource
.
site
=
self
.
class
.
site
resource
...
...
activeresource/test/base_test.rb
浏览文件 @
22506570
require
'abstract_unit'
require
"fixtures/person"
require
"fixtures/customer"
require
"fixtures/street_address"
require
"fixtures/beast"
...
...
@@ -15,6 +16,37 @@ def setup
@people_david
=
[{
:id
=>
2
,
:name
=>
'David'
}].
to_xml
(
:root
=>
'people'
)
@addresses
=
[{
:id
=>
1
,
:street
=>
'12345 Street'
}].
to_xml
(
:root
=>
'addresses'
)
# - deep nested resource -
# - Luis (Customer)
# - JK (Customer::Friend)
# - Mateo (Customer::Friend::Brother)
# - Edith (Customer::Friend::Brother::Child)
# - Martha (Customer::Friend::Brother::Child)
# - Felipe (Customer::Friend::Brother)
# - Bryan (Customer::Friend::Brother::Child)
# - Luke (Customer::Friend::Brother::Child)
# - Eduardo (Customer::Friend)
# - Sebas (Customer::Friend::Brother)
# - Andres (Customer::Friend::Brother::Child)
# - Jorge (Customer::Friend::Brother::Child)
# - Elsa (Customer::Friend::Brother)
# - Natacha (Customer::Friend::Brother::Child)
# - Milena (Customer::Friend::Brother)
#
@luis
=
{
:id
=>
1
,
:name
=>
'Luis'
,
:friends
=>
[{
:name
=>
'JK'
,
:brothers
=>
[{
:name
=>
'Mateo'
,
:children
=>
[{
:name
=>
'Edith'
},{
:name
=>
'Martha'
}]},
{
:name
=>
'Felipe'
,
:children
=>
[{
:name
=>
'Bryan'
},{
:name
=>
'Luke'
}]}]},
{
:name
=>
'Eduardo'
,
:brothers
=>
[{
:name
=>
'Sebas'
,
:children
=>
[{
:name
=>
'Andres'
},{
:name
=>
'Jorge'
}]},
{
:name
=>
'Elsa'
,
:children
=>
[{
:name
=>
'Natacha'
}]},
{
:name
=>
'Milena'
,
:children
=>
[]}]}]}.
to_xml
(
:root
=>
'customer'
)
ActiveResource
::
HttpMock
.
respond_to
do
|
mock
|
mock
.
get
"/people/1.xml"
,
{},
@matz
mock
.
get
"/people/2.xml"
,
{},
@david
...
...
@@ -46,6 +78,8 @@ def setup
mock
.
head
"/people/1/addresses/2.xml"
,
{},
nil
,
404
mock
.
head
"/people/2/addresses/1.xml"
,
{},
nil
,
404
mock
.
head
"/people/Greg/addresses/1.xml"
,
{},
nil
,
200
# customer
mock
.
get
"/customers/1.xml"
,
{},
@luis
end
Person
.
user
=
nil
...
...
@@ -788,4 +822,18 @@ def test_to_param_quacks_like_active_record
matz
=
Person
.
find
(
1
)
assert_equal
'1'
,
matz
.
to_param
end
def
test_parse_deep_nested_resources
luis
=
Customer
.
find
(
1
)
assert_kind_of
Customer
,
luis
luis
.
friends
.
each
do
|
friend
|
assert_kind_of
Customer
::
Friend
,
friend
friend
.
brothers
.
each
do
|
brother
|
assert_kind_of
Customer
::
Friend
::
Brother
,
brother
brother
.
children
.
each
do
|
child
|
assert_kind_of
Customer
::
Friend
::
Brother
::
Child
,
child
end
end
end
end
end
activeresource/test/fixtures/customer.rb
0 → 100644
浏览文件 @
22506570
class
Customer
<
ActiveResource
::
Base
self
.
site
=
"http://37s.sunrise.i:3000"
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录