Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6efd02e2
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 搜索 >>
提交
6efd02e2
编写于
1月 30, 2016
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add `ActiveRecord::ValueTooLong` exception class
上级
b9a95456
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
18 addition
and
0 deletion
+18
-0
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
...tive_record/connection_adapters/abstract_mysql_adapter.rb
+2
-0
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
...b/active_record/connection_adapters/postgresql_adapter.rb
+3
-0
activerecord/lib/active_record/errors.rb
activerecord/lib/active_record/errors.rb
+4
-0
activerecord/test/cases/adapter_test.rb
activerecord/test/cases/adapter_test.rb
+9
-0
未找到文件。
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
浏览文件 @
6efd02e2
...
...
@@ -741,6 +741,8 @@ def translate_exception(exception, message)
RecordNotUnique
.
new
(
message
)
when
1452
InvalidForeignKey
.
new
(
message
)
when
1406
ValueTooLong
.
new
(
message
)
else
super
end
...
...
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
浏览文件 @
6efd02e2
...
...
@@ -398,6 +398,7 @@ def postgresql_version
protected
# See http://www.postgresql.org/docs/current/static/errcodes-appendix.html
VALUE_LIMIT_VIOLATION
=
"22001"
FOREIGN_KEY_VIOLATION
=
"23503"
UNIQUE_VIOLATION
=
"23505"
...
...
@@ -409,6 +410,8 @@ def translate_exception(exception, message)
RecordNotUnique
.
new
(
message
)
when
FOREIGN_KEY_VIOLATION
InvalidForeignKey
.
new
(
message
)
when
VALUE_LIMIT_VIOLATION
ValueTooLong
.
new
(
message
)
else
super
end
...
...
activerecord/lib/active_record/errors.rb
浏览文件 @
6efd02e2
...
...
@@ -125,6 +125,10 @@ class RecordNotUnique < WrappedDatabaseException
class
InvalidForeignKey
<
WrappedDatabaseException
end
# Raised when a record cannot be inserted or updated because a value too long for a column type.
class
ValueTooLong
<
StatementInvalid
end
# Raised when number of bind variables in statement given to +:condition+ key
# (for example, when using {ActiveRecord::Base.find}[rdoc-ref:FinderMethods#find] method)
# does not match number of expected values supplied.
...
...
activerecord/test/cases/adapter_test.rb
浏览文件 @
6efd02e2
...
...
@@ -2,6 +2,7 @@
require
"models/book"
require
"models/post"
require
"models/author"
require
"models/event"
module
ActiveRecord
class
AdapterTest
<
ActiveRecord
::
TestCase
...
...
@@ -193,6 +194,14 @@ def test_foreign_key_violations_are_translated_to_specific_exception_with_valida
assert_not_nil
error
.
cause
end
def
test_value_limit_violations_are_translated_to_specific_exception
error
=
assert_raises
(
ActiveRecord
::
ValueTooLong
)
do
Event
.
create
(
title:
'abcdefgh'
)
end
assert_not_nil
error
.
cause
end
end
def
test_disable_referential_integrity
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录