-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 use of contains?
in tax_rate.rb
#657
Conversation
Consider I ask a zone whether it contains itself - that would be true, right? `Zone#contains` is only ever called from `tax_rate.rb`, and every time it gets called there is (or should be) a safeguard for this. Plus: It removes a `create` call from the zone specs.
@@ -188,8 +186,7 @@ def compute_amount(item) | |||
end | |||
|
|||
def default_zone_or_zone_match?(order_tax_zone) | |||
default_tax = Zone.default_tax | |||
(default_tax && default_tax.contains?(order_tax_zone)) || order_tax_zone == self.zone | |||
Zone.default_tax.try(:contains?, order_tax_zone) || self.zone.contains?(order_tax_zone) |
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.
This should probably be try!
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.
Yep, agree. Fixing.
Other than one comment this is good by me 👍 |
There's a bit of confusion around when a tax rate is applicable in the code. Sometimes the order tax zone has to be equal the tax rates zone, and sometimes it's ok if the tax rates' zone contains the order tax zone. Using the shortcut from the previous commit, this can be unified.
👍 |
I took the liberty of adding an additional spec :) |
Nice. Thank you! |
I'm 👍 for this, I think we can slip it in for 1.2 |
Previously, when checking a tax rate's applicability for an order, we would do two checks: Is it the same zone? If not: Does the tax rate's zone contain the other zone? Since a zone will always contain itself, I added an early return in
Zone#contains?
for that case, and unified the applicability checks inTaxRate
.This should ease mergeability of #650 (once this is in, #650 will really only be specs).