Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
20f943ff
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,发现更多精彩内容 >>
提交
20f943ff
编写于
9月 05, 2012
作者:
M
Matt Jones
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
correctly flag changed attributes in AR::Store, combine multiple calls to store_accessor
上级
27acd1e0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
12 addition
and
4 deletion
+12
-4
activerecord/lib/active_record/store.rb
activerecord/lib/active_record/store.rb
+3
-2
activerecord/test/cases/store_test.rb
activerecord/test/cases/store_test.rb
+8
-2
activerecord/test/models/admin/user.rb
activerecord/test/models/admin/user.rb
+1
-0
未找到文件。
activerecord/lib/active_record/store.rb
浏览文件 @
20f943ff
...
...
@@ -57,8 +57,8 @@ def store_accessor(store_attribute, *keys)
define_method
(
"
#{
key
}
="
)
do
|
value
|
attribute
=
initialize_store_attribute
(
store_attribute
)
if
value
!=
attribute
[
key
]
attribute
[
key
]
=
value
send
:"
#{
store_attribute
}
_will_change!"
attribute
[
key
]
=
value
end
end
...
...
@@ -67,7 +67,8 @@ def store_accessor(store_attribute, *keys)
end
end
self
.
stored_attributes
[
store_attribute
]
=
keys
self
.
stored_attributes
[
store_attribute
]
||=
[]
self
.
stored_attributes
[
store_attribute
]
|=
keys
end
end
...
...
activerecord/test/cases/store_test.rb
浏览文件 @
20f943ff
...
...
@@ -34,6 +34,12 @@ class StoreTest < ActiveRecord::TestCase
assert
@john
.
settings_changed?
end
test
"updating the store populates the changed array correctly"
do
@john
.
color
=
'red'
assert_equal
'black'
,
@john
.
settings_change
[
0
][
'color'
]
assert_equal
'red'
,
@john
.
settings_change
[
1
][
'color'
]
end
test
"updating the store won't mark it as changed if an attribute isn't changed"
do
@john
.
color
=
@john
.
color
assert
!
@john
.
settings_changed?
...
...
@@ -117,8 +123,8 @@ class StoreTest < ActiveRecord::TestCase
assert_equal
false
,
@john
.
is_a_good_guy
end
test
"stored attributes are returned"
do
assert_equal
[
:color
,
:homepage
],
Admin
::
User
.
stored_attributes
[
:settings
]
test
"
all
stored attributes are returned"
do
assert_equal
[
:color
,
:homepage
,
:favorite_food
],
Admin
::
User
.
stored_attributes
[
:settings
]
end
test
"stores_attributes are class level settings"
do
...
...
activerecord/test/models/admin/user.rb
浏览文件 @
20f943ff
class
Admin::User
<
ActiveRecord
::
Base
belongs_to
:account
store
:settings
,
:accessors
=>
[
:color
,
:homepage
]
store_accessor
:settings
,
:favorite_food
store
:preferences
,
:accessors
=>
[
:remember_login
]
store
:json_data
,
:accessors
=>
[
:height
,
:weight
],
:coder
=>
JSON
store
:json_data_empty
,
:accessors
=>
[
:is_a_good_guy
],
:coder
=>
JSON
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录