summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/super_good/solidus_taxjar/calculator_helper.rb2
-rw-r--r--spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb19
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/super_good/solidus_taxjar/calculator_helper.rb b/lib/super_good/solidus_taxjar/calculator_helper.rb
index 89dedc0..636f322 100644
--- a/lib/super_good/solidus_taxjar/calculator_helper.rb
+++ b/lib/super_good/solidus_taxjar/calculator_helper.rb
@@ -17,7 +17,7 @@ module SuperGood
address.city,
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 }