Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
89630a7c
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,发现更多精彩内容 >>
提交
89630a7c
编写于
10月 02, 2009
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cleanup whitespace introduced in
8377646d
and
f4f68885
上级
8377646d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
47 addition
and
55 deletion
+47
-55
activeresource/lib/active_resource/base.rb
activeresource/lib/active_resource/base.rb
+34
-35
activeresource/test/cases/base/load_test.rb
activeresource/test/cases/base/load_test.rb
+9
-16
activeresource/test/cases/base_test.rb
activeresource/test/cases/base_test.rb
+4
-4
未找到文件。
activeresource/lib/active_resource/base.rb
浏览文件 @
89630a7c
...
...
@@ -156,7 +156,7 @@ module ActiveResource
#
# <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:
#
#
# * 200..399 - Valid response, no exception (other than 301, 302)
# * 301, 302 - ActiveResource::Redirection
# * 400 - ActiveResource::BadRequest
...
...
@@ -415,7 +415,7 @@ def headers
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>)
# This method is regenerated at runtime based on what the \prefix is set to.
def
prefix
(
options
=
{})
...
...
@@ -916,7 +916,7 @@ def dup
def
save
new?
?
create
:
update
end
# Saves the resource.
#
# If the resource is new, it is created via +POST+, otherwise the
...
...
@@ -925,7 +925,7 @@ def save
# With <tt>save!</tt> validations always run. If any of them fail
# ActiveResource::ResourceInvalid gets raised, and nothing is POSTed to
# the remote system.
# See ActiveResource::Validations for more information.
# See ActiveResource::Validations for more information.
#
# There's a series of callbacks associated with <tt>save!</tt>. If any
# of the <tt>before_*</tt> callbacks return +false+ the action is
...
...
@@ -1100,36 +1100,36 @@ def load(attributes)
self
end
# Updates a single attribute and then saves the object.
#
# Note: Unlike ActiveRecord::Base.update_attribute, this method <b>is</b>
# subject to normal validation routines as an update sends the whole body
# of the resource in the request. (See Validations).
#
# As such, this method is equivalent to calling update_attributes with a single attribute/value pair.
#
# If the saving fails because of a connection or remote service error, an
# exception will be raised. If saving fails because the resource is
# invalid then <tt>false</tt> will be returned.
def
update_attribute
(
name
,
value
)
self
.
send
(
"
#{
name
}
="
.
to_sym
,
value
)
self
.
save
end
# Updates this resource with all the attributes from the passed-in Hash
# and requests that the record be saved.
#
# If the saving fails because of a connection or remote service error, an
# exception will be raised. If saving fails because the resource is
# invalid then <tt>false</tt> will be returned.
#
# Note: Though this request can be made with a partial set of the
# resource's attributes, the full body of the request will still be sent
# in the save request to the remote service.
def
update_attributes
(
attributes
)
load
(
attributes
)
&&
save
end
# Updates a single attribute and then saves the object.
#
# Note: Unlike ActiveRecord::Base.update_attribute, this method <b>is</b>
# subject to normal validation routines as an update sends the whole body
# of the resource in the request. (See Validations).
#
# As such, this method is equivalent to calling update_attributes with a single attribute/value pair.
#
# If the saving fails because of a connection or remote service error, an
# exception will be raised. If saving fails because the resource is
# invalid then <tt>false</tt> will be returned.
def
update_attribute
(
name
,
value
)
self
.
send
(
"
#{
name
}
="
.
to_sym
,
value
)
self
.
save
end
# Updates this resource with all the attributes from the passed-in Hash
# and requests that the record be saved.
#
# If the saving fails because of a connection or remote service error, an
# exception will be raised. If saving fails because the resource is
# invalid then <tt>false</tt> will be returned.
#
# Note: Though this request can be made with a partial set of the
# resource's attributes, the full body of the request will still be sent
# in the save request to the remote service.
def
update_attributes
(
attributes
)
load
(
attributes
)
&&
save
end
# For checking <tt>respond_to?</tt> without searching the attributes (which is faster).
alias_method
:respond_to_without_attributes?
,
:respond_to?
...
...
@@ -1150,7 +1150,6 @@ def respond_to?(method, include_priv = false)
super
end
protected
def
connection
(
refresh
=
false
)
self
.
class
.
connection
(
refresh
)
...
...
activeresource/test/cases/base/load_test.rb
浏览文件 @
89630a7c
...
...
@@ -15,26 +15,21 @@ class Comment < ActiveResource::Base
module
Deeply
module
Nested
class
Note
<
ActiveResource
::
Base
self
.
site
=
"http://37s.sunrise.i:3000"
end
class
Comment
<
ActiveResource
::
Base
self
.
site
=
"http://37s.sunrise.i:3000"
end
module
TestDifferentLevels
class
Note
<
ActiveResource
::
Base
self
.
site
=
"http://37s.sunrise.i:3000"
end
end
class
Comment
<
ActiveResource
::
Base
self
.
site
=
"http://37s.sunrise.i:3000"
end
module
TestDifferentLevels
class
Note
<
ActiveResource
::
Base
self
.
site
=
"http://37s.sunrise.i:3000"
end
end
end
end
end
...
...
@@ -156,7 +151,7 @@ def test_recursively_loaded_collections
assert_kind_of
String
,
places
.
first
assert_equal
@deep
[
:street
][
:state
][
:places
].
first
,
places
.
first
end
def
test_nested_collections_within_the_same_namespace
n
=
Highrise
::
Note
.
new
(
:comments
=>
[{
:name
=>
"1"
}])
assert_kind_of
Highrise
::
Comment
,
n
.
comments
.
first
...
...
@@ -171,6 +166,4 @@ def test_nested_collections_in_different_levels_of_namespaces
n
=
Highrise
::
Deeply
::
Nested
::
TestDifferentLevels
::
Note
.
new
(
:comments
=>
[{
:name
=>
"1"
}])
assert_kind_of
Highrise
::
Deeply
::
Nested
::
Comment
,
n
.
comments
.
first
end
end
activeresource/test/cases/base_test.rb
浏览文件 @
89630a7c
...
...
@@ -828,7 +828,7 @@ def test_update_conflict
######
# update_attribute(s)(!)
def
test_update_attribute_as_symbol
matz
=
Person
.
first
matz
.
expects
(
:save
).
returns
(
true
)
...
...
@@ -837,7 +837,7 @@ def test_update_attribute_as_symbol
assert
matz
.
update_attribute
(
:name
,
"David"
)
assert_equal
"David"
,
matz
.
name
end
def
test_update_attribute_as_string
matz
=
Person
.
first
matz
.
expects
(
:save
).
returns
(
true
)
...
...
@@ -847,7 +847,7 @@ def test_update_attribute_as_string
assert_equal
"David"
,
matz
.
name
end
def
test_update_attributes_as_symbols
addy
=
StreetAddress
.
first
(
:params
=>
{
:person_id
=>
1
})
addy
.
expects
(
:save
).
returns
(
true
)
...
...
@@ -913,7 +913,7 @@ def test_delete_with_custom_prefix
end
assert_raise
(
ActiveResource
::
ResourceNotFound
)
{
StreetAddress
.
find
(
1
,
:params
=>
{
:person_id
=>
1
})
}
end
def
test_delete_with_410_gone
assert
Person
.
delete
(
1
)
ActiveResource
::
HttpMock
.
respond_to
do
|
mock
|
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录