diff options
author | Juan Carlos Ruiz <JuanCrg90@gmail.com> | 2019-03-12 14:11:49 -0600 |
---|---|---|
committer | Juan Carlos Ruiz <JuanCrg90@gmail.com> | 2019-03-12 16:20:46 -0600 |
commit | 9f48531b513be0f233eddbdfce8be2e071f3539a (patch) | |
tree | ad50e6c3c6150dbfa80601fc9449250b8d19478e | |
parent | 9a83ec4cda37760aad82373dc422cadbb33eddfe (diff) |
Add incomplete_address? check method
Solidus has deprecated the `empty?` method on
https://github.com/solidusio/solidus/pull/1686 . This adds a private
`incomplete_address?` method for avoid future problems and remove the
deprecation warning in projects that uses this gem.
-rw-r--r-- | lib/super_good/solidus_taxjar/tax_calculator.rb | 12 | ||||
-rw-r--r-- | spec/super_good/solidus_taxjar/tax_calculator_spec.rb | 12 |
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/super_good/solidus_taxjar/tax_calculator.rb b/lib/super_good/solidus_taxjar/tax_calculator.rb index 5052814..327e248 100644 --- a/lib/super_good/solidus_taxjar/tax_calculator.rb +++ b/lib/super_good/solidus_taxjar/tax_calculator.rb @@ -12,7 +12,7 @@ module SuperGood def calculate return no_tax if SuperGood::SolidusTaxJar.test_mode - return no_tax if order.tax_address.empty? || order.line_items.none? + return no_tax if incomplete_address?(order.tax_address) || order.line_items.none? return no_tax unless taxable_address? order.tax_address cache do @@ -150,6 +150,16 @@ module SuperGood def line_item_tax_label(taxjar_line_item, spree_line_item) SuperGood::SolidusTaxJar.line_item_tax_label_maker.(taxjar_line_item, spree_line_item) end + + def incomplete_address?(tax_address) + [ + tax_address.address1, + tax_address.city, + tax_address&.state&.abbr || tax_address.state_name, + tax_address.zipcode, + tax_address.country.iso + ].any?(&:blank?) + end end end end diff --git a/spec/super_good/solidus_taxjar/tax_calculator_spec.rb b/spec/super_good/solidus_taxjar/tax_calculator_spec.rb index a13f564..0d390ec 100644 --- a/spec/super_good/solidus_taxjar/tax_calculator_spec.rb +++ b/spec/super_good/solidus_taxjar/tax_calculator_spec.rb @@ -78,6 +78,10 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxCalculator do let(:address) do ::Spree::Address.new( first_name: "Ronnie James", + zipcode: "90210", + address1: "9900 Wilshire Blvd", + city: "Beverly Hills", + state_name: "California", country: ::Spree::Country.new(iso: "US") ) end @@ -95,6 +99,10 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxCalculator do let(:address) do ::Spree::Address.new( first_name: "Ronnie James", + zipcode: "90210", + address1: "9900 Wilshire Blvd", + city: "Beverly Hills", + state_name: "California", country: ::Spree::Country.new(iso: "US") ) end @@ -123,6 +131,10 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxCalculator do let(:address) do ::Spree::Address.new( first_name: "Ronnie James", + zipcode: "90210", + address1: "9900 Wilshire Blvd", + city: "Beverly Hills", + state_name: "California", country: ::Spree::Country.new(iso: "US") ) end |