mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: return populated data at the end of the method. (#13739)
And some minor refactoring.
This commit is contained in:
parent
5cd447695e
commit
74b3730143
@ -38,6 +38,7 @@ module DiscourseDev
|
|||||||
post = PostCreator.new(user, data).create!
|
post = PostCreator.new(user, data).create!
|
||||||
topic.reload
|
topic.reload
|
||||||
generate_likes(post)
|
generate_likes(post)
|
||||||
|
post
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_likes(post)
|
def generate_likes(post)
|
||||||
@ -63,9 +64,11 @@ module DiscourseDev
|
|||||||
def populate!
|
def populate!
|
||||||
generate_likes(topic.first_post)
|
generate_likes(topic.first_post)
|
||||||
|
|
||||||
@count.times do
|
super(ignore_current_count: true)
|
||||||
create!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def current_count
|
||||||
|
topic.posts_count - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.add_replies!(args)
|
def self.add_replies!(args)
|
||||||
|
@ -29,7 +29,8 @@ module DiscourseDev
|
|||||||
record
|
record
|
||||||
end
|
end
|
||||||
|
|
||||||
def populate!
|
def populate!(ignore_current_count: false)
|
||||||
|
unless ignore_current_count
|
||||||
if current_count >= @count
|
if current_count >= @count
|
||||||
puts "Already have #{current_count} #{type} records"
|
puts "Already have #{current_count} #{type} records"
|
||||||
|
|
||||||
@ -45,15 +46,16 @@ module DiscourseDev
|
|||||||
else
|
else
|
||||||
puts "Creating #{@count} sample #{type} records"
|
puts "Creating #{@count} sample #{type} records"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
records = []
|
records = []
|
||||||
@count.times do
|
@count.times do
|
||||||
records << create!
|
records << create!
|
||||||
putc "."
|
putc "." unless type == :post
|
||||||
end
|
end
|
||||||
|
|
||||||
|
puts unless type == :post
|
||||||
DiscourseEvent.trigger(:after_populate_dev_records, records, type)
|
DiscourseEvent.trigger(:after_populate_dev_records, records, type)
|
||||||
puts
|
|
||||||
records
|
records
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -67,21 +67,24 @@ module DiscourseDev
|
|||||||
def create!
|
def create!
|
||||||
@category = Category.random
|
@category = Category.random
|
||||||
user = self.user
|
user = self.user
|
||||||
topic = Faker::DiscourseMarkdown.with_user(user.id) { data }
|
topic_data = Faker::DiscourseMarkdown.with_user(user.id) { data }
|
||||||
post = PostCreator.new(user, topic).create!
|
post = PostCreator.new(user, topic_data).create!
|
||||||
|
|
||||||
if override = @settings.dig(:replies, :overrides).find { |o| o[:title] == topic[:title] }
|
if override = @settings.dig(:replies, :overrides).find { |o| o[:title] == topic_data[:title] }
|
||||||
reply_count = override[:count]
|
reply_count = override[:count]
|
||||||
else
|
else
|
||||||
reply_count = Faker::Number.between(from: @settings.dig(:replies, :min), to: @settings.dig(:replies, :max))
|
reply_count = Faker::Number.between(from: @settings.dig(:replies, :min), to: @settings.dig(:replies, :max))
|
||||||
end
|
end
|
||||||
|
|
||||||
Post.new(post.topic, reply_count).populate!
|
topic = post.topic
|
||||||
|
Post.new(topic, reply_count).populate!
|
||||||
|
topic
|
||||||
end
|
end
|
||||||
|
|
||||||
def populate!
|
def populate!
|
||||||
super
|
topics = super
|
||||||
delete_unwanted_sidekiq_jobs
|
delete_unwanted_sidekiq_jobs
|
||||||
|
topics
|
||||||
end
|
end
|
||||||
|
|
||||||
def user
|
def user
|
||||||
|
Loading…
Reference in New Issue
Block a user