discourse/lib/tasks/build_test_topic.rake

50 lines
1.5 KiB
Ruby
Raw Normal View History

2013-02-05 14:16:51 -05:00
# Build a test topic full of links to test our replaceState/pushState functionality.
desc 'create pushstate/replacestate test topic'
task 'build_test_topic' => :environment do
puts 'Creating topic'
# Acceptable options:
#
# raw - raw text of post
2013-02-25 11:42:20 -05:00
# image_sizes - We can pass a list of the sizes of images in the post as a shortcut.
2013-02-05 14:16:51 -05:00
#
# When replying to a topic:
# topic_id - topic we're replying to
# reply_to_post_number - post number we're replying to
#
# When creating a topic:
# title - New topic title
# archetype - Topic archetype
# category - Category to assign to topic
# target_usernames - comma delimited list of usernames for membership (private message)
# meta_data - Topic meta data hash
evil_trout = User.find_by_username('EvilTrout')
first_post = PostCreator.new(evil_trout, raw: "This is the original post.", title: "pushState/replaceState test topic").create
topic = first_post.topic
topic_url = "#{Discourse.base_url}/t/#{Slug.for(topic.title)}/#{topic.id}"
99.times do |i|
post_number = (i + 2)
links = []
[-30, -10, 10, 30].each do |offset|
where = (post_number + offset)
2017-07-27 21:20:09 -04:00
if where >= (1) && where <= (100)
2013-02-05 14:16:51 -05:00
links << "Link to ##{where}: #{topic_url}/#{where}"
end
end
2013-02-25 11:42:20 -05:00
2013-02-05 14:16:51 -05:00
raw = <<eos
This is post ##{post_number}.
#{links.join("\n")}
eos
2013-02-25 11:42:20 -05:00
PostCreator.new(evil_trout, raw: raw, topic_id: topic.id).create
2013-02-05 14:16:51 -05:00
end
2013-02-25 11:42:20 -05:00
end