Show poll user answers in subsequent sessions

This commit is contained in:
Senén Rodero Rodríguez
2022-09-29 12:20:35 +02:00
parent 48d7ec75d0
commit f90d0d9c4d
5 changed files with 1 additions and 83 deletions

View File

@@ -1,7 +1,7 @@
<div class="poll-question-answers">
<% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %>
<% question_answers.each do |question_answer| %>
<% if already_answered?(question_answer) && !voted_before_sign_in? %>
<% if already_answered?(question_answer) %>
<span class="button answered"
title="<%= t("poll_questions.show.voted", answer: question_answer.title) %>">
<%= question_answer.title %>

View File

@@ -10,12 +10,6 @@ class Polls::Questions::AnswersComponent < ApplicationComponent
user_answers.find_by(answer: question_answer.title).present?
end
def voted_before_sign_in?
user_answers.any? do |vote|
vote.updated_at < current_user.current_sign_in_at
end
end
def question_answers
question.question_answers
end

View File

@@ -22,7 +22,6 @@ describe Polls::Questions::AnswersComponent do
it "renders a span instead of a button for existing user answers" do
user = create(:user, :verified)
allow(user).to receive(:current_sign_in_at).and_return(user.created_at)
create(:poll_answer, author: user, question: question, answer: "Yes")
sign_in(user)
@@ -33,18 +32,6 @@ describe Polls::Questions::AnswersComponent do
expect(page).to have_button "No"
end
it "hides current answer and shows buttons in successive sessions" do
user = create(:user, :verified)
create(:poll_answer, author: user, question: question, answer: "Yes")
allow(user).to receive(:current_sign_in_at).and_return(Time.current)
sign_in(user)
render_inline Polls::Questions::AnswersComponent.new(question)
expect(page).to have_button "Yes"
expect(page).to have_button "No"
end
it "when user is not signed in, renders answers links pointing to user sign in path" do
render_inline Polls::Questions::AnswersComponent.new(question)

View File

@@ -276,44 +276,6 @@ describe "Polls" do
end
end
scenario "Level 2 votes, signs out, signs in, votes again" do
poll.update!(geozone_restricted: true)
poll.geozones << geozone
question = create(:poll_question, :yes_no, poll: poll)
user = create(:user, :level_two, geozone: geozone)
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
click_link "Sign out"
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
click_link "Sign out"
login_as user
visit poll_path(poll)
within("#poll_question_#{question.id}_answers") do
click_button "No"
expect(page).not_to have_button "No"
expect(page).to have_button "Yes"
end
end
scenario "Shows SDG tags when feature is enabled" do
Setting["feature.sdg"] = true
Setting["sdg.process.polls"] = true

View File

@@ -163,31 +163,6 @@ describe "Voter" do
expect(page).to have_content "1"
end
end
scenario "Trying to vote in web again" do
login_as user
vote_for_poll_via_web(poll, question, answer_yes.title)
expect(Poll::Voter.count).to eq(1)
visit poll_path(poll)
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_button(answer_yes.title)
end
unfreeze_time
click_link "Sign out"
login_as user
visit poll_path(poll)
within("#poll_question_#{question.id}_answers") do
expect(page).to have_button(answer_yes.title)
expect(page).to have_button(answer_no.title)
end
end
end
scenario "Voting in poll and then verifiying account" do