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

Fix the issue where the exception was not caught when the purchase was distributed. #4894

Conversation

nozomirin
Copy link
Contributor

Resolves #4886

Description

I am not sure whether this test is practical. If you have any ideas to improve it, please let me know.

Type of change

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

How Has This Been Tested?

bundle exec rspec spec/system/purchase_system_spec.rb:296

Screenshots

screenshot-4886

PurchaseDestroyService.call(purchase)
begin
PurchaseDestroyService.call(purchase)
rescue InventoryError => e
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason you can't catch any StandardError here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. I will change it.

end
end

context "When the purchase has been distributed" do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Really all we're testing here is the ability to catch errors. So you can ensure that the delete service throws an error:

allow(PurchaseDestroyService).to receive(:call).and_raise('an error')

and you don't need all the setup here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that's really easy. I will change it. Thanks for your review.

@nozomirin nozomirin force-pushed the 4886-catch-validation-error-of-purchase-deletion branch from 7a88ad3 to ca9e75d Compare December 28, 2024 08:20
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.

Looks good to me! @cielf did you want to take a look?

@dorner dorner requested a review from cielf December 31, 2024 00:56
@cielf
Copy link
Collaborator

cielf commented Jan 5, 2025

A definite improvment!

@cielf cielf merged commit aadeccf into rubyforgood:main Jan 5, 2025
11 checks passed
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.

Purchase delete: catch validation errors
3 participants