Skip to content

Add Spree::ZERO constant #6291

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

Merged
merged 3 commits into from
Jun 25, 2025
Merged

Add Spree::ZERO constant #6291

merged 3 commits into from
Jun 25, 2025

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Jun 18, 2025

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 mamhoff requested a review from a team as a code owner June 18, 2025 11:54
@github-actions github-actions bot added changelog:solidus_core Changes to the solidus_core gem changelog:solidus_legacy_promotions Changes to the solidus_legacy_promotions gem changelog:solidus_promotions Changes to the solidus_promotions gem labels Jun 18, 2025
@tvdeyen tvdeyen added this to the 4.6 milestone Jun 18, 2025
@tvdeyen tvdeyen moved this to In Progress in Solidus Public Roadmap Jun 18, 2025
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Nice idea ;)

Copy link

codecov bot commented Jun 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@mamhoff mamhoff force-pushed the promotions-zero branch 4 times, most recently from 9844f2e to 8780f63 Compare June 18, 2025 14:58
mamhoff added 3 commits June 20, 2025 10:10
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.
This file is currently only loaded when loading either
`Spree::Calculator` or `Spree::PaymentMethod`. We can use Rails'
autoloading mechanism instead.

This makes running the spec for the `Preferable` module run through on
its own.
`String#to_d` will never, ever raise an ArgumentError. I tried with
`Object.new.to_s.to_d`.

This raises our test coverage for these files.

This was originally introduced to guard against weird behaviour of Ruby
2.4, which we do not support any longer.
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

👌

@tvdeyen tvdeyen merged commit 55a1be5 into solidusio:main Jun 25, 2025
25 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Solidus Public Roadmap Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem changelog:solidus_legacy_promotions Changes to the solidus_legacy_promotions gem changelog:solidus_promotions Changes to the solidus_promotions gem
Projects
Development

Successfully merging this pull request may close these issues.

4 participants