Skip to content

Instantly share code, notes, and snippets.

@thephw
Last active February 4, 2016 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thephw/3ad7ce7a80cd17b3d20e to your computer and use it in GitHub Desktop.
Save thephw/3ad7ce7a80cd17b3d20e to your computer and use it in GitHub Desktop.
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