Skip to content

Instantly share code, notes, and snippets.

@DavidMah
Created August 29, 2011 20:35
Show Gist options
  • Save DavidMah/1179349 to your computer and use it in GitHub Desktop.
Save DavidMah/1179349 to your computer and use it in GitHub Desktop.
Populate Posterous devcloud
def make_sites(options = {})
times = options[:times] ? options[:times] : 50
users = options[:users] ? options[:users] : User.all
times.times do |t|
n = Site.new
begin
n.user = users.sample
n.hostname = "siteno#{t}"
n.save
puts "site #{t}"
rescue
puts $!
end
end
end
def make_notifications(options = {})
times = options[:times] ? options[:times] : 50
posts = options[:posts] ? options[:posts] : Post.all
users = options[:users] ? options[:users] : User.all
post_ids = posts.collect(&:id)
times.times do |t|
n = Notification.new
n.notifiable_type = 'Post'
begin
n.notifiable_id = post_ids.sample
n.user = users.sample
n.save
puts "notification #{t}"
rescue
puts $!
end
end
end
def make_likes(options = {})
times = options[:times] ? options[:times] : 50
users = options[:users] ? options[:users] : User.all
posts = options[:posts] ? options[:posts] : Post.all
times.times do |t|
n = Comment.new
begin
n.post = posts.sample
n.user = users.sample
n.comment_type = 1
n.body = ""
n.save
puts "like #{t}"
rescue
puts $!
end
end
end
def make_comments(options = {})
times = options[:times] ? options[:times] : 50
users = options[:users] ? options[:users] : User.all
posts = options[:posts] ? options[:posts] : Post.all
times.times do |t|
n = Comment.new
begin
n.post = posts.sample
n.user = users.sample
n.body = %Q[dd if="/dev/urandom" of="/"
derp]
n.comment_type = 2
n.save
puts "comment #{t}"
rescue
puts $!
end
end
end
def make_posts(options = {})
times = options[:times] ? options[:times] : 50
sites = options[:sites] ? options[:sites] : Site.all
times.times do |t|
n = Post.new
begin
n.site = sites.sample
n.body = "Derpity derp derp magerp
がはは!
あんたは太いだよ
えと。。。はい。あんた"
n.save
puts "post #{t}"
rescue
puts $!
end
end
end
make_sites( :times => 10)
make_posts( :times => 1000)
make_comments( :times => 3000)
make_likes( :times => 3000)
make_notifications( :times => 4000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment