From ee4c286ebc80779cc67fbce6988982d1017718b9 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 8 Apr 2019 12:29:31 -0400 Subject: [PATCH] Ensure cartons find soft deleted shipping methods Even if a shipping method is soft deleted, cartons should still be able to find it. If they can't, the #tracking_url method blows up when it tries to call #build_tracking_url on a nil shipping method. --- core/app/models/spree/carton.rb | 2 +- core/spec/models/spree/carton_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/app/models/spree/carton.rb b/core/app/models/spree/carton.rb index 931b3b62dff..9eee372d3b0 100644 --- a/core/app/models/spree/carton.rb +++ b/core/app/models/spree/carton.rb @@ -3,7 +3,7 @@ class Spree::Carton < Spree::Base belongs_to :address, class_name: 'Spree::Address', optional: true belongs_to :stock_location, class_name: 'Spree::StockLocation', inverse_of: :cartons, optional: true - belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', inverse_of: :cartons, optional: true + belongs_to :shipping_method, -> { with_discarded }, class_name: 'Spree::ShippingMethod', inverse_of: :cartons, optional: true has_many :inventory_units, class_name: "Spree::InventoryUnit", inverse_of: :carton, dependent: :nullify has_many :orders, -> { distinct }, through: :inventory_units diff --git a/core/spec/models/spree/carton_spec.rb b/core/spec/models/spree/carton_spec.rb index c5285ce73a8..7dd8196c1af 100644 --- a/core/spec/models/spree/carton_spec.rb +++ b/core/spec/models/spree/carton_spec.rb @@ -5,6 +5,14 @@ RSpec.describe Spree::Carton do let(:carton) { create(:carton) } + describe 'shipping method' do + it 'returns soft deleted shipping method' do + carton = create(:carton) + carton.shipping_method.discard + expect(carton.reload.shipping_method).to be_present + end + end + describe "#create" do subject { carton }