From 2e36c699f6b103fdba5029180bf4250acfe12073 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 2 Jul 2024 15:40:06 +1000 Subject: [PATCH] Test resulting stock instead of method calls The next test case wasn't asserting anything as well. The referenced method `decrease_stock_for_variant` doesn't actually exist. --- spec/models/spree/order_spec.rb | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 7fa0f365c1..c37fc28033 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -228,21 +228,15 @@ RSpec.describe Spree::Order do }.from(nil) end - it "should sell inventory units" do - shipment = Spree::Shipment.new - order.shipments = [shipment] + it "updates shipments and decreases stock" do + order = create(:order_ready_for_confirmation) + shipment = order.shipments.first + shipment.update_columns(updated_at: 1.minute.ago) - expect(shipment).to receive(:update!).with(order) - expect(shipment).to receive(:finalize!) - - order.finalize! - end - - it "should decrease the stock for each variant in the shipment" do - order.shipments.each do |shipment| - expect(shipment.stock_location).to receive(:decrease_stock_for_variant) - end - order.finalize! + expect { + order.finalize! + }.to change { order.variants.first.on_hand }.by(-1) + .and change { shipment.updated_at } end it "should change the shipment state to ready if order is paid" do