Add ballot sheet votes to the total count

This commit is contained in:
Jorge Barata
2022-02-07 01:18:48 +01:00
committed by Javi Martín
parent 5928f467f3
commit b507acb38b
2 changed files with 8 additions and 5 deletions

View File

@@ -7,6 +7,8 @@ class Poll::BallotSheet < ApplicationRecord
validates :poll_id, presence: true
validates :officer_assignment_id, presence: true
after_create :verify_ballots
def author
officer_assignment.officer.name
end

View File

@@ -2,9 +2,12 @@ require "rails_helper"
describe Poll::BallotSheet do
let(:ballot_sheet) do
build(:poll_ballot_sheet, poll: create(:poll),
budget = create(:budget)
investment1 = create(:budget_investment, budget: budget)
investment2 = create(:budget_investment, budget: budget)
build(:poll_ballot_sheet, poll: create(:poll, budget: budget),
officer_assignment: create(:poll_officer_assignment),
data: "1234;5678")
data: "#{investment1.id};#{investment2.id}")
end
context "Validations" do
@@ -36,9 +39,7 @@ describe Poll::BallotSheet do
describe "#verify_ballots" do
it "creates ballots for each document number" do
poll = create(:poll, :for_budget)
poll_ballot = create(:poll_ballot_sheet, poll: poll, data: "1,2,3;4,5,6")
poll_ballot.verify_ballots
create(:poll_ballot_sheet, poll: create(:poll, :for_budget), data: "1,2,3;4,5,6")
expect(Poll::Ballot.count).to eq(2)
expect(Budget::Ballot.count).to eq(2)