docbrown/spec/requests/comments_destroy_spec.rb
Andy Zhao 0785720908 Add comment policy and specs (#475)
* Fix edge case with apostrophes

* Add comment policy and specs

* Add login for deleting comment spec

* Change test to raise pundit error instead of 404

* Clean up comment destroy request specs

* Remove redundant raise
2018-06-21 17:20:34 -04:00

55 lines
1.5 KiB
Ruby

require "rails_helper"
RSpec.describe "CommentsDestroy", type: :request do
let(:user) { create(:user) }
let(:article) { create(:article, user_id: user.id) }
before do
sign_in user
end
describe "GET /:username/comment/:id_code/delete_confirm" do
it "renders the confirmation message" do
comment = create(:comment, user_id: user.id, commentable_id: article.id)
get comment.path + "/delete_confirm"
expect(response.body).to include("Are you sure you want to delete this comment")
end
end
describe "DELETE /comments/:id" do
context "when comment has no children" do
it "destroys the comment" do
comment = create(:comment, user_id: user.id, commentable_id: article.id)
delete "/comments/#{comment.id}"
expect(Comment.all.size).to eq(0)
end
end
context "when comment has children" do
let(:parent_comment) { create(:comment, user_id: user.id, commentable_id: article.id) }
let(:child_comment) do
create(
:comment,
user_id: user.id,
commentable_id: article.id,
parent_id: parent_comment.id,
)
end
before do
parent_comment
child_comment
delete "/comments/#{parent_comment.id}"
end
it "marks the comment as deleted" do
expect(Comment.first.deleted).to eq(true)
end
it "renders [deleted]" do
get parent_comment.path
expect(response.body).to include "[deleted]"
end
end
end
end