Skip to content

Instantly share code, notes, and snippets.

@david-hodgetts
Created February 15, 2012 09:46
Show Gist options
  • Save david-hodgetts/1834824 to your computer and use it in GitHub Desktop.
Save david-hodgetts/1834824 to your computer and use it in GitHub Desktop.
make fake users
def make_user(how_many)
count = 0
tags = %w{ ancient brief early fast late long modern old old-fashioned quick rapid short slow swift young agreeable brave calm delightful eager faithful gentle happy jolly kind lively nice obedient proud relieved silly thankful victorious witty zealous big colossal fat gigantic great huge immense large mammoth massive miniature petite puny scrawny short small tall teeny teeny-tiny tiny }
how_many.times do
email = "david_#{count}@demainlalune.ch"
first_name = "david_#{count}"
last_name = "hodge_#{count}"
job = ["acrobate", "violoncelliste", "tueur à gage"].sort_by { rand } .first
location = Directory::Location.all.sort_by { rand }.first
roles = Role.all.reject{ |r| r.name == 'god' }.sort_by{ rand }.slice(0, rand(3) + 1)
subscriptions = Directory::Subscription.all.sort_by{ rand }.slice(0, rand(3) + 1)
main_communication_language = Directory::Language.all.sort_by { rand }.first
communication_languages = Directory::Language.all.reject {|l| l == main_communication_language}.sort_by { rand }.slice(0, rand(3) + 1)
count += 1
p = Person.create!(:email => email,
:first_name => first_name,
:last_name => last_name,
:job => Directory::Job.find_or_create_by_name(job),
:location => location,
:roles => roles,
:subscriptions => subscriptions,
:main_communication_language => main_communication_language,
:communication_languages => communication_languages)
if rand < 0.75
p.tag_list << tags.sort_by { rand }.slice(0, rand(10) + 1)
end
p.save
end
end
Person.find_each(:start => 2) { |p| p.destroy }
make_user(6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment