Class: DiscourseDev::Topic

Inherits:
Record
  • Object
show all
Defined in:
lib/discourse_dev/topic.rb

Constant Summary

Constants inherited from Record

Record::DEFAULT_COUNT

Instance Attribute Summary

Attributes inherited from Record

#count, #model, #type

Instance Method Summary collapse

Methods inherited from Record

#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



37
38
39
40
41
42
43
# File 'lib/discourse_dev/topic.rb', line 37

def create!
  offset = rand(@user_count)
  user = ::User.offset(offset).first

  PostCreator.new(user, data).create!
  putc "."
end

#dataObject



15
16
17
18
19
20
21
22
23
24
# 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: @category_ids.sample,
    tags: tags,
    topic_opts: { custom_fields: { dev_sample: true } },
    skip_validations: true
  }
end

#tagsObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/discourse_dev/topic.rb', line 26

def tags
  @tags = []
  keys = ["model", "make", "manufacture"]

  Faker::Number.between(from: 0, to: 3).times do |index|
    @tags << Faker::Vehicle.send(keys[index])
  end

  @tags
end