jtrupiano edited this page Sep 13, 2010 · 7 revisions
Clone this wiki locally

Using Story Helper with existing Fixtures

  • Write about the motivation for skirting fixtures ****

Story Helper actually works quite nicely with existing fixtures. After storify’ing your app, take a peak at lib/tasks/story_helper.rake. This file defines a new rake task db:load_stories which will load in your test data.

namespace :db do
  desc "Load dev data into the current environment's database."
  task :load_stories => :environment do

Notice that we invoke the db:fixtures:load rake task right in the db:load_stories task. If you have no fixture files defined at all, this line of code will do nothing at all. However, this can be very useful if you already have existing tests/data written in fixtures, but are moving to StoryHelper because you need/want to be able to load more complex data than YAML will gracefully handle.

Do not mix Story Helper and Fixtures for the same model

The most important thing to keep in mind is that we cannot mix stories and fixtures together for the same model. Furthermore, you need to ensure that you completely remove the fixture file (test/fixtures/nonfixture_models.yml) for the tests to run properly (if using fixtures :all in test_helper). If you forget to do this, that table will be emptied out each time a test is run, which is not what we’re trying to achieve here.

Note that by continuing to include the “fixtures :all” line of code in your test_helper.rb file, you’ll also continue to get the accessors that fixtures normally afford you in your test code. Any story helper-specific accessors will go directly into lib/story_accessors.rb.

Delete all empty fixtures!!!!

If you leave empty fixture files hanging around, those tables will be emptied out when fixtures are loaded. So, when migrating your users.yml file over to Story Helper, ensure that you completely delete the fixture file (from SCM too). Otherwise, your tests will complain that your users cannot be found (because the fixture loading code saw the empty file and emptied your users table).

Remove all calls to fixture :models for models that have been moved over to Story Helper

This will bite you in the ass pretty good. This can (and will) happen if you use the default tests provided to you by restful_authentication. These tests (sessions_controller_test and users_controller_test) embed calls to fixtures :users. Even if you have completely removed the users.yml file, this call to fixtures() will empty your users table!!!!

I’m having problems with restful_authentication’s functional tests

See section above for details.