mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 10:27:54 +08:00
DEV: Add rake task to bulk delete posts (#31576)
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.
This commit is contained in:
21
spec/lib/tasks/destroy_rake_spec.rb
Normal file
21
spec/lib/tasks/destroy_rake_spec.rb
Normal file
@ -0,0 +1,21 @@
|
||||
# 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
|
Reference in New Issue
Block a user