Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
7f7b4800
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,发现更多精彩内容 >>
提交
7f7b4800
编写于
1月 08, 2011
作者:
J
Jon Leighton
提交者:
Aaron Patterson
1月 11, 2011
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
When assigning a has_one, if the new record fails to save, raise an error
上级
1bc71ed9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
19 deletion
+19
-19
activerecord/lib/active_record/associations/has_one_association.rb
...ord/lib/active_record/associations/has_one_association.rb
+3
-3
activerecord/test/cases/associations/has_one_associations_test.rb
...cord/test/cases/associations/has_one_associations_test.rb
+14
-14
activerecord/test/cases/autosave_association_test.rb
activerecord/test/cases/autosave_association_test.rb
+2
-2
未找到文件。
activerecord/lib/active_record/associations/has_one_association.rb
浏览文件 @
7f7b4800
...
...
@@ -32,9 +32,9 @@ def replace(record, save = true)
loaded
if
@owner
.
persisted?
&&
record
&&
save
record
.
save
&&
self
else
record
&&
self
unless
record
.
save
raise
RecordNotSaved
,
"Failed to save the new associated
#{
@reflection
.
name
}
."
end
end
end
...
...
activerecord/test/cases/associations/has_one_associations_test.rb
浏览文件 @
7f7b4800
...
...
@@ -93,18 +93,18 @@ def test_natural_assignment_to_nil
def
test_nullification_on_association_change
firm
=
companies
(
:rails_core
)
old_account_id
=
firm
.
account
.
id
firm
.
account
=
Account
.
new
firm
.
account
=
Account
.
new
(
:credit_limit
=>
5
)
# account is dependent with nullify, therefore its firm_id should be nil
assert_nil
Account
.
find
(
old_account_id
).
firm_id
end
def
test_association_change_calls_delete
companies
(
:first_firm
).
deletable_account
=
Account
.
new
companies
(
:first_firm
).
deletable_account
=
Account
.
new
(
:credit_limit
=>
5
)
assert_equal
[],
Account
.
destroyed_account_ids
[
companies
(
:first_firm
).
id
]
end
def
test_association_change_calls_destroy
companies
(
:first_firm
).
account
=
Account
.
new
companies
(
:first_firm
).
account
=
Account
.
new
(
:credit_limit
=>
5
)
assert_equal
[
companies
(
:first_firm
).
id
],
Account
.
destroyed_account_ids
[
companies
(
:first_firm
).
id
]
end
...
...
@@ -182,17 +182,6 @@ def test_build
assert_equal
account
,
firm
.
account
end
def
test_failing_build_association
firm
=
Firm
.
new
(
"name"
=>
"GlobalMegaCorp"
)
firm
.
save
firm
.
account
=
account
=
Account
.
new
assert_equal
account
,
firm
.
account
assert
!
account
.
save
assert_equal
account
,
firm
.
account
assert_equal
[
"can't be empty"
],
account
.
errors
[
"credit_limit"
]
end
def
test_create
firm
=
Firm
.
new
(
"name"
=>
"GlobalMegaCorp"
)
firm
.
save
...
...
@@ -320,4 +309,15 @@ def test_replacement_failure_due_to_existing_record_should_raise_error
assert_equal
ships
(
:black_pearl
),
pirate
.
ship
assert_equal
pirate
.
id
,
pirate
.
ship
.
pirate_id
end
def
test_replacement_failure_due_to_new_record_should_raise_error
pirate
=
pirates
(
:blackbeard
)
new_ship
=
Ship
.
new
assert_raise
(
ActiveRecord
::
RecordNotSaved
)
do
pirate
.
ship
=
new_ship
end
assert_equal
new_ship
,
pirate
.
ship
assert_equal
pirate
.
id
,
new_ship
.
pirate_id
end
end
activerecord/test/cases/autosave_association_test.rb
浏览文件 @
7f7b4800
...
...
@@ -90,7 +90,7 @@ def test_save_fails_for_invalid_has_one
firm
=
Firm
.
find
(
:first
)
assert
firm
.
valid?
firm
.
account
=
Account
.
new
firm
.
build_account
assert
!
firm
.
account
.
valid?
assert
!
firm
.
valid?
...
...
@@ -102,7 +102,7 @@ def test_save_succeeds_for_invalid_has_one_with_validate_false
firm
=
Firm
.
find
(
:first
)
assert
firm
.
valid?
firm
.
unvalidated_account
=
Account
.
new
firm
.
build_unvalidated_account
assert
!
firm
.
unvalidated_account
.
valid?
assert
firm
.
valid?
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录