Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
7efb1fea
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,发现更多精彩内容 >>
提交
7efb1fea
编写于
10月 19, 2012
作者:
J
Jon Leighton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename the partial_updates config to partial_writes
This reflects the fact that it now impact inserts as well as updates.
上级
0096f53b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
53 addition
and
23 deletion
+53
-23
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+4
-0
activerecord/lib/active_record/attribute_methods/dirty.rb
activerecord/lib/active_record/attribute_methods/dirty.rb
+18
-6
activerecord/lib/active_record/timestamp.rb
activerecord/lib/active_record/timestamp.rb
+1
-1
activerecord/test/cases/autosave_association_test.rb
activerecord/test/cases/autosave_association_test.rb
+1
-1
activerecord/test/cases/dirty_test.rb
activerecord/test/cases/dirty_test.rb
+29
-15
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
7efb1fea
...
...
@@ -112,6 +112,10 @@
app processes (so long as the code in those processes doesn't
contain any references to the removed column).
The `partial_updates` configuration option is now renamed to
`partial_writes` to reflect the fact that it now impacts both inserts
and updates.
*Jon Leighton*
*
Allow before and after validations to take an array of lifecycle events
...
...
activerecord/lib/active_record/attribute_methods/dirty.rb
浏览文件 @
7efb1fea
require
'active_support/core_ext/module/attribute_accessors'
require
'active_support/deprecation'
module
ActiveRecord
ActiveSupport
.
on_load
(
:active_record_config
)
do
mattr_accessor
:partial_
upda
tes
,
instance_accessor:
false
self
.
partial_
upda
tes
=
true
mattr_accessor
:partial_
wri
tes
,
instance_accessor:
false
self
.
partial_
wri
tes
=
true
end
module
AttributeMethods
...
...
@@ -17,7 +18,18 @@ module Dirty # :nodoc:
raise
"You cannot include Dirty after Timestamp"
end
config_attribute
:partial_updates
config_attribute
:partial_writes
def
self
.
partial_updates
=
(
v
);
self
.
partial_writes
=
v
;
end
def
self
.
partial_updates?
;
partial_writes?
;
end
def
self
.
partial_updates
;
partial_writes
;
end
ActiveSupport
::
Deprecation
.
deprecate_methods
(
singleton_class
,
:partial_updates
=
=>
:partial_writes
=
,
:partial_updates?
=>
:partial_writes?
,
:partial_updates
=>
:partial_writes
)
end
# Attempts to +save+ the record and clears changed attributes if successful.
...
...
@@ -64,16 +76,16 @@ def write_attribute(attr, value)
end
def
update
(
*
)
partial_
updates?
?
super
(
keys_for_partial_upda
te
)
:
super
partial_
writes?
?
super
(
keys_for_partial_wri
te
)
:
super
end
def
create
(
*
)
partial_
updates?
?
super
(
keys_for_partial_upda
te
)
:
super
partial_
writes?
?
super
(
keys_for_partial_wri
te
)
:
super
end
# Serialized attributes should always be written in case they've been
# changed in place.
def
keys_for_partial_
upda
te
def
keys_for_partial_
wri
te
changed
|
(
attributes
.
keys
&
self
.
class
.
serialized_attributes
.
keys
)
end
...
...
activerecord/lib/active_record/timestamp.rb
浏览文件 @
7efb1fea
...
...
@@ -75,7 +75,7 @@ def update(*args)
end
def
should_record_timestamps?
self
.
record_timestamps
&&
(
!
partial_
upda
tes?
||
changed?
||
(
attributes
.
keys
&
self
.
class
.
serialized_attributes
.
keys
).
present?
)
self
.
record_timestamps
&&
(
!
partial_
wri
tes?
||
changed?
||
(
attributes
.
keys
&
self
.
class
.
serialized_attributes
.
keys
).
present?
)
end
def
timestamp_attributes_for_create_in_model
...
...
activerecord/test/cases/autosave_association_test.rb
浏览文件 @
7efb1fea
...
...
@@ -144,7 +144,7 @@ def test_not_resaved_when_unchanged
firm
=
Firm
.
first
firm
.
account
=
Account
.
first
assert_queries
(
Firm
.
partial_
upda
tes?
?
0
:
1
)
{
firm
.
save!
}
assert_queries
(
Firm
.
partial_
wri
tes?
?
0
:
1
)
{
firm
.
save!
}
firm
=
Firm
.
first
.
dup
firm
.
account
=
Account
.
first
...
...
activerecord/test/cases/dirty_test.rb
浏览文件 @
7efb1fea
...
...
@@ -311,12 +311,12 @@ def test_partial_update
pirate
=
Pirate
.
new
(
:catchphrase
=>
'foo'
)
old_updated_on
=
1
.
hour
.
ago
.
beginning_of_day
with_partial_
upda
tes
Pirate
,
false
do
with_partial_
wri
tes
Pirate
,
false
do
assert_queries
(
2
)
{
2
.
times
{
pirate
.
save!
}
}
Pirate
.
where
(
id:
pirate
.
id
).
update_all
(
:updated_on
=>
old_updated_on
)
end
with_partial_
upda
tes
Pirate
,
true
do
with_partial_
wri
tes
Pirate
,
true
do
assert_queries
(
0
)
{
2
.
times
{
pirate
.
save!
}
}
assert_equal
old_updated_on
,
pirate
.
reload
.
updated_on
...
...
@@ -329,12 +329,12 @@ def test_partial_update_with_optimistic_locking
person
=
Person
.
new
(
:first_name
=>
'foo'
)
old_lock_version
=
1
with_partial_
upda
tes
Person
,
false
do
with_partial_
wri
tes
Person
,
false
do
assert_queries
(
2
)
{
2
.
times
{
person
.
save!
}
}
Person
.
where
(
id:
person
.
id
).
update_all
(
:first_name
=>
'baz'
)
end
with_partial_
upda
tes
Person
,
true
do
with_partial_
wri
tes
Person
,
true
do
assert_queries
(
0
)
{
2
.
times
{
person
.
save!
}
}
assert_equal
old_lock_version
,
person
.
reload
.
lock_version
...
...
@@ -408,8 +408,8 @@ def test_reverted_changes_are_not_dirty_going_from_nil_to_value_and_back
assert
!
pirate
.
catchphrase_changed?
end
def
test_save_should_store_serialized_attributes_even_with_partial_
upda
tes
with_partial_
upda
tes
(
Topic
)
do
def
test_save_should_store_serialized_attributes_even_with_partial_
wri
tes
with_partial_
wri
tes
(
Topic
)
do
topic
=
Topic
.
create!
(
:content
=>
{
:a
=>
"a"
})
topic
.
content
[
:b
]
=
"b"
#assert topic.changed? # Known bug, will fail
...
...
@@ -421,7 +421,7 @@ def test_save_should_store_serialized_attributes_even_with_partial_updates
end
def
test_save_always_should_update_timestamps_when_serialized_attributes_are_present
with_partial_
upda
tes
(
Topic
)
do
with_partial_
wri
tes
(
Topic
)
do
topic
=
Topic
.
create!
(
:content
=>
{
:a
=>
"a"
})
topic
.
save!
...
...
@@ -434,8 +434,8 @@ def test_save_always_should_update_timestamps_when_serialized_attributes_are_pre
end
end
def
test_save_should_not_save_serialized_attribute_with_partial_
upda
tes_if_not_present
with_partial_
upda
tes
(
Topic
)
do
def
test_save_should_not_save_serialized_attribute_with_partial_
wri
tes_if_not_present
with_partial_
wri
tes
(
Topic
)
do
Topic
.
create!
(
:author_name
=>
'Bill'
,
:content
=>
{
:a
=>
"a"
})
topic
=
Topic
.
select
(
'id, author_name'
).
first
topic
.
update_columns
author_name:
'John'
...
...
@@ -552,7 +552,7 @@ def test_setting_time_attributes_with_time_zone_field_to_same_time_should_not_be
end
test
"partial insert"
do
with_partial_
upda
tes
Person
do
with_partial_
wri
tes
Person
do
jon
=
nil
assert_sql
(
/first_name/i
)
do
jon
=
Person
.
create!
first_name:
'Jon'
...
...
@@ -568,20 +568,34 @@ def test_setting_time_attributes_with_time_zone_field_to_same_time_should_not_be
end
test
"partial insert with empty values"
do
with_partial_
upda
tes
Aircraft
do
with_partial_
wri
tes
Aircraft
do
a
=
Aircraft
.
create!
a
.
reload
assert_not_nil
a
.
id
end
end
test
"partial_updates config attribute is deprecated"
do
klass
=
Class
.
new
(
ActiveRecord
::
Base
)
assert
klass
.
partial_writes?
assert_deprecated
{
assert
klass
.
partial_updates?
}
assert_deprecated
{
assert
klass
.
partial_updates
}
assert_deprecated
{
klass
.
partial_updates
=
false
}
assert
!
klass
.
partial_writes?
assert_deprecated
{
assert
!
klass
.
partial_updates?
}
assert_deprecated
{
assert
!
klass
.
partial_updates
}
end
private
def
with_partial_
upda
tes
(
klass
,
on
=
true
)
old
=
klass
.
partial_
upda
tes?
klass
.
partial_
upda
tes
=
on
def
with_partial_
wri
tes
(
klass
,
on
=
true
)
old
=
klass
.
partial_
wri
tes?
klass
.
partial_
wri
tes
=
on
yield
ensure
klass
.
partial_
upda
tes
=
old
klass
.
partial_
wri
tes
=
old
end
def
check_pirate_after_save_failure
(
pirate
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录