I am still using latest Rails 1.8, not 2.
Using the “serialize :attribute_name” method on an ActiveRecord, if the
serialization ends up being too long for the field, with a MySQL
database, it will just be silently truncated. Of course, this makes it
so it can’t be unserialized again, and you end up with a raw string in
the attribute instead of actually the unserialized object you expected.
Is there any easy way to get an exception to be raised on save if the
serialized value will be truncated?
Sadly, validates_length_of doesn’t do it, because it tries to call
#length on the pre-serialized object, which depending on the class of
the object will give an irrelevant value (Hash.length or Array.length),
or even raise a method not found exception.