Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c0584ea0
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,发现更多精彩内容 >>
提交
c0584ea0
编写于
3月 02, 2015
作者:
S
Sean Griffin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19077 from robin850/unknown-attribute-error
Move `UnknownAttributeError` to a more sane namespace
上级
53333935
95c2fc96
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
30 addition
and
24 deletion
+30
-24
activemodel/lib/active_model.rb
activemodel/lib/active_model.rb
+1
-0
activemodel/lib/active_model/attribute_assignment.rb
activemodel/lib/active_model/attribute_assignment.rb
+0
-11
activemodel/lib/active_model/errors.rb
activemodel/lib/active_model/errors.rb
+11
-0
activemodel/test/cases/attribute_assignment_test.rb
activemodel/test/cases/attribute_assignment_test.rb
+2
-2
activemodel/test/cases/model_test.rb
activemodel/test/cases/model_test.rb
+1
-1
activerecord/lib/active_record/attribute_assignment.rb
activerecord/lib/active_record/attribute_assignment.rb
+7
-0
activerecord/lib/active_record/errors.rb
activerecord/lib/active_record/errors.rb
+2
-4
activerecord/test/cases/associations/has_one_associations_test.rb
...cord/test/cases/associations/has_one_associations_test.rb
+1
-1
activerecord/test/cases/attribute_methods_test.rb
activerecord/test/cases/attribute_methods_test.rb
+3
-3
activerecord/test/cases/attributes_test.rb
activerecord/test/cases/attributes_test.rb
+1
-1
activerecord/test/cases/nested_attributes_test.rb
activerecord/test/cases/nested_attributes_test.rb
+1
-1
未找到文件。
activemodel/lib/active_model.rb
浏览文件 @
c0584ea0
...
...
@@ -50,6 +50,7 @@ module ActiveModel
eager_autoload
do
autoload
:Errors
autoload
:StrictValidationFailed
,
'active_model/errors'
autoload
:UnknownAttributeError
,
'active_model/errors'
end
module
Serializers
...
...
activemodel/lib/active_model/attribute_assignment.rb
浏览文件 @
c0584ea0
...
...
@@ -48,16 +48,5 @@ def _assign_attribute(k, v)
raise
UnknownAttributeError
.
new
(
self
,
k
)
end
end
# Raised when unknown attributes are supplied via mass assignment.
class
UnknownAttributeError
<
NoMethodError
attr_reader
:record
,
:attribute
def
initialize
(
record
,
attribute
)
@record
=
record
@attribute
=
attribute
super
(
"unknown attribute '
#{
attribute
}
' for
#{
@record
.
class
}
."
)
end
end
end
end
activemodel/lib/active_model/errors.rb
浏览文件 @
c0584ea0
...
...
@@ -524,4 +524,15 @@ def normalize_detail(attribute, message, options)
# # => ActiveModel::StrictValidationFailed: Name can't be blank
class
StrictValidationFailed
<
StandardError
end
# Raised when unknown attributes are supplied via mass assignment.
class
UnknownAttributeError
<
NoMethodError
attr_reader
:record
,
:attribute
def
initialize
(
record
,
attribute
)
@record
=
record
@attribute
=
attribute
super
(
"unknown attribute '
#{
attribute
}
' for
#{
@record
.
class
}
."
)
end
end
end
activemodel/test/cases/attribute_assignment_test.rb
浏览文件 @
c0584ea0
...
...
@@ -49,7 +49,7 @@ def dup
test
"assign non-existing attribute"
do
model
=
Model
.
new
error
=
assert_raises
(
ActiveModel
::
AttributeAssignment
::
UnknownAttributeError
)
do
error
=
assert_raises
(
ActiveModel
::
UnknownAttributeError
)
do
model
.
assign_attributes
(
hz:
1
)
end
...
...
@@ -59,7 +59,7 @@ def dup
test
"assign private attribute"
do
model
=
Model
.
new
assert_raises
(
ActiveModel
::
AttributeAssignment
::
UnknownAttributeError
)
do
assert_raises
(
ActiveModel
::
UnknownAttributeError
)
do
model
.
assign_attributes
(
metadata:
{
a:
1
})
end
end
...
...
activemodel/test/cases/model_test.rb
浏览文件 @
c0584ea0
...
...
@@ -70,7 +70,7 @@ def test_mixin_initializer_when_args_exist
end
def
test_mixin_initializer_when_args_dont_exist
assert_raises
(
ActiveModel
::
AttributeAssignment
::
UnknownAttributeError
)
do
assert_raises
(
ActiveModel
::
UnknownAttributeError
)
do
SimpleModel
.
new
(
hello:
'world'
)
end
end
...
...
activerecord/lib/active_record/attribute_assignment.rb
浏览文件 @
c0584ea0
...
...
@@ -29,6 +29,13 @@ def _assign_attributes(attributes) # :nodoc:
assign_multiparameter_attributes
(
multi_parameter_attributes
)
unless
multi_parameter_attributes
.
empty?
end
# Re-raise with the ActiveRecord constant in case of an error
def
_assign_attribute
(
k
,
v
)
# :nodoc:
super
rescue
ActiveModel
::
UnknownAttributeError
raise
UnknownAttributeError
.
new
(
self
,
k
)
end
# Assign any deferred nested attributes after the base attributes have been set.
def
assign_nested_parameter_attributes
(
pairs
)
pairs
.
each
{
|
k
,
v
|
_assign_attribute
(
k
,
v
)
}
...
...
activerecord/lib/active_record/errors.rb
浏览文件 @
c0584ea0
...
...
@@ -178,10 +178,8 @@ class Rollback < ActiveRecordError
class
DangerousAttributeError
<
ActiveRecordError
end
UnknownAttributeError
=
ActiveSupport
::
Deprecation
::
DeprecatedConstantProxy
.
new
(
# :nodoc:
'ActiveRecord::UnknownAttributeError'
,
'ActiveModel::AttributeAssignment::UnknownAttributeError'
)
# Raised when unknown attributes are supplied via mass assignment.
UnknownAttributeError
=
ActiveModel
::
UnknownAttributeError
# Raised when an error occurred while doing a mass assignment to an attribute through the
# +attributes=+ method. The exception has an +attribute+ property that is the name of the
...
...
activerecord/test/cases/associations/has_one_associations_test.rb
浏览文件 @
c0584ea0
...
...
@@ -276,7 +276,7 @@ def test_create_association_with_bang_failing
def
test_create_with_inexistent_foreign_key_failing
firm
=
Firm
.
create
(
name:
'GlobalMegaCorp'
)
assert_raises
(
Active
Model
::
AttributeAssignment
::
UnknownAttributeError
)
do
assert_raises
(
Active
Record
::
UnknownAttributeError
)
do
firm
.
create_account_with_inexistent_foreign_key
end
end
...
...
activerecord/test/cases/attribute_methods_test.rb
浏览文件 @
c0584ea0
...
...
@@ -758,12 +758,12 @@ def test_question_attributes_respect_access_control
def
test_bulk_update_respects_access_control
privatize
(
"title=(value)"
)
assert_raise
(
Active
Model
::
AttributeAssignment
::
UnknownAttributeError
)
{
@target
.
new
(
:title
=>
"Rants about pants"
)
}
assert_raise
(
Active
Model
::
AttributeAssignment
::
UnknownAttributeError
)
{
@target
.
new
.
attributes
=
{
:title
=>
"Ants in pants"
}
}
assert_raise
(
Active
Record
::
UnknownAttributeError
)
{
@target
.
new
(
:title
=>
"Rants about pants"
)
}
assert_raise
(
Active
Record
::
UnknownAttributeError
)
{
@target
.
new
.
attributes
=
{
:title
=>
"Ants in pants"
}
}
end
def
test_bulk_update_raise_unknown_attribute_error
error
=
assert_raises
(
Active
Model
::
AttributeAssignment
::
UnknownAttributeError
)
{
error
=
assert_raises
(
Active
Record
::
UnknownAttributeError
)
{
Topic
.
new
(
hello:
"world"
)
}
assert_instance_of
Topic
,
error
.
record
...
...
activerecord/test/cases/attributes_test.rb
浏览文件 @
c0584ea0
...
...
@@ -58,7 +58,7 @@ class CustomPropertiesTest < ActiveRecord::TestCase
data
=
OverloadedType
.
new
(
non_existent_decimal:
1
)
assert_equal
BigDecimal
.
new
(
1
),
data
.
non_existent_decimal
assert_raise
Active
Model
::
AttributeAssignment
::
UnknownAttributeError
do
assert_raise
Active
Record
::
UnknownAttributeError
do
UnoverloadedType
.
new
(
non_existent_decimal:
1
)
end
end
...
...
activerecord/test/cases/nested_attributes_test.rb
浏览文件 @
c0584ea0
...
...
@@ -672,7 +672,7 @@ def test_should_automatically_build_new_associated_models_for_each_entry_in_a_ha
end
def
test_should_not_assign_destroy_key_to_a_record
assert_nothing_raised
Active
Model
::
AttributeAssignment
::
UnknownAttributeError
do
assert_nothing_raised
Active
Record
::
UnknownAttributeError
do
@pirate
.
send
(
association_setter
,
{
'foo'
=>
{
'_destroy'
=>
'0'
}})
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录