Bradford Smith
unread,Feb 4, 2013, 10:22:31 AM2/4/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message as abuse
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to factor...@googlegroups.com
I have State and Country that my app needs to run. I seed it in my test, development, and production environments. I use FactoryGirl to create a store:
FactoryGirl.define do
factory :store do
name "Best Store Ever"
city "Somewhere"
state_id State.find_by_abbreviation("CA").id
country_id Country.find_by_iso("US").id
end
end
But, FactoryGirl seems to get run before my seed and I get an error: Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id (RuntimeError)
State.abbreviation and Country.iso are unique.
What are my best options for doing this? Should FactoryGirl not rely on seed data? How else should I do this? I have some ideas, but would like to know what the best practice is here.