-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
Fix #4172 donation validation display error #4483
Fix #4172 donation validation display error #4483
Conversation
When edited donation amount plus available inventory is less than requested inventory for distribution, it should redirect to the edit donation page, display an error, the original donated item name, and the original amount
…t edit * direct call to render doesn't load @Items causing partial to be unable to match item IDs to item names, resulting in displaying numbers * replace with redirect to edit
2b03b55
to
e49ef32
Compare
Error message changes if using events or not, add cases for both
e49ef32
to
0585857
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this approach won't do what we want. Can you verify?
@@ -84,7 +84,7 @@ def update | |||
redirect_to donations_path | |||
rescue => e | |||
flash[:alert] = "Error updating donation: #{e.message}" | |||
render "edit" | |||
redirect_back(fallback_location: edit_donation_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this lose all the information you've entered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is the existing behavior when I tested right now on the main branch commit e12311, I can try to change it and add a test so that it keeps all entered information except for the incorrect edited quantity if you want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems to be the correct thing to do, yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…ate error * Page should still display original donation source pre-edit in the title and breadcrumbs
223b647
to
708bbbb
Compare
* Also keeps submitted incorrect quantity
708bbbb
to
68cabfb
Compare
donation_params[:line_items_attributes].values.each { |attr| | ||
attr.delete(:_destroy) | ||
line_items.push(attr) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would put back any line items that the user removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you would have been right, but I originally put this line to pass donation controller request rspec tests which sent the _destroy parameter. Those tests I found out are outdated, the way the donation form is currently implemented the _destroy parameter is never sent, the donation object is just overridden with the new line_items_attributes. updated those rspec tests and removed this line in 3560157
expect(response.body).to include("Editing Donation\n <small>from #{original_source}") | ||
expect(response.body).to include("<li class=\"breadcrumb-item\">\n <a href=\"#\">Editing #{original_source}") | ||
expect(response.body).to include("<option selected=\"selected\" value=\"#{edited_source}\">#{edited_source}</option>") | ||
expect(response.body).to include("<option selected=\"selected\" value=\"#{edited_source_drive.id}\">#{edited_source_drive.name}</option>") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to specify the name etc. (anything we're actually checking) when creating the data. This makes the tests less flaky and more easily reproducible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved by 82a76fd
1920943
to
44a6ef4
Compare
* _destroy parameter is not sent when deleting line items when tested on commit [#f747006](rubyforgood@f747006) (could not find commit when this change occurred) * remove _destroy parameter reference in outdated rspec tests and donations controller code
14dfdc6
to
dfaa0e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, but there's a really huge test I'd like to try to sanitize if possible.
} | ||
} | ||
|
||
put donation_path(id: donation.id, donation: edited_donation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really what we're trying to hit, right? Why are we hitting all those other endpoints rather than just directly creating the data we want to interact with on this page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think when I wrote this (several weeks ago at this point, I don't remember) I didn't know how the inventory system worked and that DistributionCreateService or TestInventory existed. I think this can be rewritten to just use TestInventory and set inventory to 0 before editing the donation, I will try that.
I am thinking of adding TestInventory info and linking to the wiki Event page in CONTRIBUTING.md so new contributors have a easier time writing tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved by ba5af77
* Use TestInventory instead of distribution endpoint in rspec * Use build(:line_item) instead of as_json merge
Looks good to me! @cielf did you want to take a look? |
Passes my manual testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All set, thank you!
@jimmyli97: Your PR |
Resolves #4172
Description
Alternatives considered
Type of change
How Has This Been Tested?
Screenshots