Hello, I''m working on a small, Rails-powered photo archiving/gallery application; and I am planning to store the original photos in the database. The table in question (MySQL) has the following columns: id: int(11) unsigned caption: varchar(255) mime_type: varchar(100) data: BLOB When unit testing the model, I would like to use the YAML-style fixtures, but they don''t seem to be working correctly with the BLOB field. My photos.yml fixture file looks like: photo_one: id: 1 caption: ''A Test Photo'' mime_type: ''image/jpeg'' data: ''<%= File.read(RAILS_ROOT + ''test/mocks/test/test_img_1.jpg'') %>'' photo_two: id: 2 caption: ''Another Test Photo'' mime_type: ''image/jpeg'' data: ''<%= File.read(RAILS_ROOT + ''test/mocks/test/test_img_2.jpg'') %>'' However, when it imports the fixtures, the information for ''photo_two'' is not imported _at all_ (and no fixture is created for it), and the ''data'' field for ''photo_one'' does not contain the full file. Am I doing something obviously wrong here? How have others handled fixtures with BLOB data? -- Regards, John Wilger ----------- Alice came to a fork in the road. "Which road do I take?" she asked. "Where do you want to go?" responded the Cheshire cat. "I don''t know," Alice answered. "Then," said the cat, "it doesn''t matter." - Lewis Carrol, Alice in Wonderland
John Wilger wrote:> Hello, > > I''m working on a small, Rails-powered photo archiving/gallery > application; and I am planning to store the original photos in the > database. The table in question (MySQL) has the following columns: > > id: int(11) unsigned > caption: varchar(255) > mime_type: varchar(100) > data: BLOB > > When unit testing the model, I would like to use the YAML-style > fixtures, but they don''t seem to be working correctly with the BLOB > field. My photos.yml fixture file looks like: > > photo_one: > id: 1 > caption: ''A Test Photo'' > mime_type: ''image/jpeg'' > data: ''<%= File.read(RAILS_ROOT + ''test/mocks/test/test_img_1.jpg'') %>'' > photo_two: > id: 2 > caption: ''Another Test Photo'' > mime_type: ''image/jpeg'' > data: ''<%= File.read(RAILS_ROOT + ''test/mocks/test/test_img_2.jpg'') %>'' > > However, when it imports the fixtures, the information for ''photo_two'' > is not imported _at all_ (and no fixture is created for it), and the > ''data'' field for ''photo_one'' does not contain the full file. > > Am I doing something obviously wrong here? How have others handled > fixtures with BLOB data? >I haven''t used YAML for binary content, but I believe[1] yaml is capable of handling it. Here''s an example I lifted from the specs[2] picture: !!binary | R0lGODlhDAAMAIQAAP//9/X 17unp5WZmZgAAAOfn515eXv Pz7Y6OjuDg4J+fn5OTk6enp 56enmleECcgggoBADs Its base64 encoded, so you''ll need to change your yaml a bit. [1] http://www.yaml.org/refcard.html see !!binary under "Language Independent Scalar types" [2] http://yaml.org/spec/current.html -- Lee