Skip to content

fix: validate sponsor seats and number_of_coaches presence#2647

Merged
mroderick merged 2 commits into
masterfrom
fix/sponsor-coach-validation
Jun 15, 2026
Merged

fix: validate sponsor seats and number_of_coaches presence#2647
mroderick merged 2 commits into
masterfrom
fix/sponsor-coach-validation

Conversation

@mroderick

Copy link
Copy Markdown
Collaborator

Description

Fixes #1794. Supersedes #1803 (stale PR with the same fix, now corrected and rebased).

Organisers could create sponsors without specifying number_of_coaches or seats, which saved nil to the database. The show page then crashed on coach_spots when it evaluated nil / 2.0 — manifesting as a 404.

Changes

  • app/models/sponsor.rb — Add presence: true and numericality: { greater_than_or_equal_to: 0, only_integer: true } validations for both number_of_coaches and seats
  • app/views/admin/sponsors/_form.html.haml — Enable HTML5 browser validation (novalidate: false) and mark both fields as required with min: 0 for instant client-side feedback
  • spec/fabricators/sponsor_fabricator.rb — Add fabricator defaults so all existing tests continue to work
  • spec/models/sponsor_spec.rb — Add shoulda-matcher coverage for the new validations
  • spec/controllers/admin/sponsors_controller_spec.rb — Add number_of_coaches to controller create params
  • spec/features/admin/manage_sponsor_spec.rb — Add Coach spots field fill-in to feature tests

Test Plan

  • bundle exec rspec — 1023 examples, 0 failures
  • All sponsor-related controller, model, feature, policy, and presenter tests pass
  • Model validations reject blank and negative values
  • Client-side validation (HTML5 required, min: 0) active on the form

Organisers could create sponsors without specifying seat/coach counts,
saving nil to the database. The show page then crashed on coach_spots
when evaluating nil / 2.0, manifesting as a 404.

- Add model validations (presence + numericality >= 0)
- Enable HTML5 browser validation on the form
- Add fabricator defaults and fix test coverage

Closes #1794. Supersedes #1803.

@KimberleyCook KimberleyCook left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@mroderick mroderick marked this pull request as ready for review June 15, 2026 08:02
89 production sponsors (11.9%) have nil number_of_coaches. Without
backfill, editing them would fail the new presence validation. Uses
the same formula as Sponsor#coach_spots: ROUND(seats / 2.0).
@mroderick mroderick merged commit fbdab0d into master Jun 15, 2026
18 checks passed
@mroderick mroderick deleted the fix/sponsor-coach-validation branch June 15, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Organisers can create new Sponsors without adding in number of coaches/students but it will 404

2 participants