
Untitled
By: a guest on
May 1st, 2012 | syntax:
None | size: 0.77 KB | hits: 12 | expires: Never
How to properly randomize data with seed.rb using Factory Girl and random_data?
require 'factory_girl_rails'
50.times do
@user = FactoryGirl.create(:user)
FactoryGirl.create(:contact, :user => @user)
@question = FactoryGirl.create(:question, :user => @user)
FactoryGirl.create(:user_answer, :question => @question, :authorable => @user)
@contact = FactoryGirl.create(:contact, :user => @user)
FactoryGirl.create(:contact_answer, :question => @question, :authorable => @contact)
end
FactoryGirl.define do
factory :question do
title "What is the best place to travel in " + Random.country + "?"
body Random.paragraphs(2)
association :user, :method => :build
end
end
Faker::Name.name
Faker::Address.uk_country
Faker::Lorem.paragraph