提交 d1794cd8 编写于 作者: S Sean Griffin

Merge pull request #24980 from merhard/virtual-attribute-default

Define ActiveRecord::Attribute::Null#type_cast
...@@ -170,7 +170,7 @@ def initialize(name) ...@@ -170,7 +170,7 @@ def initialize(name)
super(name, nil, Type::Value.new) super(name, nil, Type::Value.new)
end end
def value def type_cast(*)
nil nil
end end
......
...@@ -63,6 +63,15 @@ class CustomPropertiesTest < ActiveRecord::TestCase ...@@ -63,6 +63,15 @@ class CustomPropertiesTest < ActiveRecord::TestCase
end end
end end
test "model with nonexistent attribute with default value can be saved" do
klass = Class.new(OverloadedType) do
attribute :non_existent_string_with_default, :string, default: 'nonexistent'
end
model = klass.new
assert model.save
end
test "changing defaults" do test "changing defaults" do
data = OverloadedType.new data = OverloadedType.new
unoverloaded_data = UnoverloadedType.new unoverloaded_data = UnoverloadedType.new
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册