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
#count, #populate!, populate!
Constructor Details
#initialize(count = DEFAULT_COUNT) ⇒ Topic
Returns a new instance of Topic.
9
10
11
12
13
|
# File 'lib/discourse_dev/topic.rb', line 9
def initialize(count = DEFAULT_COUNT)
super(::Topic, count)
@category_ids = ::Category.pluck(:id)
@user_count = ::User.count
end
|
Instance Method Details
#create! ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/discourse_dev/topic.rb', line 25
def create!
offset = rand(@user_count)
user = ::User.offset(offset).first
PostCreator.new(user, data).create!
putc "."
end
|
#data ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/discourse_dev/topic.rb', line 15
def data
{
title: Faker::Lorem.sentence(word_count: 3, supplemental: true, random_words_to_add: 4).chomp(".")[0, SiteSetting.max_topic_title_length],
raw: Faker::Markdown.sandwich(sentences: 5),
category_id: @category_ids.sample,
topic_opts: { custom_fields: { dev_sample: true } },
skip_validations: true
}
end
|