Spree Commerce

Try It Now

New on Edge: Improved Fixture Support for Extensions

Posted on November 23, 2009 by Sean Schofield

We have just improved the seed and sample data loading for Spree extensions. Torsten RĂ¼ger has just contributed a great new patch to introduce new flexibility when it comes to loading fixture data from your extensions. Prior to this patch, there was no way to override seed data in an extension. So if you wanted to replace the list of default countries in your site extension, you were pretty much out of luck (or you had to write an ugly hack.)

Seed data is data that is needed by the application in order for it to work properly. Seed data is not the same as sample data. Instead of loading this type of data in a migration it is handled through the standard rails task through rake db:seed. The rake task will first load the seed data in the spree core (ex. db/default/countries.yml.) Spree will then load any fixtures found in the db/default directory of your extensions. You will no longer need to explicitly load extension seed data yourself from db/seeds.rb. If you have an extension that does so, you will need to remove that code so that you’re not loading the data twice.

Sample data is data that is convenient to have when testing your code. Its loaded with the rake db:sample task. The core sample data is loaded first, followed by any fixtures contained in the db/sample directory of your extensions.

If you have fixtures in your extension with the same filename as those found in the core, they will be loaded instead of the core version. This applies to both sample and seed fixtures. This allows for fine grained control over the sample and seed data. For example, you can create your own custom sample order data in your site extension instead of relying on the version provided by Spree.