Skip to content

Instantly share code, notes, and snippets.

@liwh
Created October 19, 2010 09:43
Show Gist options
  • Save liwh/633930 to your computer and use it in GitHub Desktop.
Save liwh/633930 to your computer and use it in GitHub Desktop.
factory_girl error
Factory.define :valid_thing, :class => Thing do |t|
  t.name 'Some valid thing'
  t.user { Factory(:valid_user) }
end
Wrapping the call in {} causes Factory Girl to not evaluate the code inside of the 
braces until the :valid_thing factory is created. This will force it to wait until the 
:valid_user factory has been loaded (Your example is failing because it is not yet 
loaded), it will also cause a new :valid_user to be created for each :valid_thing 
rather than having the same user for all :valid_thing's (Which is probably what you 
want).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment