diff options
author | andrea longhi <andrea@spaghetticode.it> | 2020-01-22 10:22:42 +0100 |
---|---|---|
committer | andrea longhi <andrea@spaghetticode.it> | 2020-01-22 10:31:57 +0100 |
commit | c28df097c661387e3e37d06eb56380fb59f58754 (patch) | |
tree | d8a1f8b21e02b3f7c509afda04feb314992a3a13 /spec/super_good | |
parent | 48a68fcb692d83e211794ba064fd4448158a0c92 (diff) |
Avoid raising unnecessary errors with incomplete address
When validating addresses, it may happen that the address
has no country, so trying to fetch the country ISO raises
an unnecessary error. Using ruby safe navigation prevents
this to happen. Of course, the address will still result
invalid eventually.
Diffstat (limited to 'spec/super_good')
-rw-r--r-- | spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb | 19 |
1 files changed, 19 insertions, 0 deletions
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 } |