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.
This commit is contained in:
@@ -137,8 +137,7 @@ describe "Admin booths assignments" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Cannot unassing booth if poll is expired" do
|
scenario "Cannot unassing booth if poll is expired" do
|
||||||
poll_expired = create(:poll, :expired)
|
poll_expired = create(:poll, :expired, booths: [booth])
|
||||||
create(:poll_booth_assignment, poll: poll_expired, booth: booth)
|
|
||||||
|
|
||||||
visit manage_admin_poll_booth_assignments_path(poll_expired)
|
visit manage_admin_poll_booth_assignments_path(poll_expired)
|
||||||
|
|
||||||
|
|||||||
@@ -37,14 +37,8 @@ describe "Admin booths" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Available" do
|
scenario "Available" do
|
||||||
booth_for_current_poll = create(:poll_booth)
|
booth_for_current_poll = create(:poll_booth, polls: [create(:poll, :current)])
|
||||||
booth_for_expired_poll = create(:poll_booth)
|
booth_for_expired_poll = create(:poll_booth, polls: [create(:poll, :expired)])
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
visit admin_root_path
|
visit admin_root_path
|
||||||
|
|
||||||
@@ -85,8 +79,7 @@ describe "Admin booths" do
|
|||||||
|
|
||||||
scenario "Edit" do
|
scenario "Edit" do
|
||||||
poll = create(:poll, :current)
|
poll = create(:poll, :current)
|
||||||
booth = create(:poll_booth)
|
booth = create(:poll_booth, polls: [poll])
|
||||||
assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
|
|
||||||
|
|
||||||
visit admin_booths_path
|
visit admin_booths_path
|
||||||
|
|
||||||
@@ -111,8 +104,7 @@ describe "Admin booths" do
|
|||||||
|
|
||||||
scenario "Back link go back to available list when manage shifts" do
|
scenario "Back link go back to available list when manage shifts" do
|
||||||
poll = create(:poll, :current)
|
poll = create(:poll, :current)
|
||||||
booth = create(:poll_booth)
|
booth = create(:poll_booth, polls: [poll])
|
||||||
assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
|
|
||||||
|
|
||||||
visit available_admin_booths_path
|
visit available_admin_booths_path
|
||||||
|
|
||||||
|
|||||||
@@ -34,9 +34,7 @@ describe "Admin shifts" do
|
|||||||
scenario "Create Vote Collection Shift and Recount & Scrutiny Shift on same date", :js do
|
scenario "Create Vote Collection Shift and Recount & Scrutiny Shift on same date", :js do
|
||||||
create(:poll)
|
create(:poll)
|
||||||
poll = create(:poll, :current)
|
poll = create(:poll, :current)
|
||||||
booth = create(:poll_booth)
|
booth = create(:poll_booth, polls: [poll, create(:poll, :expired)])
|
||||||
create(:poll_booth_assignment, poll: poll, booth: booth)
|
|
||||||
create(:poll_booth_assignment, poll: create(:poll, :expired), booth: booth)
|
|
||||||
officer = create(:poll_officer)
|
officer = create(:poll_officer)
|
||||||
vote_collection_dates = (Date.current..poll.ends_at.to_date).to_a.map { |date| I18n.l(date, format: :long) }
|
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) }
|
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
|
scenario "Vote Collection Shift and Recount & Scrutiny Shift don't include already assigned dates to officer", :js do
|
||||||
poll = create(:poll, :current)
|
poll = create(:poll, :current)
|
||||||
booth = create(:poll_booth)
|
booth = create(:poll_booth, polls: [poll])
|
||||||
assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
|
|
||||||
officer = create(:poll_officer)
|
officer = create(:poll_officer)
|
||||||
|
|
||||||
shift1 = create(:poll_shift, :vote_collection_task, officer: officer, booth: booth, date: Date.current)
|
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
|
scenario "Error on create", :js do
|
||||||
poll = create(:poll, :current)
|
poll = create(:poll, :current)
|
||||||
booth = create(:poll_booth)
|
booth = create(:poll_booth, polls: [poll])
|
||||||
assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
|
|
||||||
officer = create(:poll_officer)
|
officer = create(:poll_officer)
|
||||||
|
|
||||||
visit available_admin_booths_path
|
visit available_admin_booths_path
|
||||||
@@ -171,8 +167,7 @@ describe "Admin shifts" do
|
|||||||
|
|
||||||
scenario "Destroy" do
|
scenario "Destroy" do
|
||||||
poll = create(:poll, :current)
|
poll = create(:poll, :current)
|
||||||
booth = create(:poll_booth)
|
booth = create(:poll_booth, polls: [poll])
|
||||||
assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
|
|
||||||
officer = create(:poll_officer)
|
officer = create(:poll_officer)
|
||||||
|
|
||||||
shift = create(:poll_shift, officer: officer, booth: booth)
|
shift = create(:poll_shift, officer: officer, booth: booth)
|
||||||
|
|||||||
@@ -2,13 +2,12 @@ require "rails_helper"
|
|||||||
|
|
||||||
describe "Poll budget ballot sheets" do
|
describe "Poll budget ballot sheets" do
|
||||||
let(:poll) { create(:poll, :for_budget, ends_at: 1.day.ago) }
|
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) }
|
let(:poll_officer) { create(:poll_officer) }
|
||||||
|
|
||||||
context "Officing recounts and results view" do
|
context "Officing recounts and results view" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
create(:poll_booth_assignment, poll: poll, booth: booth)
|
|
||||||
create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
|
create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
|
||||||
date: Date.current)
|
date: Date.current)
|
||||||
create(:poll_officer_assignment, officer: poll_officer)
|
create(:poll_officer_assignment, officer: poll_officer)
|
||||||
@@ -44,7 +43,6 @@ describe "Poll budget ballot sheets" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Access ballot sheets officing with one booth assignment" do
|
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,
|
create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
|
||||||
date: Date.current)
|
date: Date.current)
|
||||||
create(:poll_officer_assignment, officer: poll_officer)
|
create(:poll_officer_assignment, officer: poll_officer)
|
||||||
@@ -58,9 +56,7 @@ describe "Poll budget ballot sheets" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Access ballot sheets officing with multiple booth assignments", :with_frozen_time do
|
scenario "Access ballot sheets officing with multiple booth assignments", :with_frozen_time do
|
||||||
booth_2 = create(:poll_booth)
|
booth_2 = create(:poll_booth, polls: [poll])
|
||||||
create(:poll_booth_assignment, poll: poll, booth: booth)
|
|
||||||
create(:poll_booth_assignment, poll: poll, booth: booth_2)
|
|
||||||
create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
|
create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
|
||||||
date: Date.current)
|
date: Date.current)
|
||||||
create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth_2,
|
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
|
context "Index" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
create(:poll_booth_assignment, poll: poll, booth: booth)
|
|
||||||
create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
|
create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
|
||||||
date: Date.current)
|
date: Date.current)
|
||||||
|
|
||||||
@@ -102,7 +97,6 @@ describe "Poll budget ballot sheets" do
|
|||||||
context "New" do
|
context "New" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
create(:poll_booth_assignment, poll: poll, booth: booth)
|
|
||||||
create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
|
create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
|
||||||
date: Date.current)
|
date: Date.current)
|
||||||
create(:poll_officer_assignment, officer: poll_officer)
|
create(:poll_officer_assignment, officer: poll_officer)
|
||||||
@@ -150,7 +144,6 @@ describe "Poll budget ballot sheets" do
|
|||||||
context "Show" do
|
context "Show" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
create(:poll_booth_assignment, poll: poll, booth: booth)
|
|
||||||
create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
|
create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
|
||||||
date: Date.current)
|
date: Date.current)
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,10 @@ require "rails_helper"
|
|||||||
|
|
||||||
describe "Officing Results", :with_frozen_time do
|
describe "Officing Results", :with_frozen_time do
|
||||||
let(:poll) { create(:poll, ends_at: 1.day.ago) }
|
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) }
|
let(:poll_officer) { create(:poll_officer) }
|
||||||
|
|
||||||
before 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_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth, date: Date.current)
|
||||||
@question_1 = create(:poll_question, poll: poll)
|
@question_1 = create(:poll_question, poll: poll)
|
||||||
create(:poll_question_answer, title: "Yes", question: @question_1, given_order: 1)
|
create(:poll_question_answer, title: "Yes", question: @question_1, given_order: 1)
|
||||||
|
|||||||
@@ -27,14 +27,8 @@ describe Poll::Booth do
|
|||||||
describe ".available" do
|
describe ".available" do
|
||||||
|
|
||||||
it "returns booths associated to current polls" do
|
it "returns booths associated to current polls" do
|
||||||
booth_for_current_poll = create(:poll_booth)
|
booth_for_current_poll = create(:poll_booth, polls: [create(:poll, :current)])
|
||||||
booth_for_expired_poll = create(:poll_booth)
|
booth_for_expired_poll = create(:poll_booth, polls: [create(:poll, :expired)])
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
expect(Poll::Booth.available).to include(booth_for_current_poll)
|
expect(Poll::Booth.available).to include(booth_for_current_poll)
|
||||||
expect(Poll::Booth.available).not_to include(booth_for_expired_poll)
|
expect(Poll::Booth.available).not_to include(booth_for_expired_poll)
|
||||||
|
|||||||
Reference in New Issue
Block a user