-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdevelopment.rb
34 lines (29 loc) · 1.07 KB
/
development.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'factory_bot_rails'
email = '[email protected]'
unless User.exists?(email: email)
User.create!({name: 'Nick', username: 'hello1', email: email, password: 'hello1234', password_confirmation: 'hello1234'})
end
admin_email = '[email protected]'
unless User.exists?(email: admin_email)
admin = User.create!({name: 'admin', username: 'admin', email: admin_email, password: 'admin1234', password_confirmation: 'admin1234'})
admin.admin_roles
end
user_count = 20
category_count = rand(10..20)
post_count_max = 120
comment_count_max = 300
users = FactoryBot.create_list :user, user_count
threads = []
category_count.times do
threads << Thread.new do
category = FactoryBot.create :category, user: admin
rand(0..post_count_max).times do
post = FactoryBot.create :post, user: users[rand(0...user_count)], category: category
rand(0..comment_count_max).times do
FactoryBot.create :comment, post: post, user: users[rand(0...user_count)]
end
end
ActiveRecord::Base.connection_pool.clear_reloadable_connections!
end
end
threads.each{|t| t.join}