Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 0.77 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to properly randomize data with seed.rb using Factory Girl and random_data?
  2. require 'factory_girl_rails'
  3.  
  4. 50.times do
  5.  
  6.   @user = FactoryGirl.create(:user)
  7.   FactoryGirl.create(:contact, :user => @user)
  8.  
  9.   @question = FactoryGirl.create(:question, :user => @user)
  10.  
  11.   FactoryGirl.create(:user_answer, :question => @question, :authorable => @user)
  12.  
  13.   @contact = FactoryGirl.create(:contact, :user => @user)
  14.   FactoryGirl.create(:contact_answer, :question => @question, :authorable => @contact)
  15.  
  16. end
  17.        
  18. FactoryGirl.define do
  19.   factory :question do
  20.     title       "What is the best place to travel in " + Random.country + "?"
  21.     body        Random.paragraphs(2)
  22.     association :user, :method => :build
  23.   end
  24. end
  25.        
  26. Faker::Name.name
  27. Faker::Address.uk_country
  28. Faker::Lorem.paragraph