Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
8be911c6
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,体验更适合开发者的 AI 搜索 >>
提交
8be911c6
编写于
9月 27, 2010
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge remote branch 'gramos/ares-missing-prefix-value'
上级
8aa3684e
f85b38a3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
41 addition
and
1 deletion
+41
-1
activeresource/lib/active_resource/base.rb
activeresource/lib/active_resource/base.rb
+22
-0
activeresource/lib/active_resource/exceptions.rb
activeresource/lib/active_resource/exceptions.rb
+3
-0
activeresource/test/abstract_unit.rb
activeresource/test/abstract_unit.rb
+1
-0
activeresource/test/cases/base_test.rb
activeresource/test/cases/base_test.rb
+14
-0
activeresource/test/cases/finder_test.rb
activeresource/test/cases/finder_test.rb
+1
-1
未找到文件。
activeresource/lib/active_resource/base.rb
浏览文件 @
8be911c6
...
...
@@ -166,6 +166,7 @@ module ActiveResource
# # GET http://api.people.com:3000/people/999.xml
# ryan = Person.find(999) # 404, raises ActiveResource::ResourceNotFound
#
#
# <tt>404</tt> is just one of the HTTP error response codes that Active Resource will handle with its own exception. The
# following HTTP response codes will also result in these exceptions:
#
...
...
@@ -194,6 +195,16 @@ module ActiveResource
# redirect_to :action => 'new'
# end
#
# When a GET is requested for a nested resource and you don't provide the prefix_param
# an ActiveResource::MissingPrefixParam will be raised.
#
# class Comment < ActiveResource::Base
# self.site = "http://someip.com/posts/:post_id/"
# end
#
# Comment.find(1)
# # => ActiveResource::MissingPrefixParam: post_id prefix_option is missing
#
# === Validation errors
#
# Active Resource supports validations on resources and will return errors if any of these validations fail
...
...
@@ -621,6 +632,8 @@ def prefix(options={}) "#{prefix_call}" end
# # => /posts/5/comments/1.xml?active=1
#
def
element_path
(
id
,
prefix_options
=
{},
query_options
=
nil
)
check_prefix_options
(
prefix_options
)
prefix_options
,
query_options
=
split_options
(
prefix_options
)
if
query_options
.
nil?
"
#{
prefix
(
prefix_options
)
}#{
collection_name
}
/
#{
URI
.
escape
id
.
to_s
}
.
#{
format
.
extension
}#{
query_string
(
query_options
)
}
"
end
...
...
@@ -663,6 +676,7 @@ def new_element_path(prefix_options = {})
# # => /posts/5/comments.xml?active=1
#
def
collection_path
(
prefix_options
=
{},
query_options
=
nil
)
check_prefix_options
(
prefix_options
)
prefix_options
,
query_options
=
split_options
(
prefix_options
)
if
query_options
.
nil?
"
#{
prefix
(
prefix_options
)
}#{
collection_name
}
.
#{
format
.
extension
}#{
query_string
(
query_options
)
}
"
end
...
...
@@ -842,6 +856,14 @@ def exists?(id, options = {})
end
private
def
check_prefix_options
(
prefix_options
)
p_options
=
HashWithIndifferentAccess
.
new
(
prefix_options
)
prefix_parameters
.
each
do
|
p
|
raise
(
MissingPrefixParam
,
"
#{
p
}
prefix_option is missing"
)
if
p_options
[
p
].
blank?
end
end
# Find every resource
def
find_every
(
options
)
begin
...
...
activeresource/lib/active_resource/exceptions.rb
浏览文件 @
8be911c6
...
...
@@ -36,6 +36,9 @@ class Redirection < ConnectionError # :nodoc:
def
to_s
;
response
[
'Location'
]
?
"
#{
super
}
=>
#{
response
[
'Location'
]
}
"
:
super
;
end
end
# Raised when ...
class
MissingPrefixParam
<
ArgumentError
;
end
# :nodoc:
# 4xx Client Error
class
ClientError
<
ConnectionError
;
end
# :nodoc:
...
...
activeresource/test/abstract_unit.rb
浏览文件 @
8be911c6
...
...
@@ -97,6 +97,7 @@ def setup_response
mock
.
put
"/people/1/addresses/1.xml"
,
{},
nil
,
204
mock
.
delete
"/people/1/addresses/1.xml"
,
{},
nil
,
200
mock
.
post
"/people/1/addresses.xml"
,
{},
nil
,
201
,
'Location'
=>
'/people/1/addresses/5'
mock
.
get
"/people/1/addresses/99.xml"
,
{},
nil
,
404
mock
.
get
"/people//addresses.xml"
,
{},
nil
,
404
mock
.
get
"/people//addresses/1.xml"
,
{},
nil
,
404
mock
.
put
"/people//addresses/1.xml"
,
{},
nil
,
404
...
...
activeresource/test/cases/base_test.rb
浏览文件 @
8be911c6
...
...
@@ -475,6 +475,12 @@ def test_custom_element_path
assert_equal
'/people/ann%20mary/addresses/ann%20mary.xml'
,
StreetAddress
.
element_path
(
:'ann mary'
,
'person_id'
=>
'ann mary'
)
end
def
test_custom_element_path_without_required_prefix_param
assert_raise
ActiveResource
::
MissingPrefixParam
do
StreetAddress
.
element_path
(
1
)
end
end
def
test_module_element_path
assert_equal
'/sounds/1.xml'
,
Asset
::
Sound
.
element_path
(
1
)
end
...
...
@@ -513,6 +519,12 @@ def test_custom_element_path_with_prefix_and_parameters
assert_equal
'/people/1/addresses/1.xml?type=work'
,
StreetAddress
.
element_path
(
1
,
{
:person_id
=>
1
},
{
:type
=>
'work'
})
end
def
test_custom_collection_path_without_required_prefix_param
assert_raise
ActiveResource
::
MissingPrefixParam
do
StreetAddress
.
collection_path
end
end
def
test_custom_collection_path
assert_equal
'/people/1/addresses.xml'
,
StreetAddress
.
collection_path
(
:person_id
=>
1
)
assert_equal
'/people/1/addresses.xml'
,
StreetAddress
.
collection_path
(
'person_id'
=>
1
)
...
...
@@ -560,6 +572,8 @@ def test_set_prefix_twice_should_clear_params
assert_equal
Set
.
new
([
:the_param1
]),
person_class
.
prefix_parameters
person_class
.
prefix
=
"the_prefix/:the_param2"
assert_equal
Set
.
new
([
:the_param2
]),
person_class
.
prefix_parameters
person_class
.
prefix
=
"the_prefix/:the_param1/other_prefix/:the_param2"
assert_equal
Set
.
new
([
:the_param2
,
:the_param1
]),
person_class
.
prefix_parameters
end
end
...
...
activeresource/test/cases/finder_test.rb
浏览文件 @
8be911c6
...
...
@@ -84,7 +84,7 @@ def test_last_with_params
def
test_find_by_id_not_found
assert_raise
(
ActiveResource
::
ResourceNotFound
)
{
Person
.
find
(
99
)
}
assert_raise
(
ActiveResource
::
ResourceNotFound
)
{
StreetAddress
.
find
(
1
)
}
assert_raise
(
ActiveResource
::
ResourceNotFound
)
{
StreetAddress
.
find
(
99
,
:params
=>
{
:person_id
=>
1
}
)
}
end
def
test_find_all_sub_objects
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录