Skip to content

validates the item purchase fields for diapers, #5076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jahuang415
Copy link

Resolves #5059

Description

Before the change, a user could a new purchase with negative dollar values for the respective items (other, incontinence, etc.) and it would be valid so long as the total sum was correct and greater than zero.

A validation was added such that each purchase item must be greater than or equal to zero, and a respective rspec test was added to check.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Create a new purchase, and set the following values respectively: 1, -1, 2, 0, 0. This will submit successfully, which is incorrect.

Following the change, this will produce an error and not submit.

adult incontinence, period, other as >= 0, added
tests
Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

One nitpick re the test description - otherwise this LGTM

expect(d).not_to be_valid
end

it "is valid if all categories are positive" do
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would say "is valid if all categories are positive and add up to the total"

@cielf
Copy link
Collaborator

cielf commented Apr 7, 2025

@dorner -- do you want to take a technical pass on this? My nitpick is small enough that we could just edit the file on behalf of @jahuang415 , methinks.

@cielf cielf requested a review from dorner April 7, 2025 00:28
Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

Also would like a comment removed :)

@@ -54,6 +54,29 @@
expect(d).to be_valid
end

# re 5059-non-negative-purchase_value, adding in amount_spent_on_period_supplies_cents to test.
# also adding in amount_spend_on_incontinence_cents because it was missing.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment isn't necessary - this belongs in the PR, not in the code.

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.

In new purchase, Category purchase values must be non-negative
3 participants