-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathdev.rake
More file actions
91 lines (79 loc) · 2.37 KB
/
dev.rake
File metadata and controls
91 lines (79 loc) · 2.37 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
desc "Fill the database tables with some sample data"
task sample_data: :environment do
starting = Time.now
FollowRequest.delete_all
Comment.delete_all
Like.delete_all
Photo.delete_all
User.delete_all
people = Array.new(10) do
{
first_name: Faker::Name.first_name,
last_name: Faker::Name.last_name,
}
end
people << { first_name: "Alice", last_name: "Smith", private: true }
people << { first_name: "Bob", last_name: "Smith" }
people << { first_name: "Carol", last_name: "Smith" }
people << { first_name: "Doug", last_name: "Smith" }
people.each do |person|
username = person.fetch(:first_name).downcase
user = User.create(
email: "#{username}@example.com",
password: "password",
username: username.downcase,
name: "#{person[:first_name]} #{person[:last_name]}",
bio: Faker::Lorem.paragraph(
sentence_count: 2,
supplemental: true,
random_sentences_to_add: 4
),
website: Faker::Internet.url,
private: [true, false].sample,
avatar_image: "https://robohash.org/#{username}"
)
end
users = User.all
users.each do |first_user|
users.each do |second_user|
if rand < 0.75
first_user_follow_request = first_user.sent_follow_requests.create(
recipient: second_user,
status: FollowRequest.statuses.values.sample
)
end
if rand < 0.75
second_user_follow_request = second_user.sent_follow_requests.create(
recipient: first_user,
status: FollowRequest.statuses.values.sample
)
end
end
end
users.each do |user|
rand(15).times do
photo = user.own_photos.create(
caption: Faker::Quote.jack_handey,
image: "/#{rand(1..10)}.jpeg"
)
user.followers.each do |follower|
if rand < 0.5
photo.fans << follower
end
if rand < 0.25
comment = photo.comments.create(
body: Faker::Quote.jack_handey,
author: follower
)
end
end
end
end
ending = Time.now
p "It took #{(ending - starting).to_i} seconds to create sample data."
p "There are now #{User.count} users."
p "There are now #{FollowRequest.count} follow requests."
p "There are now #{Photo.count} photos."
p "There are now #{Like.count} likes."
p "There are now #{Comment.count} comments."
end