From e1141d1cd36ee0f1377d7f9c77b8cbef7bbbced6 Mon Sep 17 00:00:00 2001 From: voodoorai2000 Date: Wed, 13 Mar 2019 15:01:36 +0100 Subject: [PATCH] Display already voted message for budget polls Budget polls behave slightly differently to non-budget polls. In budget polls we use Budget::Ballot::Lines to verify if a user has already voted online. In non-budget polls we use Poll::Voter to verify this. In this commit we are adding an extra check to make sure that the correct message is displayed if the user has already voted online for a budget poll[1] [1] https://github.com/AyuntamientoMadrid/consul/blob/master/spec/features/budget_polls/voter_spec.rb#L122 --- app/models/poll.rb | 4 ++-- app/views/officing/voters/new.html.erb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index 6d0e344b0..30068820c 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -91,12 +91,12 @@ class Poll < ApplicationRecord end def votable_by?(user) - return false if user_has_an_online_ballot(user) + return false if user_has_an_online_ballot?(user) answerable_by?(user) && not_voted_by?(user) end - def user_has_an_online_ballot(user) + def user_has_an_online_ballot?(user) budget.present? && budget.ballots.find_by(user: user)&.lines.present? end diff --git a/app/views/officing/voters/new.html.erb b/app/views/officing/voters/new.html.erb index 8f218c09c..e88e86d85 100644 --- a/app/views/officing/voters/new.html.erb +++ b/app/views/officing/voters/new.html.erb @@ -19,7 +19,7 @@ <% if poll.votable_by?(@user) %> <%= render "can_vote", poll: poll %> - <% elsif poll.voted_by?(@user) %> + <% elsif poll.voted_by?(@user) || poll.user_has_an_online_ballot?(@user) %> <%= render "already_voted" %> <% else %> <%= render "cannot_vote" %>