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

@@ -36,6 +36,18 @@ describe Legislation::Proposals::VotesController do
post :create, xhr: true, params: vote_params
end.not_to change { proposal.reload.votes_for.size }
end
it "redirects authenticated users without JavaScript to the same page" do
request.env["HTTP_REFERER"] = legislation_process_proposal_path(legislation_process, proposal)
sign_in create(:user, :level_two)
expect do
post :create, params: vote_params
end.to change { proposal.reload.votes_for.size }.by(1)
expect(response).to redirect_to legislation_process_proposal_path(legislation_process, proposal)
expect(flash[:notice]).to eq "Vote created successfully"
end
end
describe "DELETE destroy" do
@@ -52,5 +64,17 @@ describe Legislation::Proposals::VotesController do
delete :destroy, xhr: true, params: vote_params
end.to change { proposal.reload.votes_for.size }.by(-1)
end
it "redirects authenticated users without JavaScript to the same page" do
request.env["HTTP_REFERER"] = legislation_process_proposals_path(legislation_process)
sign_in user
expect do
delete :destroy, params: vote_params
end.to change { proposal.reload.votes_for.size }.by(-1)
expect(response).to redirect_to legislation_process_proposals_path(legislation_process)
expect(flash[:notice]).to eq "Vote deleted successfully"
end
end
end