summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Norman <jared@super.gd>2020-01-22 10:16:06 -0800
committerGitHub <noreply@github.com>2020-01-22 10:16:06 -0800
commitb7e6a192a1afae053288af0c3a33c7f60cfd34b9 (patch)
tree3edcb7b3fedbdc699b2d68079ecbb7e506dc8f66
parent48a68fcb692d83e211794ba064fd4448158a0c92 (diff)
parentac30ff69f619bc504cd295de2f983310077b30e0 (diff)
Merge pull request #18 from spaghetticode/spaghetticode/minor-fixes
Remove unnecessary errors when validating address without country
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/super_good/solidus_taxjar/calculator_helper.rb4
-rw-r--r--spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb19
3 files changed, 22 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 581f0d8..4e56853 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
# Changelog
## master
+- Fix `#incomplete_address?` method to be friendly also to completely blank addresses.
- Added `SuperGood::SolidusTaxJar::TaxRateCalculator` for retrieving the tax rate for a given `Spree::Address`. The calculator follows `TaxCalculator` conventions by relying on address validators and custom exception handling.
diff --git a/lib/super_good/solidus_taxjar/calculator_helper.rb b/lib/super_good/solidus_taxjar/calculator_helper.rb
index 89dedc0..dbde950 100644
--- a/lib/super_good/solidus_taxjar/calculator_helper.rb
+++ b/lib/super_good/solidus_taxjar/calculator_helper.rb
@@ -15,9 +15,9 @@ module SuperGood
[
address.address1,
address.city,
- address&.state&.abbr || address.state_name,
+ address.state&.abbr || address.state_name,
address.zipcode,
- address.country.iso
+ address.country&.iso
].any?(&:blank?)
end
diff --git a/spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb b/spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb
index 9a4e2b8..3af89e5 100644
--- a/spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb
+++ b/spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb
@@ -12,6 +12,10 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxRateCalculator do
let(:dummy_tax_rate) { BigDecimal(0) }
+ let(:empty_address) do
+ ::Spree::Address.new
+ end
+
let(:incomplete_address) do
::Spree::Address.new(
first_name: "Ronnie James",
@@ -34,6 +38,21 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxRateCalculator do
it { expect(subject).to eq dummy_tax_rate }
end
+ context "when the address is an empty address" do
+ let(:address) { empty_address }
+
+ context "when we're not rescuing from errors" do
+ around do |example|
+ handler = SuperGood::SolidusTaxJar.exception_handler
+ SuperGood::SolidusTaxJar.exception_handler = -> (error) { raise error }
+ example.run
+ SuperGood::SolidusTaxJar.exception_handler = handler
+ end
+
+ it_behaves_like "returns the dummy tax rate"
+ end
+ end
+
context "when the address is not complete" do
let(:address) { incomplete_address }