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:
@@ -10,6 +10,7 @@ module Comments
|
|||||||
@comment.vote_by(voter: current_user, vote: params[:value])
|
@comment.vote_by(voter: current_user, vote: params[:value])
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
format.html { redirect_to request.referer, notice: I18n.t("flash.actions.create.vote") }
|
||||||
format.js { render :show }
|
format.js { render :show }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -18,6 +19,7 @@ module Comments
|
|||||||
@comment.unvote_by(current_user)
|
@comment.unvote_by(current_user)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
format.html { redirect_to request.referer, notice: I18n.t("flash.actions.destroy.vote") }
|
||||||
format.js { render :show }
|
format.js { render :show }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ module Debates
|
|||||||
@debate.register_vote(current_user, params[:value])
|
@debate.register_vote(current_user, params[:value])
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
format.html { redirect_to request.referer, notice: I18n.t("flash.actions.create.vote") }
|
||||||
format.js { render :show }
|
format.js { render :show }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -17,6 +18,7 @@ module Debates
|
|||||||
@debate.unvote_by(current_user)
|
@debate.unvote_by(current_user)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
format.html { redirect_to request.referer, notice: I18n.t("flash.actions.destroy.vote") }
|
||||||
format.js { render :show }
|
format.js { render :show }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ module Legislation
|
|||||||
@proposal.vote_by(voter: current_user, vote: params[:value])
|
@proposal.vote_by(voter: current_user, vote: params[:value])
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
format.html { redirect_to request.referer, notice: I18n.t("flash.actions.create.vote") }
|
||||||
format.js { render :show }
|
format.js { render :show }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -21,6 +22,7 @@ module Legislation
|
|||||||
@proposal.unvote_by(current_user)
|
@proposal.unvote_by(current_user)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
format.html { redirect_to request.referer, notice: I18n.t("flash.actions.destroy.vote") }
|
||||||
format.js { render :show }
|
format.js { render :show }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ en:
|
|||||||
support: "Investment supported successfully"
|
support: "Investment supported successfully"
|
||||||
topic: "Topic created successfully."
|
topic: "Topic created successfully."
|
||||||
valuator_group: "Valuator group created successfully"
|
valuator_group: "Valuator group created successfully"
|
||||||
|
vote: "Vote created successfully"
|
||||||
save_changes:
|
save_changes:
|
||||||
notice: Changes saved
|
notice: Changes saved
|
||||||
update:
|
update:
|
||||||
@@ -35,3 +36,4 @@ en:
|
|||||||
topic: "Topic deleted successfully."
|
topic: "Topic deleted successfully."
|
||||||
poll_question_answer_video: "Answer video deleted successfully."
|
poll_question_answer_video: "Answer video deleted successfully."
|
||||||
valuator_group: "Valuator group deleted successfully"
|
valuator_group: "Valuator group deleted successfully"
|
||||||
|
vote: "Vote deleted successfully"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Comments::VotesController do
|
describe Comments::VotesController do
|
||||||
let(:comment) { create(:comment) }
|
let(:comment) { create(:debate_comment) }
|
||||||
|
|
||||||
describe "POST create" do
|
describe "POST create" do
|
||||||
it "allows voting" do
|
it "allows voting" do
|
||||||
@@ -11,6 +11,18 @@ describe Comments::VotesController do
|
|||||||
post :create, xhr: true, params: { comment_id: comment.id, value: "yes" }
|
post :create, xhr: true, params: { comment_id: comment.id, value: "yes" }
|
||||||
end.to change { comment.reload.votes_for.size }.by(1)
|
end.to change { comment.reload.votes_for.size }.by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "redirects authenticated users without JavaScript to the same page" do
|
||||||
|
request.env["HTTP_REFERER"] = comment_path(comment)
|
||||||
|
sign_in create(:user)
|
||||||
|
|
||||||
|
expect do
|
||||||
|
post :create, params: { comment_id: comment.id, value: "yes" }
|
||||||
|
end.to change { comment.reload.votes_for.size }.by(1)
|
||||||
|
|
||||||
|
expect(response).to redirect_to comment_path(comment)
|
||||||
|
expect(flash[:notice]).to eq "Vote created successfully"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "DELETE destroy" do
|
describe "DELETE destroy" do
|
||||||
@@ -30,5 +42,17 @@ describe Comments::VotesController do
|
|||||||
delete :destroy, xhr: true, params: { comment_id: comment.id, id: vote }
|
delete :destroy, xhr: true, params: { comment_id: comment.id, id: vote }
|
||||||
end.to change { comment.reload.votes_for.size }.by(-1)
|
end.to change { comment.reload.votes_for.size }.by(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "redirects authenticated users without JavaScript to the same page" do
|
||||||
|
request.env["HTTP_REFERER"] = debate_path(comment.commentable)
|
||||||
|
sign_in user
|
||||||
|
|
||||||
|
expect do
|
||||||
|
delete :destroy, params: { comment_id: comment.id, id: vote }
|
||||||
|
end.to change { comment.reload.votes_for.size }.by(-1)
|
||||||
|
|
||||||
|
expect(response).to redirect_to debate_path(comment.commentable)
|
||||||
|
expect(flash[:notice]).to eq "Vote deleted successfully"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,6 +18,19 @@ describe Debates::VotesController do
|
|||||||
expect(response).to redirect_to new_user_session_path
|
expect(response).to redirect_to new_user_session_path
|
||||||
end
|
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
|
describe "Vote with too many anonymous votes" do
|
||||||
it "allows vote if user is allowed" do
|
it "allows vote if user is allowed" do
|
||||||
Setting["max_ratio_anon_votes_on_debates"] = 100
|
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 }
|
delete :destroy, xhr: true, params: { debate_id: debate.id, id: vote }
|
||||||
end.to change { debate.reload.votes_for.size }.by(-1)
|
end.to change { debate.reload.votes_for.size }.by(-1)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -36,6 +36,18 @@ describe Legislation::Proposals::VotesController do
|
|||||||
post :create, xhr: true, params: vote_params
|
post :create, xhr: true, params: vote_params
|
||||||
end.not_to change { proposal.reload.votes_for.size }
|
end.not_to change { proposal.reload.votes_for.size }
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "DELETE destroy" do
|
describe "DELETE destroy" do
|
||||||
@@ -52,5 +64,17 @@ describe Legislation::Proposals::VotesController do
|
|||||||
delete :destroy, xhr: true, params: vote_params
|
delete :destroy, xhr: true, params: vote_params
|
||||||
end.to change { proposal.reload.votes_for.size }.by(-1)
|
end.to change { proposal.reload.votes_for.size }.by(-1)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user