From 0a0659d1150a7df8f0ca23e4876672e95a103f51 Mon Sep 17 00:00:00 2001 From: Alessandro Desantis Date: Thu, 19 Nov 2020 13:14:14 +0100 Subject: Process one installment at a time in background jobs Instead of attempting to process multiple installments at a time, which increases the chances something might go wrong, we are now only processing one installment at a time. This also improves the extension's performance, because the installments can be processed in parallel. --- .../process_installment_job_spec.rb | 11 +++++++++ .../process_installments_job_spec.rb | 28 ---------------------- 2 files changed, 11 insertions(+), 28 deletions(-) create mode 100644 spec/jobs/solidus_subscriptions/process_installment_job_spec.rb delete mode 100644 spec/jobs/solidus_subscriptions/process_installments_job_spec.rb (limited to 'spec/jobs') diff --git a/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb b/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb new file mode 100644 index 0000000..4a33819 --- /dev/null +++ b/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb @@ -0,0 +1,11 @@ +RSpec.describe SolidusSubscriptions::ProcessInstallmentJob do + it 'processes checkout for the installment' do + installment = build_stubbed(:installment) + checkout = instance_spy(SolidusSubscriptions::Checkout) + allow(SolidusSubscriptions::Checkout).to receive(:new).with(installment).and_return(checkout) + + described_class.perform_now(installment) + + expect(checkout).to have_received(:process) + end +end diff --git a/spec/jobs/solidus_subscriptions/process_installments_job_spec.rb b/spec/jobs/solidus_subscriptions/process_installments_job_spec.rb deleted file mode 100644 index 111fc05..0000000 --- a/spec/jobs/solidus_subscriptions/process_installments_job_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'spec_helper' - -RSpec.describe SolidusSubscriptions::ProcessInstallmentsJob do - let(:root_order) { create :completed_order_with_pending_payment } - let(:installments) do - traits = { - subscription_traits: [{ - user: root_order.user, - line_item_traits: [{ - spree_line_item: root_order.line_items.first - }] - }] - } - - create_list(:installment, 2, traits) - end - - describe '#perform' do - subject { described_class.new.perform(installments) } - - it 'processes the consolidated installment' do - expect_any_instance_of(SolidusSubscriptions::Checkout). - to receive(:process).once - - subject - end - end -end -- cgit v1.2.3