-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add Spree::ZERO
constant
#6291
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.
Nice idea ;)
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚀 New features to boost your workflow:
|
9844f2e
to
8780f63
Compare
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.
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.
👌
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 (Seehttps://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: