HOLD: Validate scholarship amount against event registration due#1865
Draft
maebeale wants to merge 1 commit into
Draft
HOLD: Validate scholarship amount against event registration due#1865maebeale wants to merge 1 commit into
maebeale wants to merge 1 commit into
Conversation
Saving a scholarship amount above the registration's remaining due previously raised an unhandled error (or silently over-allocated) via the Allocation after_update callback. Validate up front on the scholarship so the user gets a flash message and an inline field error. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
maebeale
commented
Jun 22, 2026
| return if amount_cents <= due_cents | ||
|
|
||
| errors.add(:amount_dollars, "cannot exceed the event registration amount due (#{MoneyFormatter.dollars_from_cents(due_cents)})") | ||
| end |
Collaborator
Author
There was a problem hiding this comment.
🤖 From Claude: Runs before save so create/update fail gracefully here — without it, an over-due amount reaches sync_allocation_amount's allocation.update! in after_update and raises RecordInvalid (500). The where.not(id: allocation.id) excludes this scholarship's own allocation so edits don't double-count.
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.
What is the goal of this PR and why is this important?
Scholarship#sync_allocation_amount→allocation.update!, where theAllocationover-cost validation raisesActiveRecord::RecordInvalid— an unhandled 500.mainalready validates the grant budget (within_grant_budget); this PR adds the parallel guard for the event registration amount due, which was not covered.How did you approach the change?
Scholarship#amount_within_event_registration_duevalidation that runs before save, so create/update fail gracefully (@scholarship.savereturns false) instead of reaching the raisingupdate!in theafter_updatecallback.event.cost_cents − other allocations, excluding the scholarship's own allocation so edits don't double-count.MoneyFormatterfor consistency with the rest of the UI.flash.now[:alert]from the model errors on create/update failure.shared/errorslist was already present onmain).Anything else to add?
main's recent scholarship/allocation rework. Thescholarship-previewStimulus controller (live "Still owed" preview) is purely cosmetic and never blocks submission, so this server-side validation remains the enforcement; its "other allocated" math matches this validation's "other allocations" computation.422with the field error (no more 500), plus a within-due happy path.🤖 Generated with Claude Code