diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-12-27 19:46:36 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-12-27 19:49:09 -0700 |
commit | 307ec3db0fe26cbd1811d34a27e6637726ce23ce (patch) | |
tree | 93fee6a30b053e6ad1892ddbadf63a3b429431e3 /activerecord/test | |
parent | cd84b27ca45aa6f18f38202fdbc0ecc0ce9f98ef (diff) | |
download | rails-307ec3db0fe26cbd1811d34a27e6637726ce23ce.tar.gz rails-307ec3db0fe26cbd1811d34a27e6637726ce23ce.tar.bz2 rails-307ec3db0fe26cbd1811d34a27e6637726ce23ce.zip |
Provide a better error message for unsupported classes in `serialize`
We only support classes which provide a no-args constructor to use as a
default value. We can provide a more helpful error message if we catch
this when `serialize` is called, rather than letting it error when you
try to assign the attribute.
Fixes #18224
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/serialized_attribute_test.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/cases/serialized_attribute_test.rb b/activerecord/test/cases/serialized_attribute_test.rb index c8441201ca..c261a5b1c0 100644 --- a/activerecord/test/cases/serialized_attribute_test.rb +++ b/activerecord/test/cases/serialized_attribute_test.rb @@ -264,4 +264,10 @@ class SerializedAttributeTest < ActiveRecord::TestCase assert_not topic.content_changed? end + + def test_classes_without_no_arg_constructors_are_not_supported + assert_raises(ArgumentError) do + Topic.serialize(:content, Regexp) + end + end end |