Make poll feature work in browsers with javascript disabled
By using the Rails `button_to` helper (which generates a form), and adapting the response to `html` and `js` formats, the feature works with or without javascript enabled.
This commit is contained in:
@@ -1634,9 +1634,10 @@
|
||||
}
|
||||
|
||||
.poll-question-answers {
|
||||
@include flex-with-gap($line-height / 4);
|
||||
flex-wrap: wrap;
|
||||
|
||||
.button {
|
||||
margin-right: $line-height / 4;
|
||||
min-width: rem-calc(168);
|
||||
|
||||
@include breakpoint(medium down) {
|
||||
|
||||
@@ -11,5 +11,14 @@ class Polls::QuestionsController < ApplicationController
|
||||
answer.save_and_record_voter_participation
|
||||
|
||||
@answers_by_question_id = { @question.id => params[:answer] }
|
||||
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
redirect_to request.referer
|
||||
end
|
||||
format.js do
|
||||
render :answer
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
<%= answer.title %>
|
||||
</span>
|
||||
<% else %>
|
||||
<%= link_to answer.title,
|
||||
answer_question_path(question, answer: answer.title),
|
||||
method: :post,
|
||||
remote: true,
|
||||
title: t("poll_questions.show.vote_answer", answer: answer.title),
|
||||
class: "button secondary hollow" %>
|
||||
<%= button_to answer_question_path(question, answer: answer.title),
|
||||
remote: true,
|
||||
title: t("poll_questions.show.vote_answer", answer: answer.title),
|
||||
class: "button secondary hollow" do %>
|
||||
<%= answer.title %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% elsif !user_signed_in? %>
|
||||
|
||||
@@ -3,8 +3,10 @@ module Polls
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
click_link answer.to_s
|
||||
expect(page).not_to have_link(answer.to_s)
|
||||
click_button answer
|
||||
|
||||
expect(page).to have_css("span.answered", text: answer)
|
||||
expect(page).not_to have_button(answer)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -283,8 +283,8 @@ describe "Polls" do
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
expect(page).to have_content("Yes")
|
||||
expect(page).to have_content("No")
|
||||
expect(page).not_to have_link("Yes")
|
||||
expect(page).not_to have_link("No")
|
||||
expect(page).not_to have_button "Yes"
|
||||
expect(page).not_to have_button "No"
|
||||
end
|
||||
expect(page).to have_content("This poll has finished")
|
||||
end
|
||||
@@ -302,8 +302,8 @@ describe "Polls" do
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
expect(page).to have_content("Yes")
|
||||
expect(page).to have_content("No")
|
||||
expect(page).not_to have_link("Yes")
|
||||
expect(page).not_to have_link("No")
|
||||
expect(page).not_to have_button "Yes"
|
||||
expect(page).not_to have_button "No"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -317,8 +317,8 @@ describe "Polls" do
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
expect(page).to have_link("Yes")
|
||||
expect(page).to have_link("No")
|
||||
expect(page).to have_button "Yes"
|
||||
expect(page).to have_button "No"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -329,8 +329,8 @@ describe "Polls" do
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
expect(page).to have_link("Yes")
|
||||
expect(page).to have_link("No")
|
||||
expect(page).to have_button "Yes"
|
||||
expect(page).to have_button "No"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -343,8 +343,8 @@ describe "Polls" do
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
expect(page).to have_link("Yes")
|
||||
expect(page).to have_link("No")
|
||||
expect(page).to have_button "Yes"
|
||||
expect(page).to have_button "No"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -359,10 +359,10 @@ describe "Polls" do
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
click_link "Yes"
|
||||
click_button "Yes"
|
||||
|
||||
expect(page).not_to have_link("Yes")
|
||||
expect(page).to have_link("No")
|
||||
expect(page).not_to have_button "Yes"
|
||||
expect(page).to have_button "No"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -377,15 +377,15 @@ describe "Polls" do
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
click_link "Yes"
|
||||
click_button "Yes"
|
||||
|
||||
expect(page).not_to have_link("Yes")
|
||||
expect(page).to have_link("No")
|
||||
expect(page).not_to have_button "Yes"
|
||||
expect(page).to have_button "No"
|
||||
|
||||
click_link "No"
|
||||
click_button "No"
|
||||
|
||||
expect(page).not_to have_link("No")
|
||||
expect(page).to have_link("Yes")
|
||||
expect(page).not_to have_button "No"
|
||||
expect(page).to have_button "Yes"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -400,30 +400,30 @@ describe "Polls" do
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
click_link "Yes"
|
||||
click_button "Yes"
|
||||
|
||||
expect(page).not_to have_link("Yes")
|
||||
expect(page).to have_link("No")
|
||||
expect(page).not_to have_button "Yes"
|
||||
expect(page).to have_button "No"
|
||||
end
|
||||
|
||||
click_link "Sign out"
|
||||
login_as user
|
||||
visit poll_path(poll)
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
click_link "Yes"
|
||||
click_button "Yes"
|
||||
|
||||
expect(page).not_to have_link("Yes")
|
||||
expect(page).to have_link("No")
|
||||
expect(page).not_to have_button "Yes"
|
||||
expect(page).to have_button "No"
|
||||
end
|
||||
|
||||
click_link "Sign out"
|
||||
login_as user
|
||||
visit poll_path(poll)
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
click_link "No"
|
||||
click_button "No"
|
||||
|
||||
expect(page).not_to have_link("No")
|
||||
expect(page).to have_link("Yes")
|
||||
expect(page).not_to have_button "No"
|
||||
expect(page).to have_button "Yes"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -450,6 +450,20 @@ describe "Polls" do
|
||||
expect("Not restricted").to appear_before("Geozone Poll")
|
||||
expect("Geozone Poll").to appear_before("A Poll")
|
||||
end
|
||||
|
||||
scenario "Level 2 users answering in a browser without javascript", :no_js do
|
||||
question = create(:poll_question, :yes_no, poll: poll)
|
||||
user = create(:user, :level_two)
|
||||
login_as user
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
click_button "Yes"
|
||||
|
||||
expect(page).not_to have_button "Yes"
|
||||
expect(page).to have_button "No"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "Booth & Website", :with_frozen_time do
|
||||
@@ -481,8 +495,8 @@ describe "Polls" do
|
||||
expect(page).to have_content("Yes")
|
||||
expect(page).to have_content("No")
|
||||
|
||||
expect(page).not_to have_link("Yes")
|
||||
expect(page).not_to have_link("No")
|
||||
expect(page).not_to have_button "Yes"
|
||||
expect(page).not_to have_button "No"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,8 +23,8 @@ describe "Voter" do
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
click_link answer_yes.title
|
||||
expect(page).not_to have_link(answer_yes.title)
|
||||
click_button answer_yes.title
|
||||
expect(page).not_to have_button(answer_yes.title)
|
||||
end
|
||||
|
||||
expect(Poll::Voter.count).to eq(1)
|
||||
@@ -38,8 +38,8 @@ describe "Voter" do
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
expect(page).not_to have_link(answer_yes.title, href: "/questions/#{question.id}/answer?answer=#{answer_yes.title}")
|
||||
expect(page).not_to have_link(answer_no.title, href: "/questions/#{question.id}/answer?answer=#{answer_no.title}")
|
||||
expect(page).to have_link(answer_yes.title, href: verification_path)
|
||||
expect(page).to have_link(answer_no.title, href: verification_path)
|
||||
end
|
||||
|
||||
expect(page).to have_content("You must verify your account in order to answer")
|
||||
@@ -145,7 +145,7 @@ describe "Voter" do
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
expect(page).not_to have_link(answer_yes.title)
|
||||
expect(page).not_to have_button(answer_yes.title)
|
||||
end
|
||||
expect(page).to have_content "You have already participated in a physical booth. You can not participate again."
|
||||
expect(Poll::Voter.count).to eq(1)
|
||||
@@ -173,7 +173,7 @@ describe "Voter" do
|
||||
|
||||
expect(page).to have_content "You have already participated in this poll. If you vote again it will be overwritten."
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
expect(page).not_to have_link(answer_yes.title)
|
||||
expect(page).not_to have_button(answer_yes.title)
|
||||
end
|
||||
|
||||
unfreeze_time
|
||||
@@ -184,8 +184,8 @@ describe "Voter" do
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
expect(page).to have_link(answer_yes.title)
|
||||
expect(page).to have_link(answer_no.title)
|
||||
expect(page).to have_button(answer_yes.title)
|
||||
expect(page).to have_button(answer_no.title)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -209,7 +209,7 @@ describe "Voter" do
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
expect(page).not_to have_link(answer_yes.title)
|
||||
expect(page).not_to have_button(answer_yes.title)
|
||||
end
|
||||
|
||||
expect(page).to have_content "You have already participated in a physical booth. You can not participate again."
|
||||
|
||||
Reference in New Issue
Block a user