Class: DiscourseDev::Topic
Constant Summary
Constants inherited
from Record
Record::DEFAULT_COUNT
Instance Attribute Summary
Attributes inherited from Record
#model, #type
Instance Method Summary
collapse
Methods inherited from Record
#index, #populate!, populate!, random
Constructor Details
#initialize(count = DEFAULT_COUNT) ⇒ Topic
Returns a new instance of Topic.
9
10
11
|
# File 'lib/discourse_dev/topic.rb', line 9
def initialize(count = DEFAULT_COUNT)
super(::Topic, count)
end
|
Instance Method Details
#create! ⇒ Object
42
43
44
45
|
# File 'lib/discourse_dev/topic.rb', line 42
def create!
@category = Category.random
PostCreator.new(user, data).create!
end
|
#data ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/discourse_dev/topic.rb', line 13
def data
{
title: title[0, SiteSetting.max_topic_title_length],
raw: Faker::Markdown.sandwich(sentences: 5),
category: @category.id,
tags: tags,
topic_opts: { custom_fields: { dev_sample: true } },
skip_validations: true
}
end
|
32
33
34
35
36
37
38
39
40
|
# File 'lib/discourse_dev/topic.rb', line 32
def tags
@tags = []
Faker::Number.between(from: 0, to: 3).times do
@tags << Faker::Discourse.tag
end
@tags.uniq
end
|
#title ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/discourse_dev/topic.rb', line 24
def title
if index <= I18n.t("faker.discourse.topics").count
Faker::Discourse.unique.topic
else
Faker::Lorem.unique.sentence(word_count: 3, supplemental: true, random_words_to_add: 4).chomp(".")
end
end
|
#user ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/discourse_dev/topic.rb', line 47
def user
return User.random if @category.groups.blank?
group_ids = @category.groups.pluck(:id)
user_ids = ::GroupUser.where(group_id: group_ids).pluck(:user_id)
user_count = user_ids.count
position = Faker::Number.between(from: 0, to: user_count - 1)
::User.find(user_ids[position] || Discourse::SYSTEM_USER_ID)
end
|