solidus icon indicating copy to clipboard operation
solidus copied to clipboard

Add `Spree::ZERO` constant

Open mamhoff opened this issue 9 months ago • 1 comments

Summary

Ruby's BigDecimal library does not come with a constant that denotes zero. We don't need to be creating a new zero every time we need one. Also, there's even a Rubocop that tells people to use an integer for integer-type BigDecimal instantiations, but a string for float-type BigDecimals (See https://github.com/rubocop/rubocop-performance/blob/master/lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb)

This all to say: Let's have a constant in the codebase that is zero. We can just reference it, we don't need so many zeros.

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

mamhoff avatar Jun 18 '25 11:06 mamhoff

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 88.97%. Comparing base (db99cba) to head (d9e5c92). Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6291      +/-   ##
==========================================
+ Coverage   88.95%   88.97%   +0.01%     
==========================================
  Files         860      861       +1     
  Lines       18422    18416       -6     
==========================================
- Hits        16387    16385       -2     
+ Misses       2035     2031       -4     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Jun 18 '25 12:06 codecov[bot]