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

Fix use of contains? in tax_rate.rb #657

Merged
merged 3 commits into from Jan 11, 2016
Merged

Fix use of contains? in tax_rate.rb #657

merged 3 commits into from Jan 11, 2016

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Jan 6, 2016

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 in TaxRate.

This should ease mergeability of #650 (once this is in, #650 will really only be specs).

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)
Copy link
Contributor

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, agree. Fixing.

@jhawthorn
Copy link
Contributor

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.
@jhawthorn
Copy link
Contributor

👍

@jhawthorn
Copy link
Contributor

I took the liberty of adding an additional spec :)

@mamhoff
Copy link
Contributor Author

mamhoff commented Jan 8, 2016

Nice. Thank you!

@mamhoff mamhoff mentioned this pull request Jan 8, 2016
@cbrunsdon
Copy link
Contributor

I'm 👍 for this, I think we can slip it in for 1.2

@cbrunsdon cbrunsdon merged commit 298f9a9 into solidusio:master Jan 11, 2016
@mamhoff mamhoff deleted the fix-use-of-contains-in-tax-rate branch January 17, 2016 17:12
@mamhoff mamhoff mentioned this pull request Mar 16, 2016
23 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants