Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

Railsconf: In Praise of Non-fixtured Data – Kevin R. Barnes

Fixtures Suck

When modeling complex business domains, not 3 model blog software, fixtures quickly become a quagmire. What’s the size of your domain? Kevin was working on a project with 180 models. This quickly became unworkable even with only 1 fixture file per model. Fixtures don’t scale well. Scenarios are also problematic as now you have to maintain a directory hierarchy of fixtures.

Use Data Generation instead

Factory Girl

# Define

Factory.define :user do |f|
  f.first_name 'John'
  f.last_name  'Doe'

# use

user = Factory(:user)

Object Daddy

Reopens your ActiveRecord class and adds generators for each attribute.

# define

class User << ActiveRecord::Base

  generator_for :username, :method => :next_user

  generator_for :email, :start => '' do |prev|
    user, domain = prev.split('@')
    user.succ + '@' + domain

# use

@user = User.generate!





  1. Steve Conover says:

    One can point out that fixtures are inappropriate without a categorial denunciation. They’re an entirely appropriate approach given certain problems – problems where the dataset is stable, or there are few writes.

    Object mothers are great. Please, don’t always use them. It’s another tool in the toolbox.

  2. Pat Nakajima says:

    Also, always use [Fixjour](, which I say only because I wrote it. :)

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *