Check Shift destroy also destroy only associated OfficerAssigments
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user