From f23073bb286984b05edd1d90f2817cde5fbe79be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 9 Oct 2017 13:12:44 +0200 Subject: [PATCH 1/5] Fixed already voted message in poll show --- app/views/polls/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index 19daf5e35..d626f4f11 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -39,7 +39,7 @@ <% else %> - <% if current_user && !@poll.votable_by?(current_user) %> + <% if current_user && @poll.votable_by?(current_user) %>
<%= t("polls.show.already_voted_in_web") %>
From 3fc3f9e88e76542b832e53aa3814a015d8ef9b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 9 Oct 2017 17:42:13 +0200 Subject: [PATCH 2/5] Fixed condition --- app/views/polls/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index d626f4f11..c9796b836 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -39,7 +39,7 @@ <% else %> - <% if current_user && @poll.votable_by?(current_user) %> + <% unless current_user && @poll.votable_by?(current_user) %>
<%= t("polls.show.already_voted_in_web") %>
From e1e9b431d79f2d0540db6e1a862b887b388c7abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 16 Oct 2017 20:10:49 +0200 Subject: [PATCH 3/5] Added tests --- spec/features/polls/voter_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index 256807928..409bcd09d 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -41,6 +41,27 @@ feature "Voter" do expect(Poll::Voter.first.origin).to eq("web") end + scenario "Voting via web as unverified user", :js do + poll = create(:poll) + + question = create(:poll_question, poll: poll) + answer1 = create(:poll_question_answer, question: question, title: 'Yes') + answer2 = create(:poll_question_answer, question: question, title: 'No') + + user = create(:user, :incomplete_verification) + + login_as user + visit poll_path(poll) + + within("#poll_question_#{question.id}_answers") do + expect(page).to_not have_link('Yes') + expect(page).to_not have_link('No') + end + + expect(page).to have_content("You must verify your account in order to answer") + expect(page).to_not have_content("You have already participated in this poll. If you vote again it will be overwritten") + end + scenario "Voting in booth", :js do user = create(:user, :in_census) From 58f57bc15b0ab88536e60fe987228dea3568b8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 17 Oct 2017 13:16:46 +0200 Subject: [PATCH 4/5] Added poll method `voted_in_web?` --- app/models/poll.rb | 4 ++++ app/views/polls/show.html.erb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index 84349bf0b..cd91db884 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -65,6 +65,10 @@ class Poll < ActiveRecord::Base Poll::Voter.where(poll: self, user: user, origin: "booth").exists? end + def voted_in_web?(user) + Poll::Voter.where(poll: self, user: user, origin: "web").exists? + end + def date_range unless starts_at.present? && ends_at.present? && starts_at <= ends_at errors.add(:starts_at, I18n.t('errors.messages.invalid_date_range')) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index c9796b836..b81ee2c7a 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -39,7 +39,7 @@ <% else %> - <% unless current_user && @poll.votable_by?(current_user) %> + <% if current_user && @poll.voted_in_web?(current_user) %>
<%= t("polls.show.already_voted_in_web") %>
From 712151b395d576cfcc775227af9d3f54f3977a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 17 Oct 2017 13:17:20 +0200 Subject: [PATCH 5/5] Tests improvements --- spec/features/polls/voter_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index 409bcd09d..21e73e238 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -54,8 +54,8 @@ feature "Voter" do visit poll_path(poll) within("#poll_question_#{question.id}_answers") do - expect(page).to_not have_link('Yes') - expect(page).to_not have_link('No') + expect(page).to_not have_link('Yes', href: "/questions/#{question.id}/answer?answer=Yes&token=") + expect(page).to_not have_link('No', href: "/questions/#{question.id}/answer?answer=No&token=") end expect(page).to have_content("You must verify your account in order to answer")