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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fixed `spree_image_tag` with not attached image
Damian Legawiecf69a2f768709
diff --git a/core/app/helpers/spree/images_helper.rb b/core/app/helpers/spree/images_helper.rbindex a67343b2f9..d4b8623b60 100644--- a/core/app/helpers/spree/images_helper.rb+++ b/core/app/helpers/spree/images_helper.rb@@ -9,6 +9,10 @@ module Spree# @option options [Integer] :height the height of the image# @option options [Symbol] :variant use a preprocessed named variant (e.g., :mini, :small, :medium, :large, :xlarge)def spree_image_tag(image, options = {})+ return unless image+ return unless image.variable?+ return if image.respond_to?(:attached?) && !image.attached?+url_options = if options[:variant].present?{ variant: options[:variant] }else@@ -25,6 +29,7 @@ module Spreereturn unless imagereturn unless image.variable?return if image.respond_to?(:attached?) && !image.attached?+url_helpers = respond_to?(:main_app) ? main_app : Rails.application.routes.url_helpers# Use preprocessed named variant if specified (e.g., :mini, :small, :medium, :large, :xlarge)diff --git a/core/spec/helpers/images_helper_spec.rb b/core/spec/helpers/images_helper_spec.rbindex b0e297473c..af55ab44a1 100644--- a/core/spec/helpers/images_helper_spec.rb+++ b/core/spec/helpers/images_helper_spec.rb@@ -34,6 +34,26 @@ describe Spree::ImagesHelper, type: :helper doexpect(helper.spree_image_tag(image, variant: :small, width: 100, height: 100, format: :png)).to eq('image_tag')endend++ context 'when image is not attached' do+ before do+ allow(image).to receive(:attached?).and_return(false)+ end++ it 'returns nil' do+ expect(helper.spree_image_tag(image)).to be_nil+ end+ end++ context 'when image is not variable' do+ before do+ allow(image).to receive_messages(attached?: true, variable?: false)+ end++ it 'returns nil' do+ expect(helper.spree_image_tag(image)).to be_nil+ end+ endenddescribe '#spree_image_url' do