Skip to content

Commit b195de2

Browse files
authored
Merge pull request #34 from tuanle03/create-seeding-data
Create sample data for development environment
2 parents 894d9cc + 81376df commit b195de2

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

db/seeds.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# Ví dụ với 5 người dùng và 3 bài viết
1+
# Description: This file is used to create sample data for development environment
2+
3+
User.create!(email: 'mio@gmail.com', password: '12345678', role: 'admin', first_name: 'Mio', last_name: 'Admin', avatar_url: Faker::Avatar.image)
4+
25
5.times do |i|
36
email = Faker::Internet.email
47
password = Faker::Internet.password(min_length: 8)
@@ -7,24 +10,26 @@
710
last_name = Faker::Name.last_name
811
avatar_url = Faker::Avatar.image
912

13+
# Create user
1014
user = User.create!(email: email, password: password, role: role, first_name: first_name, last_name: last_name, avatar_url: avatar_url)
1115

12-
# Tạo 3 bài viết cho mỗi người dùng
16+
# each user has 3 posts
1317
3.times do
1418
title = Faker::Lorem.sentence
1519
body = Faker::Lorem.paragraphs.join('\n')
1620
total_view = Faker::Number.between(from: 1, to: 100)
1721
status = ['approved'].sample
1822

23+
# Create post
1924
post = Post.create!(title: title, body: body, user_id: user.id, total_view: total_view, status: status)
2025

21-
# Tạo feedback
26+
# Create feedback
2227
Feedback.create!(content: Faker::Lorem.sentence, post_id: post.id, user_id: User.where.not(id: user.id).sample.id)
2328

24-
# Tạo discussion
25-
discussion = Discussion.create!(content: Faker::Lorem.paragraph, user_id: User.where.not(id: user.id).sample.id, status: 'approved')
29+
# Create discussion
30+
discussion = Discussion.create!(content: Faker::Lorem.paragraph, user_id: User.where.not(id: user.id).sample.id, status: 'approved', title: Faker::Lorem.sentence)
2631

27-
# Tạo comment cho discussion
32+
# Create comment
2833
Comment.create!(content: Faker::Lorem.sentence, user_id: user.id, linked_object_id: discussion.id, linked_object_type: 'Discussion', status: 'approved')
2934
end
3035
end

0 commit comments

Comments
 (0)