discourse_dev 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/discourse_dev/post.rb +40 -2
- data/lib/discourse_dev/tasks/populate.rake +5 -0
- data/lib/discourse_dev/topic.rb +10 -3
- data/lib/discourse_dev/version.rb +1 -1
- data/lib/faker/locales/en.yml +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7cf21a4b27818d1c6c02ce68b6f3fec67fec0b5c7ce070203c4db6bec1e1e72
|
4
|
+
data.tar.gz: 7bcd79d041f43cf6ed4843c2a3fe9f20bba915682516586064a0356acb5246df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f964c9b509c0e219aff2161e49fc7d468861fefc85e6ce0a68250fbdfd2ca6d06d32ee7bf0b153ae99eb1dc9be0a1c4694752ec60ee7b0c71143d0283ebd5c15
|
7
|
+
data.tar.gz: 207d473198144df8997a72eb9ab6f9070b24b924c6600be546d6bef2aeb26076c633b781caba9fb69590a2c99807004b0c19a49026f588d2cc7ae0470fa391b5
|
data/lib/discourse_dev/post.rb
CHANGED
@@ -29,13 +29,17 @@ module DiscourseDev
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def create!
|
32
|
-
|
32
|
+
begin
|
33
|
+
PostCreator.new(user, data).create!
|
34
|
+
rescue ActiveRecord::RecordNotSaved => e
|
35
|
+
puts e
|
36
|
+
end
|
33
37
|
end
|
34
38
|
|
35
39
|
def user
|
36
40
|
return User.random if topic.category.groups.blank?
|
37
41
|
return Discourse.system_user if @user_ids.blank?
|
38
|
-
|
42
|
+
|
39
43
|
position = Faker::Number.between(from: 0, to: @user_count - 1)
|
40
44
|
::User.find(@user_ids[position])
|
41
45
|
end
|
@@ -46,5 +50,39 @@ module DiscourseDev
|
|
46
50
|
create!
|
47
51
|
end
|
48
52
|
end
|
53
|
+
|
54
|
+
def self.add_replies!(args)
|
55
|
+
if !args[:topic_id]
|
56
|
+
puts "Topic ID is required. Aborting."
|
57
|
+
return
|
58
|
+
end
|
59
|
+
|
60
|
+
if !::Topic.find_by_id(args[:topic_id])
|
61
|
+
puts "Topic ID does not match topic in DB, aborting."
|
62
|
+
return
|
63
|
+
end
|
64
|
+
|
65
|
+
topic = ::Topic.find_by_id(args[:topic_id])
|
66
|
+
count = args[:count] ? args[:count].to_i : 50
|
67
|
+
|
68
|
+
puts "Creating #{count} replies in '#{topic.title}'"
|
69
|
+
|
70
|
+
count.times do |i|
|
71
|
+
@index = i
|
72
|
+
begin
|
73
|
+
reply = {
|
74
|
+
topic_id: topic.id,
|
75
|
+
raw: Faker::Markdown.sandwich(sentences: 5),
|
76
|
+
skip_validations: true
|
77
|
+
}
|
78
|
+
PostCreator.new(User.random, reply).create!
|
79
|
+
rescue ActiveRecord::RecordNotSaved => e
|
80
|
+
puts e
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
puts "Done!"
|
85
|
+
end
|
86
|
+
|
49
87
|
end
|
50
88
|
end
|
@@ -24,3 +24,8 @@ desc 'Creates sample topics'
|
|
24
24
|
task 'topics:populate' => ['db:load_config'] do |_, args|
|
25
25
|
DiscourseDev::Topic.populate!
|
26
26
|
end
|
27
|
+
|
28
|
+
desc 'Add replies to a topic'
|
29
|
+
task 'replies:populate', [:topic_id, :count] => ['db:load_config'] do |_, args|
|
30
|
+
DiscourseDev::Post.add_replies!(args)
|
31
|
+
end
|
data/lib/discourse_dev/topic.rb
CHANGED
@@ -41,14 +41,21 @@ module DiscourseDev
|
|
41
41
|
|
42
42
|
def create!
|
43
43
|
@category = Category.random
|
44
|
-
|
44
|
+
topic = data
|
45
|
+
post = PostCreator.new(user, topic).create!
|
45
46
|
|
46
|
-
|
47
|
+
if topic[:title] == "Coolest thing you have seen today"
|
48
|
+
reply_count = 99
|
49
|
+
else
|
50
|
+
reply_count = Faker::Number.between(from: 0, to: 12)
|
51
|
+
end
|
52
|
+
|
53
|
+
Post.new(post.topic, reply_count).populate!
|
47
54
|
end
|
48
55
|
|
49
56
|
def user
|
50
57
|
return User.random if @category.groups.blank?
|
51
|
-
|
58
|
+
|
52
59
|
group_ids = @category.groups.pluck(:id)
|
53
60
|
user_ids = ::GroupUser.where(group_id: group_ids).pluck(:user_id)
|
54
61
|
user_count = user_ids.count
|
data/lib/faker/locales/en.yml
CHANGED
@@ -93,7 +93,7 @@ en:
|
|
93
93
|
- Totally amped about the 80s
|
94
94
|
- Do microwave ovens kill bacteria?
|
95
95
|
- Most inspirational movie you have ever seen?
|
96
|
-
- Catching all 151 in 2 hours
|
96
|
+
- Catching all 151 in 2 hours 😀
|
97
97
|
- Charlie The Unicorn 4
|
98
98
|
- Video Games for Pre-Teens?
|
99
99
|
- Online learning
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discourse_dev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vinoth Kannan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|