Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b5eb3215
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 搜索 >>
提交
b5eb3215
编写于
4月 04, 2017
作者:
B
bogdanvlviv
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix inconsistency with changed attributes when overriding AR attribute reader
上级
2b4583f2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
35 addition
and
4 deletion
+35
-4
activemodel/lib/active_model/dirty.rb
activemodel/lib/active_model/dirty.rb
+8
-4
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+4
-0
activerecord/lib/active_record/attribute_methods/dirty.rb
activerecord/lib/active_record/attribute_methods/dirty.rb
+4
-0
activerecord/test/cases/dirty_test.rb
activerecord/test/cases/dirty_test.rb
+19
-0
未找到文件。
activemodel/lib/active_model/dirty.rb
浏览文件 @
b5eb3215
...
...
@@ -179,13 +179,13 @@ def changed_attributes
# Handles <tt>*_changed?</tt> for +method_missing+.
def
attribute_changed?
(
attr
,
from:
OPTION_NOT_GIVEN
,
to:
OPTION_NOT_GIVEN
)
# :nodoc:
!!
changes_include?
(
attr
)
&&
(
to
==
OPTION_NOT_GIVEN
||
to
==
_
_send__
(
attr
))
&&
(
to
==
OPTION_NOT_GIVEN
||
to
==
_
attributes
(
attr
))
&&
(
from
==
OPTION_NOT_GIVEN
||
from
==
changed_attributes
[
attr
])
end
# Handles <tt>*_was</tt> for +method_missing+.
def
attribute_was
(
attr
)
# :nodoc:
attribute_changed?
(
attr
)
?
changed_attributes
[
attr
]
:
_
_send__
(
attr
)
attribute_changed?
(
attr
)
?
changed_attributes
[
attr
]
:
_
attributes
(
attr
)
end
# Handles <tt>*_previously_changed?</tt> for +method_missing+.
...
...
@@ -226,7 +226,7 @@ def clear_changes_information # :doc:
# Handles <tt>*_change</tt> for +method_missing+.
def
attribute_change
(
attr
)
[
changed_attributes
[
attr
],
_
_send__
(
attr
)]
if
attribute_changed?
(
attr
)
[
changed_attributes
[
attr
],
_
attributes
(
attr
)]
if
attribute_changed?
(
attr
)
end
# Handles <tt>*_previous_change</tt> for +method_missing+.
...
...
@@ -239,7 +239,7 @@ def attribute_will_change!(attr)
return
if
attribute_changed?
(
attr
)
begin
value
=
_
_send__
(
attr
)
value
=
_
attributes
(
attr
)
value
=
value
.
duplicable?
?
value
.
clone
:
value
rescue
TypeError
,
NoMethodError
end
...
...
@@ -268,5 +268,9 @@ def set_attribute_was(attr, old_value)
def
clear_attribute_changes
(
attributes
)
# :doc:
attributes_changed_by_setter
.
except!
(
*
attributes
)
end
def
_attributes
(
attr
)
__send__
(
attr
)
end
end
end
activerecord/CHANGELOG.md
浏览文件 @
b5eb3215
*
Fix inconsistency with changed attributes when overriding AR attribute reader.
*bogdanvlviv*
*
When calling the dynamic fixture accessor method with no arguments it now returns all fixtures of this type.
Previously this method always returned an empty array.
...
...
activerecord/lib/active_record/attribute_methods/dirty.rb
浏览文件 @
b5eb3215
...
...
@@ -328,6 +328,10 @@ def cache_changed_attributes
def
clear_changed_attributes_cache
remove_instance_variable
(
:@cached_changed_attributes
)
if
defined?
(
@cached_changed_attributes
)
end
def
_attributes
(
attr
)
_read_attribute
(
attr
)
end
end
end
end
activerecord/test/cases/dirty_test.rb
浏览文件 @
b5eb3215
...
...
@@ -671,6 +671,25 @@ def test_datetime_attribute_doesnt_change_if_zone_is_modified_in_string
assert
binary
.
changed?
end
test
"changes is correct if override attribute reader"
do
pirate
=
Pirate
.
create!
(
catchphrase:
"arrrr"
)
def
pirate
.
catchphrase
super
.
upcase
end
new_catchphrase
=
"arrrr matey!"
pirate
.
catchphrase
=
new_catchphrase
assert
pirate
.
catchphrase_changed?
expected_changes
=
{
"catchphrase"
=>
[
"arrrr"
,
new_catchphrase
]
}
assert_equal
new_catchphrase
.
upcase
,
pirate
.
catchphrase
assert_equal
expected_changes
,
pirate
.
changes
end
test
"attribute_changed? doesn't compute in-place changes for unrelated attributes"
do
test_type_class
=
Class
.
new
(
ActiveRecord
::
Type
::
Value
)
do
define_method
(
:changed_in_place?
)
do
|*|
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录