From 320b7550ed24013cd57762ca32b9d5e6a88f8288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 23 Sep 2019 01:10:39 +0200 Subject: [PATCH] Simplify assigning poll to a booth in specs We were creating booth assignments explicitely, but we can use the `has_many :through` relationship to make the code easier to read. --- .../features/admin/poll/booth_assigments_spec.rb | 3 +-- spec/features/admin/poll/booths_spec.rb | 16 ++++------------ spec/features/admin/poll/shifts_spec.rb | 13 ++++--------- spec/features/budget_polls/ballot_sheets_spec.rb | 11 ++--------- spec/features/officing/results_spec.rb | 3 +-- spec/models/poll/booth_spec.rb | 10 ++-------- 6 files changed, 14 insertions(+), 42 deletions(-) diff --git a/spec/features/admin/poll/booth_assigments_spec.rb b/spec/features/admin/poll/booth_assigments_spec.rb index 987ba99ad..117b991a0 100644 --- a/spec/features/admin/poll/booth_assigments_spec.rb +++ b/spec/features/admin/poll/booth_assigments_spec.rb @@ -137,8 +137,7 @@ describe "Admin booths assignments" do end scenario "Cannot unassing booth if poll is expired" do - poll_expired = create(:poll, :expired) - create(:poll_booth_assignment, poll: poll_expired, booth: booth) + poll_expired = create(:poll, :expired, booths: [booth]) visit manage_admin_poll_booth_assignments_path(poll_expired) diff --git a/spec/features/admin/poll/booths_spec.rb b/spec/features/admin/poll/booths_spec.rb index e81f4e539..8480a0d9b 100644 --- a/spec/features/admin/poll/booths_spec.rb +++ b/spec/features/admin/poll/booths_spec.rb @@ -37,14 +37,8 @@ describe "Admin booths" do end scenario "Available" do - booth_for_current_poll = create(:poll_booth) - booth_for_expired_poll = create(:poll_booth) - - current_poll = create(:poll, :current) - expired_poll = create(:poll, :expired) - - create(:poll_booth_assignment, poll: current_poll, booth: booth_for_current_poll) - create(:poll_booth_assignment, poll: expired_poll, booth: booth_for_expired_poll) + booth_for_current_poll = create(:poll_booth, polls: [create(:poll, :current)]) + booth_for_expired_poll = create(:poll_booth, polls: [create(:poll, :expired)]) visit admin_root_path @@ -85,8 +79,7 @@ describe "Admin booths" do scenario "Edit" do poll = create(:poll, :current) - booth = create(:poll_booth) - assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + booth = create(:poll_booth, polls: [poll]) visit admin_booths_path @@ -111,8 +104,7 @@ describe "Admin booths" do scenario "Back link go back to available list when manage shifts" do poll = create(:poll, :current) - booth = create(:poll_booth) - assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + booth = create(:poll_booth, polls: [poll]) visit available_admin_booths_path diff --git a/spec/features/admin/poll/shifts_spec.rb b/spec/features/admin/poll/shifts_spec.rb index 2720bb32c..9b226b839 100644 --- a/spec/features/admin/poll/shifts_spec.rb +++ b/spec/features/admin/poll/shifts_spec.rb @@ -34,9 +34,7 @@ describe "Admin shifts" do scenario "Create Vote Collection Shift and Recount & Scrutiny Shift on same date", :js do create(:poll) poll = create(:poll, :current) - booth = create(:poll_booth) - create(:poll_booth_assignment, poll: poll, booth: booth) - create(:poll_booth_assignment, poll: create(:poll, :expired), booth: booth) + booth = create(:poll_booth, polls: [poll, create(:poll, :expired)]) officer = create(:poll_officer) vote_collection_dates = (Date.current..poll.ends_at.to_date).to_a.map { |date| I18n.l(date, format: :long) } recount_scrutiny_dates = (poll.ends_at.to_date..poll.ends_at.to_date + 1.week).to_a.map { |date| I18n.l(date, format: :long) } @@ -98,8 +96,7 @@ describe "Admin shifts" do scenario "Vote Collection Shift and Recount & Scrutiny Shift don't include already assigned dates to officer", :js do poll = create(:poll, :current) - booth = create(:poll_booth) - assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + booth = create(:poll_booth, polls: [poll]) officer = create(:poll_officer) shift1 = create(:poll_shift, :vote_collection_task, officer: officer, booth: booth, date: Date.current) @@ -149,8 +146,7 @@ describe "Admin shifts" do scenario "Error on create", :js do poll = create(:poll, :current) - booth = create(:poll_booth) - assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + booth = create(:poll_booth, polls: [poll]) officer = create(:poll_officer) visit available_admin_booths_path @@ -171,8 +167,7 @@ describe "Admin shifts" do scenario "Destroy" do poll = create(:poll, :current) - booth = create(:poll_booth) - assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + booth = create(:poll_booth, polls: [poll]) officer = create(:poll_officer) shift = create(:poll_shift, officer: officer, booth: booth) diff --git a/spec/features/budget_polls/ballot_sheets_spec.rb b/spec/features/budget_polls/ballot_sheets_spec.rb index 532b29035..ee8c70f32 100644 --- a/spec/features/budget_polls/ballot_sheets_spec.rb +++ b/spec/features/budget_polls/ballot_sheets_spec.rb @@ -2,13 +2,12 @@ require "rails_helper" describe "Poll budget ballot sheets" do let(:poll) { create(:poll, :for_budget, ends_at: 1.day.ago) } - let(:booth) { create(:poll_booth) } + let(:booth) { create(:poll_booth, polls: [poll]) } let(:poll_officer) { create(:poll_officer) } context "Officing recounts and results view" do before do - create(:poll_booth_assignment, poll: poll, booth: booth) create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth, date: Date.current) create(:poll_officer_assignment, officer: poll_officer) @@ -44,7 +43,6 @@ describe "Poll budget ballot sheets" do end scenario "Access ballot sheets officing with one booth assignment" do - create(:poll_booth_assignment, poll: poll, booth: booth) create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth, date: Date.current) create(:poll_officer_assignment, officer: poll_officer) @@ -58,9 +56,7 @@ describe "Poll budget ballot sheets" do end scenario "Access ballot sheets officing with multiple booth assignments", :with_frozen_time do - booth_2 = create(:poll_booth) - create(:poll_booth_assignment, poll: poll, booth: booth) - create(:poll_booth_assignment, poll: poll, booth: booth_2) + booth_2 = create(:poll_booth, polls: [poll]) create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth, date: Date.current) create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth_2, @@ -80,7 +76,6 @@ describe "Poll budget ballot sheets" do context "Index" do before do - create(:poll_booth_assignment, poll: poll, booth: booth) create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth, date: Date.current) @@ -102,7 +97,6 @@ describe "Poll budget ballot sheets" do context "New" do before do - create(:poll_booth_assignment, poll: poll, booth: booth) create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth, date: Date.current) create(:poll_officer_assignment, officer: poll_officer) @@ -150,7 +144,6 @@ describe "Poll budget ballot sheets" do context "Show" do before do - create(:poll_booth_assignment, poll: poll, booth: booth) create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth, date: Date.current) diff --git a/spec/features/officing/results_spec.rb b/spec/features/officing/results_spec.rb index 75644fbfe..222562e2f 100644 --- a/spec/features/officing/results_spec.rb +++ b/spec/features/officing/results_spec.rb @@ -2,11 +2,10 @@ require "rails_helper" describe "Officing Results", :with_frozen_time do let(:poll) { create(:poll, ends_at: 1.day.ago) } - let(:booth) { create(:poll_booth) } + let(:booth) { create(:poll_booth, polls: [poll]) } let(:poll_officer) { create(:poll_officer) } before do - create(:poll_booth_assignment, poll: poll, booth: booth) create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth, date: Date.current) @question_1 = create(:poll_question, poll: poll) create(:poll_question_answer, title: "Yes", question: @question_1, given_order: 1) diff --git a/spec/models/poll/booth_spec.rb b/spec/models/poll/booth_spec.rb index 309963972..19dc8e05d 100644 --- a/spec/models/poll/booth_spec.rb +++ b/spec/models/poll/booth_spec.rb @@ -27,14 +27,8 @@ describe Poll::Booth do describe ".available" do it "returns booths associated to current polls" do - booth_for_current_poll = create(:poll_booth) - booth_for_expired_poll = create(:poll_booth) - - current_poll = create(:poll, :current) - expired_poll = create(:poll, :expired) - - create(:poll_booth_assignment, poll: current_poll, booth: booth_for_current_poll) - create(:poll_booth_assignment, poll: expired_poll, booth: booth_for_expired_poll) + booth_for_current_poll = create(:poll_booth, polls: [create(:poll, :current)]) + booth_for_expired_poll = create(:poll_booth, polls: [create(:poll, :expired)]) expect(Poll::Booth.available).to include(booth_for_current_poll) expect(Poll::Booth.available).not_to include(booth_for_expired_poll)