lib/discourse_dev/post.rb in discourse_dev-0.0.5 vs lib/discourse_dev/post.rb in discourse_dev-0.0.7
- old
+ new
@@ -27,24 +27,62 @@
skip_validations: true
}
end
def create!
- PostCreator.new(user, data).create!
+ begin
+ PostCreator.new(user, data).create!
+ rescue ActiveRecord::RecordNotSaved => e
+ puts e
+ end
end
def user
return User.random if topic.category.groups.blank?
return Discourse.system_user if @user_ids.blank?
-
+
position = Faker::Number.between(from: 0, to: @user_count - 1)
::User.find(@user_ids[position])
end
def populate!
@count.times do |i|
@index = i
create!
end
end
+
+ def self.add_replies!(args)
+ if !args[:topic_id]
+ puts "Topic ID is required. Aborting."
+ return
+ end
+
+ if !::Topic.find_by_id(args[:topic_id])
+ puts "Topic ID does not match topic in DB, aborting."
+ return
+ end
+
+ topic = ::Topic.find_by_id(args[:topic_id])
+ count = args[:count] ? args[:count].to_i : 50
+
+ puts "Creating #{count} replies in '#{topic.title}'"
+
+ count.times do |i|
+ @index = i
+ begin
+ reply = {
+ topic_id: topic.id,
+ raw: Faker::Markdown.sandwich(sentences: 5),
+ skip_validations: true
+ }
+ PostCreator.new(User.random, reply).create!
+ rescue ActiveRecord::RecordNotSaved => e
+ puts e
+ end
+ end
+
+ puts "Done!"
+ end
+
end
end