Simplify poll stats test

Adding the option to assign a poll to a poll recount factory meant we
didn't need to create so much data.

Also note we're removing the `create(:poll_voter, origin: "booth")`
code, since it isn't used in the stats calculations.
This commit is contained in:
Javi Martín
2019-01-11 20:52:39 +01:00
parent 4830b563ea
commit 4a3115607a
2 changed files with 24 additions and 10 deletions

View File

@@ -88,7 +88,12 @@ FactoryBot.define do
poll
association :user, :level_two
association :officer, factory: :poll_officer
from_web
trait :from_web do
origin "web"
token SecureRandom.hex(32)
end
trait :from_booth do
origin "booth"
@@ -129,6 +134,16 @@ FactoryBot.define do
factory :poll_recount, class: "Poll::Recount" do
association :author, factory: :user
origin "web"
trait :from_booth do
origin "booth"
transient { poll nil }
booth_assignment do
association :poll_booth_assignment, poll: poll
end
end
end
factory :officing_residence, class: "Officing::Residence" do

View File

@@ -2,16 +2,15 @@ require "rails_helper"
describe Poll::Stats do
describe "Calculate stats" do
it "Generate the correct stats" do
describe "#generate" do
it "generates the correct stats" do
poll = create(:poll)
booth = create(:poll_booth)
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
create(:poll_voter, poll: poll, origin: "web")
3.times {create(:poll_voter, poll: poll, origin: "booth")}
create(:poll_voter, poll: poll)
create(:poll_recount, origin: "booth", white_amount: 1, null_amount: 0, total_amount: 2, booth_assignment_id: booth_assignment.id)
stats = described_class.new(poll).generate
2.times { create(:poll_voter, :from_web, poll: poll) }
3.times { create(:poll_voter, :from_booth, poll: poll) }
create(:poll_recount, :from_booth, poll: poll,
white_amount: 1, null_amount: 0, total_amount: 2)
stats = Poll::Stats.new(poll).generate
expect(stats[:total_participants]).to eq(5)
expect(stats[:total_participants_web]).to eq(2)