posts: rework post deletion to use dialog box.

Rework post deletion from using a separate page to using a dialog box,
like flagging.

* Add `DELETE /posts/:id` endpoint.
* Remove `POST /moderator/post/posts/:id/delete` endpoint.
This commit is contained in:
evazion
2020-08-03 19:28:10 -05:00
parent f1b0e31923
commit bca1f122d0
10 changed files with 69 additions and 62 deletions

View File

@@ -633,6 +633,43 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
end
end
context "destroy action" do
setup do
@approver = create(:approver)
end
should "delete the post" do
delete_auth post_path(@post), @approver, params: { commit: "Delete", post: { reason: "test" } }
assert_redirected_to @post
assert_equal(true, @post.reload.is_deleted?)
assert_equal("test", @post.flags.last.reason)
end
should "delete the post even if the deleter has flagged the post previously" do
create(:post_flag, post: @post, creator: @approver)
delete_auth post_path(@post), @approver, params: { commit: "Delete", post: { reason: "test" } }
assert_redirected_to @post
assert_equal(true, @post.reload.is_deleted?)
end
should "not delete the post if the user is unauthorized" do
delete_auth post_path(@post), @user, params: { commit: "Delete" }
assert_response 403
assert_equal(false, @post.is_deleted?)
end
should "render the delete post dialog for an xhr request" do
delete_auth post_path(@post), @approver, xhr: true
assert_response :success
assert_equal(false, @post.is_deleted?)
end
end
context "revert action" do
setup do
PostVersion.sqs_service.stubs(:merge?).returns(false)