Skip to content

Commit

Permalink
Show poll user answers in subsequent sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
Senen committed Oct 18, 2022
1 parent 48d7ec7 commit f90d0d9
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 83 deletions.
2 changes: 1 addition & 1 deletion app/components/polls/questions/answers_component.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>
Expand Down
6 changes: 0 additions & 6 deletions app/components/polls/questions/answers_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ def already_answered?(question_answer)
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
Expand Down
13 changes: 0 additions & 13 deletions spec/components/polls/questions/answers_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

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)

Expand All @@ -33,18 +32,6 @@
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)

Expand Down
38 changes: 0 additions & 38 deletions spec/system/polls/polls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,44 +276,6 @@
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
Expand Down
25 changes: 0 additions & 25 deletions spec/system/polls/voter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,31 +163,6 @@
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
Expand Down

0 comments on commit f90d0d9

Please sign in to comment.