Prevent balloting online after casting a ballot offline
This commit is contained in:
@@ -70,5 +70,9 @@ class Budget
|
||||
investments.where(group: group).first.heading
|
||||
end
|
||||
|
||||
def casted_offline?
|
||||
budget.poll&.voted_by?(user)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -241,6 +241,7 @@ class Budget
|
||||
return :no_ballots_allowed unless budget.balloting?
|
||||
return :different_heading_assigned_html unless ballot.valid_heading?(heading)
|
||||
return :not_enough_money_html if ballot.present? && !enough_money?(ballot)
|
||||
return :casted_offline if ballot.casted_offline?
|
||||
end
|
||||
|
||||
def permission_problem(user)
|
||||
|
||||
@@ -22,6 +22,7 @@ en:
|
||||
no_ballots_allowed: Selecting phase is closed
|
||||
different_heading_assigned_html: "You have already voted a different heading: %{heading_link}"
|
||||
change_ballot: change your votes
|
||||
casted_offline: You have already participated offline
|
||||
groups:
|
||||
show:
|
||||
title: Select an option
|
||||
|
||||
@@ -22,6 +22,7 @@ es:
|
||||
no_ballots_allowed: El periodo de votación está cerrado.
|
||||
different_heading_assigned_html: "Ya has votado proyectos de otra partida: %{heading_link}"
|
||||
change_ballot: cambiar tus votos
|
||||
casted_offline: Ya has participado presencialmente
|
||||
groups:
|
||||
show:
|
||||
title: Selecciona una opción
|
||||
|
||||
@@ -2,7 +2,10 @@ require "rails_helper"
|
||||
|
||||
feature "BudgetPolls", :with_frozen_time do
|
||||
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(:officer) { create(:poll_officer) }
|
||||
let(:admin) { create(:administrator) }
|
||||
@@ -67,10 +70,29 @@ feature "BudgetPolls", :with_frozen_time do
|
||||
end
|
||||
end
|
||||
|
||||
scenario "A citizen cannot vote online after voting offline" do
|
||||
# create scenario for an user that voted offline
|
||||
scenario "A citizen cannot vote online after voting offline", :js do
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user