fix: validate sponsor seats and number_of_coaches presence#2647
Merged
Conversation
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.
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #1794. Supersedes #1803 (stale PR with the same fix, now corrected and rebased).
Organisers could create sponsors without specifying
number_of_coachesorseats, which savednilto the database. The show page then crashed oncoach_spotswhen it evaluatednil / 2.0— manifesting as a 404.Changes
app/models/sponsor.rb— Addpresence: trueandnumericality: { greater_than_or_equal_to: 0, only_integer: true }validations for bothnumber_of_coachesandseatsapp/views/admin/sponsors/_form.html.haml— Enable HTML5 browser validation (novalidate: false) and mark both fields asrequiredwithmin: 0for instant client-side feedbackspec/fabricators/sponsor_fabricator.rb— Add fabricator defaults so all existing tests continue to workspec/models/sponsor_spec.rb— Add shoulda-matcher coverage for the new validationsspec/controllers/admin/sponsors_controller_spec.rb— Addnumber_of_coachesto controller create paramsspec/features/admin/manage_sponsor_spec.rb— AddCoach spotsfield fill-in to feature testsTest Plan
bundle exec rspec— 1023 examples, 0 failuresrequired,min: 0) active on the form