From 839a0626b47bf4e308f449f075d56a507ded3edb Mon Sep 17 00:00:00 2001 From: vassalloandrea Date: Wed, 15 Sep 2021 17:11:07 +0200 Subject: [PATCH] Fix cache related flaky specs --- .../solidus_afterpay/payment_method_spec.rb | 36 +++++++++---------- spec/support/cache.rb | 5 +++ 2 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 spec/support/cache.rb diff --git a/spec/models/solidus_afterpay/payment_method_spec.rb b/spec/models/solidus_afterpay/payment_method_spec.rb index fb07609..02fb05d 100644 --- a/spec/models/solidus_afterpay/payment_method_spec.rb +++ b/spec/models/solidus_afterpay/payment_method_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' RSpec.describe SolidusAfterpay::PaymentMethod, type: :model do @@ -61,24 +63,18 @@ describe "#available_for_order?" do subject { payment_method.available_for_order?(order) } - let(:cache) { Rails.cache } - - let(:payment_method) { described_class.new } - let(:order) { build(:order, currency: order_currency, total: order_total) } + let(:payment_method) { create(:afterpay_payment_method) } + let(:order_total) { 5 } let(:order_currency) { 'USD' } context "with cache" do - after do - cache.clear - end - context 'when order total is inside the range' do before do - cache.write("solidus_afterpay_configuration_maximumAmount_currency", "USD") - cache.write("solidus_afterpay_configuration_maximumAmount_amount", 10.0) - cache.write("solidus_afterpay_configuration_minimumAmount_amount", 1.0) + Rails.cache.write("solidus_afterpay_configuration_maximumAmount_currency", "USD") + Rails.cache.write("solidus_afterpay_configuration_maximumAmount_amount", 10.0) + Rails.cache.write("solidus_afterpay_configuration_minimumAmount_amount", 1.0) end it { is_expected.to be(true) } @@ -86,9 +82,9 @@ context 'when order total is outside the range' do before do - cache.write("solidus_afterpay_configuration_maximumAmount_currency", "USD") - cache.write("solidus_afterpay_configuration_maximumAmount_amount", 4.0) - cache.write("solidus_afterpay_configuration_minimumAmount_amount", 1.0) + Rails.cache.write("solidus_afterpay_configuration_maximumAmount_currency", "USD") + Rails.cache.write("solidus_afterpay_configuration_maximumAmount_amount", 4.0) + Rails.cache.write("solidus_afterpay_configuration_minimumAmount_amount", 1.0) end it { is_expected.to be(false) } @@ -96,9 +92,9 @@ context 'when order currency is different from afterpay configuration' do before do - cache.write("solidus_afterpay_configuration_maximumAmount_amount", 10.0) - cache.write("solidus_afterpay_configuration_minimumAmount_amount", 1.0) - cache.write("solidus_afterpay_configuration_maximumAmount_currency", "EUR") + Rails.cache.write("solidus_afterpay_configuration_maximumAmount_amount", 10.0) + Rails.cache.write("solidus_afterpay_configuration_minimumAmount_amount", 1.0) + Rails.cache.write("solidus_afterpay_configuration_maximumAmount_currency", "EUR") end it { is_expected.to be(false) } @@ -106,9 +102,9 @@ context 'when order currency is the same from afterpay configuration' do before do - cache.write("solidus_afterpay_configuration_maximumAmount_amount", 10.0) - cache.write("solidus_afterpay_configuration_minimumAmount_amount", 1.0) - cache.write("solidus_afterpay_configuration_maximumAmount_currency", "USD") + Rails.cache.write("solidus_afterpay_configuration_maximumAmount_amount", 10.0) + Rails.cache.write("solidus_afterpay_configuration_minimumAmount_amount", 1.0) + Rails.cache.write("solidus_afterpay_configuration_maximumAmount_currency", "USD") end it { is_expected.to be(true) } diff --git a/spec/support/cache.rb b/spec/support/cache.rb new file mode 100644 index 0000000..39bdbc5 --- /dev/null +++ b/spec/support/cache.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +RSpec.configure do |config| + config.after { Rails.cache.clear } +end