From 690ebfba01c3e10cb45c8ec695f8392090c8f7a7 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 3 Oct 2017 13:24:07 +0200 Subject: [PATCH] Check Shift destroy also destroy only associated OfficerAssigments --- spec/models/poll/shift_spec.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/models/poll/shift_spec.rb b/spec/models/poll/shift_spec.rb index 86755a310..b62f220da 100644 --- a/spec/models/poll/shift_spec.rb +++ b/spec/models/poll/shift_spec.rb @@ -28,7 +28,7 @@ describe :shift do describe "officer_assignments" do - it "should create corresponding officer_assignments" do + it "should create and destroy corresponding officer_assignments" do poll1 = create(:poll) poll2 = create(:poll) poll3 = create(:poll) @@ -39,11 +39,9 @@ describe :shift do booth_assignment1 = create(:poll_booth_assignment, poll: poll1, booth: booth) booth_assignment2 = create(:poll_booth_assignment, poll: poll2, booth: booth) - shift = create(:poll_shift, booth: booth, officer: officer, date: Date.current) + expect { create(:poll_shift, booth: booth, officer: officer, date: Date.current) }.to change {Poll::OfficerAssignment.all.count}.by(2) officer_assignments = Poll::OfficerAssignment.all - expect(officer_assignments.count).to eq(2) - oa1 = officer_assignments.first oa2 = officer_assignments.second @@ -56,6 +54,10 @@ describe :shift do expect(oa2.date).to eq(Date.current) expect(oa2.booth_assignment).to eq(booth_assignment2) expect(oa2.final).to be_falsey + + create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment1, date: Date.tomorrow) + + expect { Poll::Shift.last.destroy }.to change {Poll::OfficerAssignment.all.count}.by(-2) end it "should create final officer_assignments" do