diff --git a/app/models/budget/ballot.rb b/app/models/budget/ballot.rb index c35222f3a..7dc618360 100644 --- a/app/models/budget/ballot.rb +++ b/app/models/budget/ballot.rb @@ -70,5 +70,9 @@ class Budget investments.where(group: group).first.heading end + def casted_offline? + budget.poll&.voted_by?(user) + end + end end diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 4dae6c3ac..fa95de72e 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -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) diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index 3fd88cd48..d7bd7235d 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -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 diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index c827b2349..982149b5a 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -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 diff --git a/spec/features/budget_polls/voter_spec.rb b/spec/features/budget_polls/voter_spec.rb index 2b887c29c..8808177f4 100644 --- a/spec/features/budget_polls/voter_spec.rb +++ b/spec/features/budget_polls/voter_spec.rb @@ -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