Create a gist now

Instantly share code, notes, and snippets.

@thephw /example.md
Last active Feb 4, 2016

What would you like to do?
Automaton girl - leveraging factory girl for QA data

Set your vars

email = "patrick.wiseman@salesloft.com"
user = User.find_by(email: email)
account = user.account
team = account.team

def stub_with_random_traits(model, params={})
  FactoryGirl.create(model, *random_traits_for(model), params)
end  

def random_traits_for(model)
  traits = FactoryGirl.factories[model].definition.defined_traits.map{|t| t.name }
  number_of_traits = (rand*traits.length).floor
  number_of_traits.times.map{ traits[(rand*traits.length).floor] }.uniq
end

Fake some data

Cause making data is so boring and forever taking. https://www.youtube.com/watch?v=IS8-viUNP7k

People

cadence = FactoryGirl.create(:cadence, :with_email_step, :with_phone_step, account: account)
5000.times { stub_with_random_traits(:person, account: account, cadence: cadence) rescue nil; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment