aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-05-11 22:00:37 -0400
committerSean Griffin <sean@seantheprogrammer.com>2016-05-11 22:00:37 -0400
commitd1794cd88c1de2f72ba35fd5cced42bc0f7528f9 (patch)
tree0d873b9aef9e961455a47095f9679dca73e5b209 /activerecord
parent50ef6ed4500686826997688a622496bec9b0992a (diff)
parent556e530da41dce5ae8070e8e075390bbedb949c0 (diff)
downloadrails-d1794cd88c1de2f72ba35fd5cced42bc0f7528f9.tar.gz
rails-d1794cd88c1de2f72ba35fd5cced42bc0f7528f9.tar.bz2
rails-d1794cd88c1de2f72ba35fd5cced42bc0f7528f9.zip
Merge pull request #24980 from merhard/virtual-attribute-default
Define ActiveRecord::Attribute::Null#type_cast
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute.rb2
-rw-r--r--activerecord/test/cases/attributes_test.rb9
2 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute.rb b/activerecord/lib/active_record/attribute.rb
index 3c4c8f10ec..24231dc9e1 100644
--- a/activerecord/lib/active_record/attribute.rb
+++ b/activerecord/lib/active_record/attribute.rb
@@ -170,7 +170,7 @@ module ActiveRecord
super(name, nil, Type::Value.new)
end
- def value
+ def type_cast(*)
nil
end
diff --git a/activerecord/test/cases/attributes_test.rb b/activerecord/test/cases/attributes_test.rb
index 2bebbfa205..48ba7a63d5 100644
--- a/activerecord/test/cases/attributes_test.rb
+++ b/activerecord/test/cases/attributes_test.rb
@@ -63,6 +63,15 @@ module ActiveRecord
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
data = OverloadedType.new
unoverloaded_data = UnoverloadedType.new