Prevent balloting online after casting a ballot offline

This commit is contained in:
rgarcia
2018-06-04 20:02:00 +02:00
committed by Javi Martín
parent 20a3f6539d
commit aa7441271d
5 changed files with 33 additions and 4 deletions

View File

@@ -70,5 +70,9 @@ class Budget
investments.where(group: group).first.heading investments.where(group: group).first.heading
end end
def casted_offline?
budget.poll&.voted_by?(user)
end
end end
end end

View File

@@ -241,6 +241,7 @@ class Budget
return :no_ballots_allowed unless budget.balloting? return :no_ballots_allowed unless budget.balloting?
return :different_heading_assigned_html unless ballot.valid_heading?(heading) return :different_heading_assigned_html unless ballot.valid_heading?(heading)
return :not_enough_money_html if ballot.present? && !enough_money?(ballot) return :not_enough_money_html if ballot.present? && !enough_money?(ballot)
return :casted_offline if ballot.casted_offline?
end end
def permission_problem(user) def permission_problem(user)

View File

@@ -22,6 +22,7 @@ en:
no_ballots_allowed: Selecting phase is closed no_ballots_allowed: Selecting phase is closed
different_heading_assigned_html: "You have already voted a different heading: %{heading_link}" different_heading_assigned_html: "You have already voted a different heading: %{heading_link}"
change_ballot: change your votes change_ballot: change your votes
casted_offline: You have already participated offline
groups: groups:
show: show:
title: Select an option title: Select an option

View File

@@ -22,6 +22,7 @@ es:
no_ballots_allowed: El periodo de votación está cerrado. no_ballots_allowed: El periodo de votación está cerrado.
different_heading_assigned_html: "Ya has votado proyectos de otra partida: %{heading_link}" different_heading_assigned_html: "Ya has votado proyectos de otra partida: %{heading_link}"
change_ballot: cambiar tus votos change_ballot: cambiar tus votos
casted_offline: Ya has participado presencialmente
groups: groups:
show: show:
title: Selecciona una opción title: Selecciona una opción

View File

@@ -2,7 +2,10 @@ require "rails_helper"
feature "BudgetPolls", :with_frozen_time do feature "BudgetPolls", :with_frozen_time do
let(:budget) { create(:budget, :balloting) } let(:budget) { create(:budget, :balloting) }
let(:poll) { create(:poll, :current) } let(:group) { create(:budget_group, budget: budget) }
let(:heading) { create(:budget_heading, group: group) }
let(:investment) { create(:budget_investment, :selected, heading: heading) }
let(:poll) { create(:poll, :current, budget: budget) }
let(:booth) { create(:poll_booth) } let(:booth) { create(:poll_booth) }
let(:officer) { create(:poll_officer) } let(:officer) { create(:poll_officer) }
let(:admin) { create(:administrator) } let(:admin) { create(:administrator) }
@@ -67,10 +70,29 @@ feature "BudgetPolls", :with_frozen_time do
end end
end end
scenario "A citizen cannot vote online after voting offline" do scenario "A citizen cannot vote online after voting offline", :js do
# create scenario for an user that voted offline user = create(:user, :in_census)
# Check the citizen cannot vote online login_through_form_as_officer(officer.user)
visit new_officing_residence_path
officing_verify_residence
within("#poll_#{poll.id}") do
click_button("Confirm vote")
end
expect(page).to have_content "Vote introduced!"
login_as(user)
visit budget_investment_path(budget, investment)
find("div.ballot").hover
within("#budget_investment_#{investment.id}") do
expect(page).to have_content "You have already participated offline"
expect(page).to have_css(".add a", visible: false)
end
end end
end end