WAIT: Validate grant amount covers scholarships already issued#1888
Draft
maebeale wants to merge 1 commit into
Draft
WAIT: Validate grant amount covers scholarships already issued#1888maebeale wants to merge 1 commit into
maebeale wants to merge 1 commit into
Conversation
A grant's funds are committed once scholarships are drawn against it, so lowering the grant amount below the total already awarded would leave those scholarships unbacked. Guard the amount from the grant side, mirroring Scholarship#within_grant_budget which guards each draw from the other side. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
maebeale
commented
Jun 23, 2026
|
|
||
| issued = scholarships_total_cents | ||
| if amount_cents < issued | ||
| errors.add(:amount_cents, "can't be less than the #{MoneyFormatter.dollars_from_cents(issued)} already awarded in scholarships") |
Collaborator
Author
There was a problem hiding this comment.
🤖 From Claude: Reuses scholarships_total_cents, which sums the in-memory association when loaded and otherwise runs a single SQL aggregate — so no extra query is forced on save. Equality passes intentionally (amount == awarded is valid).
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.
🤖 PR, suggested 👤 review level: 📖 Read — light-logic: small, contained logic changes with low blast radius
What is the goal of this PR and why is this important?
amount_centslower than the total scholarships already awarded against it. Those draws are committed, so an amount below them would leave scholarships unbacked.How did you approach the change?
Grantmodel validation (amount_covers_scholarships_already_issued) that compares the proposed amount against the existingscholarships_total_centshelper.Scholarship#within_grant_budget, which guards each new draw from the other side of the ledger. Equality is allowed; new grants with no scholarships are unaffected.MoneyFormatter.dollars_from_cents(e.g. "can't be less than the $600 already awarded in scholarships").Anything else to add?