|
1 |
| -# This file should contain all the record creation needed to seed the database with its default values. |
2 |
| -# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). |
3 |
| -# |
4 |
| -# Examples: |
5 |
| -# |
6 |
| -# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) |
7 |
| -# Character.create(name: 'Luke', movie: movies.first) |
8 |
| -require 'factory_bot_rails' |
9 |
| - |
10 |
| - |
11 |
| -unless User.exists?(email: email) |
12 |
| - User.create!({name: 'Nick', username: 'hello1', email: email, password: 'hello1234', password_confirmation: 'hello1234'}) |
13 |
| -end |
14 |
| - |
15 |
| -unless User.exists?(email: admin_email) |
16 |
| - admin = FactoryBot.create :admin, name: 'admin', username: 'admin', email: admin_email, password: 'admin1234', password_confirmation: 'admin1234' |
17 |
| -end |
18 |
| - |
19 |
| -user_count = 20 |
20 |
| -category_count = rand(10..20) |
21 |
| -post_count_max = 120 |
22 |
| -comment_count_max = 300 |
23 |
| -users = FactoryBot.create_list :user, user_count |
24 |
| - |
25 |
| -threads = [] |
26 |
| -category_count.times do |
27 |
| - threads << Thread.new do |
28 |
| - category = FactoryBot.create :category, user: admin |
29 |
| - rand(0..post_count_max).times do |
30 |
| - post = FactoryBot.create :post, user: users[rand(0...user_count)], category: category |
31 |
| - rand(0..comment_count_max).times do |
32 |
| - FactoryBot.create :comment, post: post, user: users[rand(0...user_count)] |
33 |
| - end |
34 |
| - end |
35 |
| - ActiveRecord::Base.connection_pool.clear_reloadable_connections! |
36 |
| - end |
37 |
| -end |
38 |
| - |
39 |
| -threads.each{|t| t.join} |
| 1 | +load(Rails.root.join( 'db', 'seeds', "#{Rails.env.downcase}.rb")) |
0 commit comments