diff options
author | Jared Norman <jared@super.gd> | 2019-06-25 11:51:14 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-25 11:51:14 -0700 |
commit | bde4deedf6d7fcc2151469bb92103208a988ffe0 (patch) | |
tree | 4d8c443b35d4b935baeebf406765933a9fda14b6 | |
parent | a3272ab16bf1597949fd300cf60743ffe172081f (diff) | |
parent | 482438819ceb12499fe75f8b11fe4c505b32816f (diff) |
Merge pull request #14 from SuperGoodSoft/better-cache-key
Make cache key a string
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | lib/super_good/solidus_taxjar.rb | 2 | ||||
-rw-r--r-- | spec/super_good/solidus_taxjar_spec.rb | 15 |
3 files changed, 18 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ac142a7..32fb9d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master +- Made sure cache key is a string, instead of a giant nested hash/array structure that probably won't get interpreted by Rails well. Still not happy with the caching behaviour, but it's configurable. + ## v0.14.0 - Added `SuperGood::SolidusTaxJar.taxable_order_check` option which can be set to a proc that receives the order and will prevent actual tax calculation from occurring if it returns false. If your app has introduced a method like `Spree::Order#complimentary?`, you could avoid trying to compute taxes on complimentary orders by doing the following in an initializer: diff --git a/lib/super_good/solidus_taxjar.rb b/lib/super_good/solidus_taxjar.rb index af2c7e8..1016397 100644 --- a/lib/super_good/solidus_taxjar.rb +++ b/lib/super_good/solidus_taxjar.rb @@ -24,7 +24,7 @@ module SuperGood end self.cache_duration = 3.hours - self.cache_key = ->(order) { APIParams.order_params(order) } + self.cache_key = ->(order) { APIParams.order_params(order).to_json } self.discount_calculator = ::SuperGood::SolidusTaxJar::DiscountCalculator self.exception_handler = ->(e) { Rails.logger.error "An error occurred while fetching TaxJar tax rates - #{e}: #{e.message}" diff --git a/spec/super_good/solidus_taxjar_spec.rb b/spec/super_good/solidus_taxjar_spec.rb index efc38b0..2b04e7b 100644 --- a/spec/super_good/solidus_taxjar_spec.rb +++ b/spec/super_good/solidus_taxjar_spec.rb @@ -6,6 +6,21 @@ RSpec.describe SuperGood::SolidusTaxJar do end describe "configuration" do + describe ".cache_key" do + subject { described_class.cache_key.(order) } + + let(:order) { Spree::Order.new } + + it "returns the API params converted to JSON" do + allow(SuperGood::SolidusTaxJar::APIParams) + .to receive(:order_params) + .with(order) + .and_return({ some: "hash", with: "stuff", in: "it" }) + + expect(subject).to eq '{"some":"hash","with":"stuff","in":"it"}' + end + end + describe ".discount_calculator" do subject { described_class.discount_calculator } it { is_expected.to eq SuperGood::SolidusTaxJar::DiscountCalculator } |