mirror of
https://github.com/discourse/discourse.git
synced 2025-05-26 06:41:24 +08:00

This PR adds a destroy:posts rake task that can be used to hard-delete a list of posts. Useful for dealing with large amounts of spam that has been soft deleted and needs to go. Notes: Works on both non-deleted and soft-deleted posts. (We might want to change this to work on only soft-deleted posts?) Works exclusively on post IDs. We can't mix topic and post IDs as they might clash, and we have no way of resolving that ambiguity. Accepts either a rake-style array of IDs or, more conveniently, you can pipe the argument in through STDIN. Added a confirmation step since it's a fairly destructive operation.
22 lines
539 B
Ruby
22 lines
539 B
Ruby
# frozen_string_literal: true
|
|
|
|
describe "destroy:posts" do # rubocop:disable RSpec/DescribeClass
|
|
subject(:task) { subject }
|
|
|
|
include_context "in a rake task"
|
|
|
|
# No console output in test suite, thanks.
|
|
before { STDOUT.stubs(:puts) }
|
|
|
|
it "accepts a list of post IDs piped through STDIN" do
|
|
destroy_task = instance_spy(DestroyTask)
|
|
DestroyTask.stubs(:new).returns(destroy_task)
|
|
|
|
STDIN.stubs(:read).returns("1,2,3\n")
|
|
|
|
task.invoke
|
|
|
|
expect(destroy_task).to have_received(:destroy_posts).with(%w[1 2 3])
|
|
end
|
|
end
|