|
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 | + |
2 | 5 | 5.times do |i| |
3 | 6 | email = Faker::Internet.email |
4 | 7 | password = Faker::Internet.password(min_length: 8) |
|
7 | 10 | last_name = Faker::Name.last_name |
8 | 11 | avatar_url = Faker::Avatar.image |
9 | 12 |
|
| 13 | + # Create user |
10 | 14 | user = User.create!(email: email, password: password, role: role, first_name: first_name, last_name: last_name, avatar_url: avatar_url) |
11 | 15 |
|
12 | | - # Tạo 3 bài viết cho mỗi người dùng |
| 16 | + # each user has 3 posts |
13 | 17 | 3.times do |
14 | 18 | title = Faker::Lorem.sentence |
15 | 19 | body = Faker::Lorem.paragraphs.join('\n') |
16 | 20 | total_view = Faker::Number.between(from: 1, to: 100) |
17 | 21 | status = ['approved'].sample |
18 | 22 |
|
| 23 | + # Create post |
19 | 24 | post = Post.create!(title: title, body: body, user_id: user.id, total_view: total_view, status: status) |
20 | 25 |
|
21 | | - # Tạo feedback |
| 26 | + # Create feedback |
22 | 27 | Feedback.create!(content: Faker::Lorem.sentence, post_id: post.id, user_id: User.where.not(id: user.id).sample.id) |
23 | 28 |
|
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) |
26 | 31 |
|
27 | | - # Tạo comment cho discussion |
| 32 | + # Create comment |
28 | 33 | Comment.create!(content: Faker::Lorem.sentence, user_id: user.id, linked_object_id: discussion.id, linked_object_type: 'Discussion', status: 'approved') |
29 | 34 | end |
30 | 35 | end |
0 commit comments