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.

Fixed `Product#digital?` + added tests (#11628)

Damian Legawiec7791ed68e45a
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 83f361afcf..87b3bfbfc1 100644
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -359,7 +359,7 @@ module Spree
end
def digital?
- shipping_category == I18n.t('spree.seed.shipping.categories.digital')
+ shipping_category&.name == I18n.t('spree.seed.shipping.categories.digital')
end
private
diff --git a/core/spec/models/spree/product_spec.rb b/core/spec/models/spree/product_spec.rb
index fe2df34740..21c0eeed03 100644
--- a/core/spec/models/spree/product_spec.rb
+++ b/core/spec/models/spree/product_spec.rb
@@ -871,5 +871,19 @@ describe Spree::Product, type: :model do
end
end
end
+
+ describe '#digital?' do
+ context 'when product is not digital' do
+ let(:product) { create(:product, stores: [store]) }
+
+ it { expect(product.digital?).to eq(false) }
+ end
+
+ context 'when product is digital' do
+ let(:product) { create(:product, stores: [store], shipping_category: create(:shipping_category, name: 'Digital')) }
+
+ it { expect(product.digital?).to eq(true) }
+ end
+ end
end
end