I have a blob field in my model for storing an image, in raw binary. I want to test that my action that returns the model's image does return the correct image, as matched from the filesystem.
I've loaded up the image and taken a Base64 encoding of it, and formatted it properly for YAML as specified at http://yaml.org/type/binary.html
canonical: !!binary "\
R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5\
OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+\
+f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC\
AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs="
(the other one, !binary |, doesn't seem to work)
Unfortunately, the value I get from the database after loading the fixture looks like this:
--- !ruby/object:YAML::Syck::PrivateType
type_id: binary
value: R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
In order to make use of this data, I need to un-yamlize it, get the value from it, and decode64 it.
This patch automatically converts from the YAML::Syck::PrivateType object to a raw binary string for import into the database. This is only done if the PrivateType's type_id is binary, so that it shouldn't affect any other YAML craziness.
This does break old behaviour, but I can't see anyone actually *wanting* to rely on storing base64-encoded, object-wrapped, yaml-ified data in their DB on a regular basis.