-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
3992 preserve storage location when editing purchase #4003
3992 preserve storage location when editing purchase #4003
Conversation
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.
Hi Sean - thanks so much for the PR! The issue here is that the default should be selected for new purchases. It should not be selected when editing existing purchases (instead, the current storage location should be). This PR appears to change it so for new purchases, no storage location is selected by default.
Hi @dorner, thanks for the feedback. I've updated my code to allow for new purchases to still default to a storage location. Let me know if this satisfies your request 😄 |
collection: @storage_locations, | ||
label: "Storage Location", | ||
error: "Where is it being stored?", | ||
selected: current_organization.intake_location, |
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.
We can probably simplify this quite a bit with a ternary on the selected.
I imagine that something like:
selected: @purchase.new_record? ? current_organization.intake_location : @purchase.storage_location_id,
would work.
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.
Hi @seanmarcia, yes you are correct. Thank you for the suggestion, I've implemented the change that you suggested and is working fine.
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.
Thanks! I think the last part of the form to this would be to just move it into a helper :)
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.
No problem, created a helper function for it now.
spec/system/purchase_system_spec.rb
Outdated
storage1 = create(:storage_location, name: "storage1") | ||
purchase = create(:purchase, storage_location: storage1) | ||
visit edit_purchase_path(@organization.to_param, purchase) | ||
expect(page).to have_content("storage1") |
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'm pretty sure this test will pass regardless of which location is selected. To verify, try taking your code in the previous files out and run the test - if it's still green, the test isn't useful. You'd need to find a better way to indicate that the right storage location is selected (perhaps via an option selected
matcher.
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.
Yes you were correct, @dorner. I've updated the test to make sure the expected storage is selected. Thanks for all the feedback, let me know if there's anything else that can be improved on.
Bumps [rubocop-rails](https://github.com/rubocop/rubocop-rails) from 2.23.0 to 2.23.1. - [Release notes](https://github.com/rubocop/rubocop-rails/releases) - [Changelog](https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md) - [Commits](rubocop/rubocop-rails@v2.23.0...v2.23.1) --- updated-dependencies: - dependency-name: rubocop-rails dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Preserved storage location on purchase edit page Improved test Fixing test affected by my change Fixed to reintroduce default storage location for new purchases
Bumps [rubocop-performance](https://github.com/rubocop/rubocop-performance) from 1.19.1 to 1.20.1. - [Release notes](https://github.com/rubocop/rubocop-performance/releases) - [Changelog](https://github.com/rubocop/rubocop-performance/blob/master/CHANGELOG.md) - [Commits](rubocop/rubocop-performance@v1.19.1...v1.20.1) --- updated-dependencies: - dependency-name: rubocop-performance dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Simplified changes Fix issue causing factory_bot_lint failure Moved logic to a helper function
fb6e43b
to
af40477
Compare
spec/system/purchase_system_spec.rb
Outdated
purchase = create(:purchase, storage_location: storage1) | ||
visit edit_purchase_path(@organization.to_param, purchase) | ||
assert page.has_select? "Storage Location", selected: "storage1" | ||
end |
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.
Agree with @seanmarcia (his comment has been abandoned since you force pushed the branch - please don't do that with open PRs that have comments!)
You can inspect the rendered response in a request test. If you're not interacting with it in any way, that should be fine. System tests should be limited to interactivity and JavaScript testing since it's slower and more brittle.
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.
Can another test be added to ensure the new
behavior is also as expected?
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've moved the test into requests, and added a new test to ensure the new
behavior. Let me know if these address the changes you wanted.
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.
Getting closer! 😄
it "storage location defaults to organizations storage location" do | ||
purchase = create(:purchase) | ||
get edit_purchase_path(@organization.to_param, purchase) | ||
assert_select('select#purchase_storage_location_id option[selected]').first[storage_location.name] |
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'm not familiar with the assert_select
method and not sure I understand what it's doing here specifically (the docs don't seem to indicate this usage). Can you match this selector with the way we do checks elsewhere?
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've updated the tests to use match
as is used elsewhere in the tests.
@@ -67,6 +67,12 @@ | |||
|
|||
expect(Purchase.last.amount_spent_in_cents).to eq 100_054 | |||
end | |||
|
|||
it "storage location defaults to organizations storage location" do | |||
purchase = create(:purchase) |
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.
Spacing seems off here?
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.
Yep, fixed that now
@PhantomSean So close! There's a conflict that needs to be solved now. |
@dorner Resolved conflict, hopefully all good now. Let me know if there's anything else to be done 😄 |
lol now linting is breaking! 😁 I think it would be simpler to just leave the gemfile / gemfile.lock updates out of this PR. It's causing more headaches than it's worth. |
…f github.com:PhantomSean/human-essentials into 3992-preserve-storage-location-when-editing-purchase
I believe I've resolved the issues if you're free to review |
This looks good! Thanks very much! |
No problem! |
@PhantomSean: Your PR |
Resolves #3992
Description
Introduced condition to determine whether a new purchase is being created or if an existing purchase is being edited. If the latter is true the current storage location is displayed rather than defaulting to the organizations storage location/first item on the drop-down.
Type of change
How Has This Been Tested?
Visual Test:
Rspec Test:
Added a test to spec/requests/purchases_requests_spec.rb to confirm that storage location is preserved editing a purchase and that the organization's storage location default is selected when creating a purchase.
Screenshots
Before:
After: