Allow liking/unliking when JavaScript is disabled

Even if pretty much nobody uses a browser with JavaScript disabled when
navigating our sites, there might be times where JavaScript isn't loaded
for reasons like a slow internet connections not getting the JavaScript
files or a technical issue.

So we're making it possible to still use the like/unlike buttons in
these cases.
This commit is contained in:
Javi Martín
2023-10-11 14:11:27 +02:00
parent 38e81f2858
commit 7070b0915b
7 changed files with 81 additions and 1 deletions

View File

@@ -18,6 +18,19 @@ describe Debates::VotesController do
expect(response).to redirect_to new_user_session_path
end
it "redirects authenticated users without JavaScript to the same page" do
debate = create(:debate)
request.env["HTTP_REFERER"] = debate_path(debate)
sign_in create(:user)
expect do
post :create, params: { debate_id: debate.id, value: "yes" }
end.to change { debate.reload.votes_for.size }.by(1)
expect(response).to redirect_to debate_path(debate)
expect(flash[:notice]).to eq "Vote created successfully"
end
describe "Vote with too many anonymous votes" do
it "allows vote if user is allowed" do
Setting["max_ratio_anon_votes_on_debates"] = 100
@@ -52,5 +65,16 @@ describe Debates::VotesController do
delete :destroy, xhr: true, params: { debate_id: debate.id, id: vote }
end.to change { debate.reload.votes_for.size }.by(-1)
end
it "redirects authenticated users without JavaScript to the same page" do
request.env["HTTP_REFERER"] = debates_path
expect do
delete :destroy, params: { debate_id: debate.id, id: vote }
end.to change { debate.reload.votes_for.size }.by(-1)
expect(response).to redirect_to debates_path
expect(flash[:notice]).to eq "Vote deleted successfully"
end
end
end