Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

fix shipment.digital? without shipping method (#13057)

Szymon Chorobski8dfbd5d8a5a0
diff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rb
index e90b618a1c..89858fbb3b 100644
--- a/core/app/models/spree/shipment.rb
+++ b/core/app/models/spree/shipment.rb
@@ -64,7 +64,6 @@ module Spree
delegate :store, :currency, to: :order
delegate :amount_in_cents, to: :display_cost
- delegate :digital?, to: :shipping_method
# shipment state machine (see http://github.com/pluginaweek/state_machine/tree/master for details)
state_machine initial: :pending, use_transactions: false do
@@ -125,6 +124,10 @@ module Spree
cost
end
+ def digital?
+ shipping_method&.digital? || false
+ end
+
def add_shipping_method(shipping_method, selected = false)
shipping_rates.create(shipping_method: shipping_method, selected: selected, cost: cost)
end
diff --git a/core/spec/models/spree/shipment_spec.rb b/core/spec/models/spree/shipment_spec.rb
index 9c1b040399..cc1e69e80c 100644
--- a/core/spec/models/spree/shipment_spec.rb
+++ b/core/spec/models/spree/shipment_spec.rb
@@ -42,9 +42,12 @@ describe Spree::Shipment, type: :model do
expect(shipment.digital?).to eq(false)
end
- it 'returns false if shipping method is nil' do
- shipment.shipping_rates.delete_all
- expect(shipment.digital?).to eq(false)
+ context 'when shipping method is nil' do
+ let(:shipping_method) { nil }
+
+ it 'returns false if shipping method is nil' do
+ expect(shipment.digital?).to eq(false)
+ end
end
end