Allow undo votes in comments votes component

This commit is contained in:
taitus
2023-09-20 16:10:36 +02:00
parent f87a332c3e
commit 718fcba6d8
16 changed files with 101 additions and 36 deletions

View File

@@ -12,4 +12,23 @@ describe Comments::VotesController do
end.to change { comment.reload.votes_for.size }.by(1)
end
end
describe "DELETE destroy" do
let(:user) { create(:user) }
let!(:vote) { create(:vote, votable: comment, voter: user) }
it "redirects unidentified users to the sign in page" do
delete :destroy, params: { comment_id: comment.id, id: vote }
expect(response).to redirect_to new_user_session_path
end
it "allows undoing a vote" do
sign_in user
expect do
delete :destroy, xhr: true, params: { comment_id: comment.id, id: vote }
end.to change { comment.reload.votes_for.size }.by(-1)
end
end
end