diff --git a/spec/factories/polls.rb b/spec/factories/polls.rb index 51da0246b..dfe2a7ed3 100644 --- a/spec/factories/polls.rb +++ b/spec/factories/polls.rb @@ -88,7 +88,12 @@ FactoryBot.define do poll association :user, :level_two association :officer, factory: :poll_officer - origin "web" + 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 diff --git a/spec/models/poll/stats_spec.rb b/spec/models/poll/stats_spec.rb index 78af334ca..b2130a370 100644 --- a/spec/models/poll/stats_spec.rb +++ b/spec/models/poll/stats_spec.rb @@ -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)