It is possible to create orphaned lottery assignments, which prevent suite selection from proceeding
Steps to replicate:
- Have a draw in the lottery phase
- Open the lottery form in two different browser tabs
- For a given group, enter two different lottery numbers in each tab (both will persist / create lottery assignments)
- For a different group, create a later lottery number
- Proceed to suite selection
Expected: Suite selection can be completed successfully
Actual: When you get to the orphaned lottery assignment, the SuiteAssignmentsController
ends up setting @groups
to []
(since it is orphaned) and tries to start the results phase since it assumes that we are done, but then the DrawResultsStarter
throws an error because there are still groups without suites assigned.
We should at a minimum change DrawSelectionStarter
to check for orphaned lottery assignments (draw.lottery_assignments.includes(:groups).where(groups: { id: nil })
) and destroy them before proceeding to suite selection. If it's possible to add a validation to LotteryAssignments to prevent the creation of a lottery assignment for a group that already has one, that would be even better.