Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
8377646d
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,发现更多精彩内容 >>
提交
8377646d
编写于
10月 02, 2009
作者:
T
Taryn East
提交者:
Joshua Peek
10月 02, 2009
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add indifferent access to the attributes
Signed-off-by:
N
Joshua Peek
<
josh@joshpeek.com
>
上级
f4f68885
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
30 addition
and
1 deletion
+30
-1
activeresource/lib/active_resource/base.rb
activeresource/lib/active_resource/base.rb
+2
-1
activeresource/test/cases/base/load_test.rb
activeresource/test/cases/base/load_test.rb
+13
-0
activeresource/test/cases/base_test.rb
activeresource/test/cases/base_test.rb
+15
-0
未找到文件。
activeresource/lib/active_resource/base.rb
浏览文件 @
8377646d
require
'active_support'
require
'active_support/core_ext/class/attribute_accessors'
require
'active_support/core_ext/class/inheritable_attributes'
require
'active_support/core_ext/hash/indifferent_access'
require
'active_support/core_ext/kernel/reporting'
require
'active_support/core_ext/module/attr_accessor_with_default'
require
'active_support/core_ext/module/delegation'
...
...
@@ -770,7 +771,7 @@ def split_options(options = {})
# my_other_course = Course.new(:name => "Philosophy: Reason and Being", :lecturer => "Ralph Cling")
# my_other_course.save
def
initialize
(
attributes
=
{})
@attributes
=
{}
@attributes
=
{}
.
with_indifferent_access
@prefix_options
=
{}
load
(
attributes
)
end
...
...
activeresource/test/cases/base/load_test.rb
浏览文件 @
8377646d
...
...
@@ -68,6 +68,19 @@ def test_load_simple_hash
assert_equal
@matz
.
stringify_keys
,
@person
.
load
(
@matz
).
attributes
end
def
test_after_load_attributes_are_accessible
assert_equal
Hash
.
new
,
@person
.
attributes
assert_equal
@matz
.
stringify_keys
,
@person
.
load
(
@matz
).
attributes
assert_equal
@matz
[
:name
],
@person
.
attributes
[
'name'
]
end
def
test_after_load_attributes_are_accessible_via_indifferent_access
assert_equal
Hash
.
new
,
@person
.
attributes
assert_equal
@matz
.
stringify_keys
,
@person
.
load
(
@matz
).
attributes
assert_equal
@matz
[
:name
],
@person
.
attributes
[
'name'
]
assert_equal
@matz
[
:name
],
@person
.
attributes
[
:name
]
end
def
test_load_one_with_existing_resource
address
=
@person
.
load
(
:street_address
=>
@first_address
).
street_address
assert_kind_of
StreetAddress
,
address
...
...
activeresource/test/cases/base_test.rb
浏览文件 @
8377646d
...
...
@@ -102,6 +102,9 @@ def setup
Person
.
password
=
nil
end
########################################################################
# Tests relating to setting up the API-connection configuration
########################################################################
def
test_site_accessor_accepts_uri_or_string_argument
site
=
URI
.
parse
(
'http://localhost'
)
...
...
@@ -509,6 +512,11 @@ def test_updating_baseclass_timeout_wipes_descendent_cached_connection_objects
assert_not_equal
(
first_connection
,
second_connection
,
'Connection should be re-created'
)
end
########################################################################
# Tests for setting up remote URLs for a given model (including adding
# parameters appropriately)
########################################################################
def
test_collection_name
assert_equal
"people"
,
Person
.
collection_name
end
...
...
@@ -637,6 +645,10 @@ def test_custom_prefix
assert_equal
[
:person_id
].
to_set
,
StreetAddress
.
__send__
(
:prefix_parameters
)
end
########################################################################
# Tests basic CRUD functions (find/save/create etc)
########################################################################
def
test_respond_to
matz
=
Person
.
find
(
1
)
assert
matz
.
respond_to?
(
:name
)
...
...
@@ -910,6 +922,9 @@ def test_delete_with_410_gone
assert_raise
(
ActiveResource
::
ResourceGone
)
{
Person
.
find
(
1
)
}
end
########################################################################
# Tests the more miscelaneous helper methods
########################################################################
def
test_exists
# Class method.
assert
!
Person
.
exists?
(
nil
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录