Testing and loading attachment_fu models using fixtures

You might think that I’m an attachment_fu fanboy, because this post is also about that plugin. However, I found that there is only little information available on this, therefore I thought it would be nice to share this with you.

Say you have setup fixtures to load as basic content for your site (using rake db:fixtures:load) or you’d like to do tests on already existing attachment_fu enriched model classes. The problem here is that the fixture data is not handled by the plugin; if you supply an image, it will not automagically create thumbnails for you. There didn’t seem to be a way to do this. Tonight however, I found a nice plugin from someone who was struggling with the same problem. It’s called attachment_fu_fixtures. attachment_fu_fixtures overrides the insert_fixture method to allow any attachment fixtures to be handled by attachment_fu, instead of just inserting the data into the database.

A small example from the README on how it can be used:

= fixtures/images.yml
  title: victoria harbour
  attachment_file: test/images/harbour.png
  user: mynyml

The attachment_file attribute is recognized by the plugin and replaced by fields required for attachment_fu. For more info, see the plugin homepage, which is hosted on GitHub.

~ by moiristo on July 31, 2008.

2 Responses to “Testing and loading attachment_fu models using fixtures”

  1. You’re right that attachment_fu_fixtures doesn’t have much visibility out there yet. Thanks for this – I wouldn’t have found it otherwise

  2. Also see vendor/plugins/attachment_fu_fixtures/spec/lib/attachment_fu_fixtures_spec.rb for the examples how the plugin works.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: