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
This commit is contained in:
voodoorai2000
2019-03-13 15:01:36 +01:00
committed by Javi Martín
parent 5abde6da6e
commit e1141d1cd3
2 changed files with 3 additions and 3 deletions

View File

@@ -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

View File

@@ -19,7 +19,7 @@
</td>
<% 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" %>