The Wayback Machine - http://web.archive.org/web/20201114050814/https://github.com/solidusio/solidus/issues/3756
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

Calculator should always return a BigDecimal, but in same scenarios that's not happening #3756

Open
stefano-sarioli opened this issue Sep 11, 2020 · 1 comment

Comments

@stefano-sarioli
Copy link
Contributor

@stefano-sarioli stefano-sarioli commented Sep 11, 2020

The calculator should always return a BigDecimal, but that's not always the case.

For example the flat_rate calculator return 0 as Integer on the else branch.

If the calculator returns a type other than BigDecimal a warning will be issued by the adjustment action for the promotions,
for example create_quantity_adjustments.

I think that we should document this expected interface on the Calculator, and update our actual implementation to respect the expected interface.

I wasn't able to find a test that raises this warning on the Solidus codebase, we should probably add some tests to cover this case.

Solidus Version:
First found out on Solidus 2.5.2.

To Reproduce

  • Write a test that creates a create_quantity_adjustments using a flat_rate calculator giving in input a nil object.
  • Launch it.
  • A Warning should appear in the console about results not being a BigDecimal. ("Spree::Calculator::FlatRate#compute returned 0, it should return a BigDecimal")

Current behavior

  • Raises a warning when using a standard calculator.

Expected behavior

  • Doesn't raise any warning when using a standard calculator.
@Ilyeo
Copy link

@Ilyeo Ilyeo commented Oct 7, 2020

Hi! I did this PR #3789, let me know if I made a mistake or if can I improve something thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.