diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 7efc0f1e8..8b254d440 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -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) { diff --git a/app/controllers/polls/questions_controller.rb b/app/controllers/polls/questions_controller.rb index 4f76fc672..51269cff1 100644 --- a/app/controllers/polls/questions_controller.rb +++ b/app/controllers/polls/questions_controller.rb @@ -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 diff --git a/app/views/polls/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb index 4c521107f..08030bc0e 100644 --- a/app/views/polls/questions/_answers.html.erb +++ b/app/views/polls/questions/_answers.html.erb @@ -9,12 +9,12 @@ <%= answer.title %> <% 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? %> diff --git a/spec/support/common_actions/polls.rb b/spec/support/common_actions/polls.rb index b097c4355..b571472c4 100644 --- a/spec/support/common_actions/polls.rb +++ b/spec/support/common_actions/polls.rb @@ -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 diff --git a/spec/system/polls/polls_spec.rb b/spec/system/polls/polls_spec.rb index d2631c873..c4ec85e99 100644 --- a/spec/system/polls/polls_spec.rb +++ b/spec/system/polls/polls_spec.rb @@ -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 diff --git a/spec/system/polls/voter_spec.rb b/spec/system/polls/voter_spec.rb index 336c2db0b..a629dcdf6 100644 --- a/spec/system/polls/voter_spec.rb +++ b/spec/system/polls/voter_spec.rb @@ -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."