Guest User

Untitled

a guest
May 1st, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment