From 8b2f6d454c302401f3a14fbbbcd916327a2d303a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Sat, 7 Oct 2017 17:33:27 +0200 Subject: [PATCH] Show poll answers in poll show view after voting on a booth If the user votes in a booth, it can see the poll and answers but can't see what he/she voted and the answers are inactive (no link, inactive ui style). --- app/views/polls/questions/_answers.html.erb | 6 +++--- app/views/polls/show.html.erb | 6 +++--- spec/features/polls/polls_spec.rb | 12 ++++++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/views/polls/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb index 7cdb50cfb..7d9bc4cac 100644 --- a/app/views/polls/questions/_answers.html.erb +++ b/app/views/polls/questions/_answers.html.erb @@ -1,8 +1,8 @@
- <% if can?(:answer, question) %> + <% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %> <% question.question_answers.each do |answer| %> - <% if @answers_by_question_id[question.id] == answer.title && - (!voted_before_sign_in(question) || + <% if @answers_by_question_id[question.id] == answer.title && + (!voted_before_sign_in(question) || question.poll.voted_in_booth?(current_user)) %> "> diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 126617684..80d8db60e 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -50,10 +50,10 @@ <%= t("polls.show.already_voted_in_web") %>
<% end %> + <% end %> - <% @questions.each do |question| %> - <%= render 'polls/questions/question', question: question, token: @token %> - <% end %> + <% @questions.each do |question| %> + <%= render 'polls/questions/question', question: question, token: @token %> <% end %> diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index 8f7a9b2de..d2be04447 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -319,10 +319,14 @@ feature 'Polls' do visit poll_path(poll) expect(page).to have_content "You have already participated in a physical booth. You can not participate again." - expect(page).to have_content('Han Solo') - expect(page).to have_content('Chewbacca') - expect(page).to_not have_link('Han Solo') - expect(page).to_not have_link('Chewbacca') + + within("#poll_question_#{question.id}_answers") do + expect(page).to have_content('Han Solo') + expect(page).to have_content('Chewbacca') + + expect(page).to_not have_link('Han Solo') + expect(page).to_not have_link('Chewbacca') + end end end