Skip to content
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

4310 - Update item quantity validation error message #4412

Merged

Conversation

vsrnth
Copy link
Contributor

@vsrnth vsrnth commented May 31, 2024

Resolves #4310

  • Updates validation error message when adding an item quantity
  • Updates related unit tests and system specs

Screenshots

image

@vsrnth vsrnth changed the title [Finishes 4310] Update item quantity validation error message 4310 - Update item quantity validation error message May 31, 2024
@@ -21,7 +21,7 @@ class LineItem < ApplicationRecord
belongs_to :item

validates :item_id, presence: true
validates :quantity, numericality: { only_integer: true, less_than: MAX_INT, greater_than: MIN_INT }
validates :quantity, numericality: { only_integer: true, less_than: MAX_INT, greater_than: MIN_INT, message: "is not a number - Note: commas are not allowed" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: Can we replace - with a period .? "is not a number. Note: commas are not allowed"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

@@ -418,7 +418,7 @@
expect(page).to have_xpath("//select[@id='donation_line_items_attributes_0_item_id']")
end.not_to change { Donation.count }
expect(page).to have_content("Start a new donation")
expect(page).to have_content("must be less than")
expect(page).to have_content("Quantity is not a number - Note: commas are not allowed")
Copy link
Collaborator

Choose a reason for hiding this comment

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

um... why? This is a number, isn't it?

Copy link
Contributor Author

@vsrnth vsrnth Jun 1, 2024

Choose a reason for hiding this comment

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

Line 412 is setting the quantity to 10000000000000000000000, this quantity value is bigger than the configured limit of 2**31 = 2,147,483,648 in the validation

Copy link
Collaborator

@cielf cielf Jun 1, 2024

Choose a reason for hiding this comment

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

Perhaps we need to split up the validation into checking for non-numeric characters and checking for range.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're checking for non-numeric characters in the unit tests. Do I need to do that for the system tests as well?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No - it's just a weird error message since I'd expect to test a string like "abc" here instead of a number that's too large.

Copy link
Collaborator

Choose a reason for hiding this comment

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

i.e. let's make the tests explicit that the input is a number with commas rather than relying on implicit changes that happen in the controller / http layer.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a little confused. The original test was about overshooting the maximum. @vsnrth is changing the meaning of the test, leaving overshooting the maximum untested.... We should still have that test, no?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes - we need both tests (one where it doesn't get a number and one where the number is too high).

Copy link
Contributor Author

@vsrnth vsrnth Jun 15, 2024

Choose a reason for hiding this comment

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

Updated the code to handle the above. We get a different message when the limit is crossed and when a string is entered.

@vsrnth vsrnth requested a review from dorner June 1, 2024 07:05
@dorner
Copy link
Collaborator

dorner commented Jun 21, 2024

Looks good to me. @cielf did you want to kick the tires?

@cielf
Copy link
Collaborator

cielf commented Jun 22, 2024

Looks good to me -- i noticed a different issue, but it's out of scope of this change.

@cielf
Copy link
Collaborator

cielf commented Jun 22, 2024

Let's merge after the release, though.

@dorner dorner merged commit 4d0bad6 into rubyforgood:main Jun 23, 2024
19 checks passed
Copy link
Contributor

github-actions bot commented Jul 7, 2024

@vsrnth: Your PR 4310 - Update item quantity validation error message is part of today's Human Essentials production release: 2024.07.07.
Thank you very much for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants