I have the following factory setting:
FactoryGirl.define do factory :country do |f| f.name "USA" f.country_code "USA" f.currency_code "USD" end factory :region do |f| f.name "East Coast" f.country {Country.first} end factory :state do |f| f.name 'CA' f.region {Region.first} f.country {Country.first} end end
What I want to do in the region and in state factories is to check if there is a record in the database for the country, if so, use it only if no records are found if it creates a new model.
Here is an example of what I mean, but not sure how to do it:
factory :state do |f| f.name 'CA' f.region {Region.first || Factory(:region} f.country {Country.first || Factory(:state} end
The reason I want to do this is to enter records in my database that will fill out the form selection fields, and I can check the use of the cucumber.
Jason source share