Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
9feda8f2
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,发现更多精彩内容 >>
提交
9feda8f2
编写于
9月 17, 2015
作者:
Y
Yves Senn
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21581 from ronakjangir47/restrict_with_error
`restrict_with_error` message will now respect owner’s human name
上级
1ebd987a
8fbd858c
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
44 addition
and
2 deletion
+44
-2
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+5
-0
activerecord/lib/active_record/associations/has_many_association.rb
...rd/lib/active_record/associations/has_many_association.rb
+1
-1
activerecord/lib/active_record/associations/has_one_association.rb
...ord/lib/active_record/associations/has_one_association.rb
+1
-1
activerecord/test/cases/associations/has_many_associations_test.rb
...ord/test/cases/associations/has_many_associations_test.rb
+19
-0
activerecord/test/cases/associations/has_one_associations_test.rb
...cord/test/cases/associations/has_one_associations_test.rb
+18
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
9feda8f2
*
Lookup the attribute name for
`restrict_with_error`
messages on the
model class that defines the association.
*kuboon*, *Ronak Jangir*
*
Correct query for PostgreSQL 8.2 compatibility.
*Ben Murphy*, *Matthew Draper*
...
...
activerecord/lib/active_record/associations/has_many_association.rb
浏览文件 @
9feda8f2
...
...
@@ -15,7 +15,7 @@ def handle_dependency
when
:restrict_with_error
unless
empty?
record
=
k
lass
.
human_attribute_name
(
reflection
.
name
).
downcase
record
=
owner
.
c
lass
.
human_attribute_name
(
reflection
.
name
).
downcase
message
=
owner
.
errors
.
generate_message
(
:base
,
:'restrict_dependent_destroy.many'
,
record:
record
,
raise:
true
)
rescue
nil
if
message
ActiveSupport
::
Deprecation
.
warn
(
<<-
MESSAGE
.
squish
)
...
...
activerecord/lib/active_record/associations/has_one_association.rb
浏览文件 @
9feda8f2
...
...
@@ -11,7 +11,7 @@ def handle_dependency
when
:restrict_with_error
if
load_target
record
=
k
lass
.
human_attribute_name
(
reflection
.
name
).
downcase
record
=
owner
.
c
lass
.
human_attribute_name
(
reflection
.
name
).
downcase
message
=
owner
.
errors
.
generate_message
(
:base
,
:'restrict_dependent_destroy.one'
,
record:
record
,
raise:
true
)
rescue
nil
if
message
ActiveSupport
::
Deprecation
.
warn
(
<<-
MESSAGE
.
squish
)
...
...
activerecord/test/cases/associations/has_many_associations_test.rb
浏览文件 @
9feda8f2
...
...
@@ -1482,6 +1482,25 @@ def test_restrict_with_error
assert
firm
.
companies
.
exists?
(
:name
=>
'child'
)
end
def
test_restrict_with_error_with_locale
I18n
.
backend
=
I18n
::
Backend
::
Simple
.
new
I18n
.
backend
.
store_translations
'en'
,
activerecord:
{
attributes:
{
restricted_with_error_firm:
{
companies:
'client companies'
}}}
firm
=
RestrictedWithErrorFirm
.
create!
(
name:
'restrict'
)
firm
.
companies
.
create
(
name:
'child'
)
assert
!
firm
.
companies
.
empty?
firm
.
destroy
assert
!
firm
.
errors
.
empty?
assert_equal
"Cannot delete record because dependent client companies exist"
,
firm
.
errors
[
:base
].
first
assert
RestrictedWithErrorFirm
.
exists?
(
name:
'restrict'
)
assert
firm
.
companies
.
exists?
(
name:
'child'
)
ensure
I18n
.
backend
.
reload!
end
def
test_included_in_collection
assert_equal
true
,
companies
(
:first_firm
).
clients
.
include?
(
Client
.
find
(
2
))
end
...
...
activerecord/test/cases/associations/has_one_associations_test.rb
浏览文件 @
9feda8f2
...
...
@@ -219,6 +219,24 @@ def test_restrict_with_error
assert
firm
.
account
.
present?
end
def
test_restrict_with_error_with_locale
I18n
.
backend
=
I18n
::
Backend
::
Simple
.
new
I18n
.
backend
.
store_translations
'en'
,
activerecord:
{
attributes:
{
restricted_with_error_firm:
{
account:
'firm account'
}}}
firm
=
RestrictedWithErrorFirm
.
create!
(
name:
'restrict'
)
firm
.
create_account
(
credit_limit:
10
)
assert_not_nil
firm
.
account
firm
.
destroy
assert
!
firm
.
errors
.
empty?
assert_equal
"Cannot delete record because a dependent firm account exists"
,
firm
.
errors
[
:base
].
first
assert
RestrictedWithErrorFirm
.
exists?
(
name:
'restrict'
)
assert
firm
.
account
.
present?
ensure
I18n
.
backend
.
reload!
end
def
test_successful_build_association
firm
=
Firm
.
new
(
"name"
=>
"GlobalMegaCorp"
)
firm
.
save
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录