Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
577d83a5
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 搜索 >>
提交
577d83a5
编写于
1月 20, 2018
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More exercise `ActiveModel::Dirty` tests
上级
05baed07
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
24 addition
and
3 deletion
+24
-3
activemodel/test/cases/dirty_test.rb
activemodel/test/cases/dirty_test.rb
+24
-3
未找到文件。
activemodel/test/cases/dirty_test.rb
浏览文件 @
577d83a5
...
...
@@ -5,12 +5,13 @@
class
DirtyTest
<
ActiveModel
::
TestCase
class
DirtyModel
include
ActiveModel
::
Dirty
define_attribute_methods
:name
,
:color
,
:size
define_attribute_methods
:name
,
:color
,
:size
,
:status
def
initialize
@name
=
nil
@color
=
nil
@size
=
nil
@status
=
"initialized"
end
def
name
...
...
@@ -40,6 +41,15 @@ def size=(val)
@size
=
val
end
def
status
@status
end
def
status
=
(
val
)
status_will_change!
unless
val
==
@status
@status
=
val
end
def
save
changes_applied
end
...
...
@@ -135,15 +145,20 @@ def reload
test
"saving should preserve previous changes"
do
@model
.
name
=
"Jericho Cane"
@model
.
status
=
"waiting"
@model
.
save
assert_equal
[
nil
,
"Jericho Cane"
],
@model
.
previous_changes
[
"name"
]
assert_equal
[
"initialized"
,
"waiting"
],
@model
.
previous_changes
[
"status"
]
end
test
"setting new attributes should not affect previous changes"
do
@model
.
name
=
"Jericho Cane"
@model
.
status
=
"waiting"
@model
.
save
@model
.
name
=
"DudeFella ManGuy"
@model
.
status
=
"finished"
assert_equal
[
nil
,
"Jericho Cane"
],
@model
.
name_previous_change
assert_equal
[
"initialized"
,
"waiting"
],
@model
.
previous_changes
[
"status"
]
end
test
"saving should preserve model's previous changed status"
do
...
...
@@ -155,20 +170,26 @@ def reload
test
"previous value is preserved when changed after save"
do
assert_equal
({},
@model
.
changed_attributes
)
@model
.
name
=
"Paul"
assert_equal
({
"name"
=>
nil
},
@model
.
changed_attributes
)
@model
.
status
=
"waiting"
assert_equal
({
"name"
=>
nil
,
"status"
=>
"initialized"
},
@model
.
changed_attributes
)
@model
.
save
@model
.
name
=
"John"
assert_equal
({
"name"
=>
"Paul"
},
@model
.
changed_attributes
)
@model
.
status
=
"finished"
assert_equal
({
"name"
=>
"Paul"
,
"status"
=>
"waiting"
},
@model
.
changed_attributes
)
end
test
"changing the same attribute multiple times retains the correct original value"
do
@model
.
name
=
"Otto"
@model
.
status
=
"waiting"
@model
.
save
@model
.
name
=
"DudeFella ManGuy"
@model
.
name
=
"Mr. Manfredgensonton"
@model
.
status
=
"processing"
@model
.
status
=
"finished"
assert_equal
[
"Otto"
,
"Mr. Manfredgensonton"
],
@model
.
name_change
assert_equal
[
"waiting"
,
"finished"
],
@model
.
status_change
assert_equal
@model
.
name_was
,
"Otto"
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录