From 24189ca88e7b8ae5cedb40e51b5cec9e3afaa5e4 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 12 Feb 2019 12:11:55 +0100 Subject: [PATCH] Create shipping_rate earlier for callback to work If the shipping_rate is not created at the time the `#after_save`'s `#ensure_correct_adjustment` callback is executed its call to `shipping_method.create_adjustment` won't be executed either. As a result, the OrderUpdater wasn't able to see any adjustments related to the shipment causing the order total to be outdated. --- spec/factories.rb | 9 +++------ .../open_food_network/user_balance_calculator_spec.rb | 2 -- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/spec/factories.rb b/spec/factories.rb index 688d5d52be..d21d1143fd 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -303,9 +303,6 @@ FactoryBot.define do p = create(:simple_product, distributors: [order.distributor]) FactoryBot.create(:line_item_with_shipment, shipping_fee: proxy.shipping_fee, order: order, product: p) order.reload - - # this will update order shipping fees and also order totals (through order.update!) - order.update_shipping_fees! end end @@ -403,9 +400,10 @@ FactoryBot.define do transient do shipping_method { create(:shipping_method) } end - after(:create) do |shipment, evaluator| - shipment.add_shipping_method(evaluator.shipping_method, true) + shipping_rates { [Spree::ShippingRate.create(shipping_method: shipping_method, selected: true)] } + + after(:create) do |shipment, evaluator| shipment.order.line_items.each do |line_item| line_item.quantity.times { shipment.inventory_units.create(variant_id: line_item.variant_id) } end @@ -432,7 +430,6 @@ FactoryBot.define do create(:payment, order: order, amount: order.total, payment_method: payment_method, state: 'checkout') while !order.completed? do break unless order.next! end - order.updater.update_adjustments # this is required to clean up duplicated shipping fees end end diff --git a/spec/lib/open_food_network/user_balance_calculator_spec.rb b/spec/lib/open_food_network/user_balance_calculator_spec.rb index 1e5786753f..675b3a91cd 100644 --- a/spec/lib/open_food_network/user_balance_calculator_spec.rb +++ b/spec/lib/open_food_network/user_balance_calculator_spec.rb @@ -3,9 +3,7 @@ require 'spec_helper' module OpenFoodNetwork describe UserBalanceCalculator do - describe "finding the account balance of a user with a hub" do - let!(:user1) { create(:user) } let!(:hub1) { create(:distributor_enterprise) }