Skip to content

Instantly share code, notes, and snippets.

@joselo
Forked from jferris/new.rb
Created January 5, 2012 21:41
Show Gist options
  • Save joselo/1567475 to your computer and use it in GitHub Desktop.
Save joselo/1567475 to your computer and use it in GitHub Desktop.
New FactoryGirl definition syntax
FactoryGirl.define do
sequence :email do |n|
"user#{n}@example.com"
end
factory :user do
email
password "test"
aliased_as :author
end
factory :post do
author
title "A post"
end
end
Factory.sequence(:email) { |n| "user#{n}@example.com" }
Factory.define :user do |factory|
factory.email { Factory.next(:email) }
factory.password "test"
end
Factory.define :post do |factory|
factory.association :author, :factory => :user
factory.title "A post"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment