From 8810f0a06ee8b5eab7ebb498e34b2966acaf885a Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Thu, 25 Mar 2021 10:56:23 +0100 Subject: [PATCH] Failing for calculator with preferences that aren't known If you try accessing a calculator with preferences in the DB, and that calculator hasn't seen the `serialize` call, Rails will try accessing the preferences column directly and return a string :( --- .../spec/models/spree/stock/estimator_spec.rb | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/spec/models/spree/stock/estimator_spec.rb b/core/spec/models/spree/stock/estimator_spec.rb index aba4e7116bc..9979fc4eff2 100644 --- a/core/spec/models/spree/stock/estimator_spec.rb +++ b/core/spec/models/spree/stock/estimator_spec.rb @@ -114,6 +114,29 @@ def compute_package(_package) end end + context 'with a custom shipping calculator with preference' do + class Spree::Calculator::Shipping::WithUnknownPreferences < Spree::ShippingCalculator + def compute_package(_package) + # no op + end + end + + let!(:shipping_methods) do + [ + create( + :shipping_method, + calculator: Spree::Calculator::Shipping::WithUnknownPreferences.new( + preferences: { a: "b" } + ) + ) + ] + end + + it 'does not raise an error' do + expect { subject.shipping_rates(package) }.not_to raise_error + end + end + context 'with two shipping methods of different cost' do let!(:shipping_methods) do [