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.

active storage blob partial fix

Szymon Chorobskid5a3db7124bf
diff --git a/core/app/helpers/spree/images_helper.rb b/core/app/helpers/spree/images_helper.rb
index 322c27d613..9e285732ed 100644
--- a/core/app/helpers/spree/images_helper.rb
+++ b/core/app/helpers/spree/images_helper.rb
@@ -18,10 +18,10 @@ module Spree
width = options[:width]
height = options[:height]
- width = width * 2 if width.present?
- height = height * 2 if height.present?
+ width *= 2 if width.present?
+ height *= 2 if height.present?
- return unless image.attached?
+ return if image.respond_to?(:attached?) && !image.attached?
return unless image.variable?
if width.present? && height.present?
@@ -51,17 +51,18 @@ module Spree
return unless height
return if height.zero?
- w, h = width.to_f, height.to_f
+ w = width.to_f
+ h = height.to_f
# Always return width / height, flipping if needed
- if h > w
- ratio = h / w
- elsif h < w
- ratio = w / h
- else
- # h == w, square image
- ratio = 1.0
- end
+ ratio = if h > w
+ h / w
+ elsif h < w
+ w / h
+ else
+ # h == w, square image
+ 1.0
+ end
ratio.round(3)
end
diff --git a/core/spec/helpers/images_helper_spec.rb b/core/spec/helpers/images_helper_spec.rb
index a4b085f0be..7306ac9221 100644
--- a/core/spec/helpers/images_helper_spec.rb
+++ b/core/spec/helpers/images_helper_spec.rb
@@ -23,6 +23,10 @@ describe Spree::ImagesHelper, type: :helper do
end
describe '#spree_image_url' do
+ it 'supports blob' do
+ expect(helper.spree_image_url(image.blob)).to eq(helper.spree_image_url(image))
+ end
+
context 'when image is not attached' do
before do
allow(image).to receive(:attached?).and_return(false)
@@ -35,8 +39,7 @@ describe Spree::ImagesHelper, type: :helper do
context 'when image is not variable' do
before do
- allow(image).to receive(:attached?).and_return(true)
- allow(image).to receive(:variable?).and_return(false)
+ allow(image).to receive_messages(attached?: true, variable?: false)
end
it 'returns nil' do
@@ -82,8 +85,7 @@ describe Spree::ImagesHelper, type: :helper do
context 'when aspect_ratio is present in metadata' do
before do
- allow(attachment).to receive(:analyzed?).and_return(true)
- allow(attachment).to receive(:metadata).and_return({ 'aspect_ratio' => 1.5 })
+ allow(attachment).to receive_messages(analyzed?: true, metadata: { 'aspect_ratio' => 1.5 })
end
it 'returns the aspect ratio' do
@@ -93,8 +95,7 @@ describe Spree::ImagesHelper, type: :helper do
context 'when calculating aspect ratio from dimensions' do
before do
- allow(attachment).to receive(:analyzed?).and_return(true)
- allow(attachment).to receive(:metadata).and_return({ 'width' => width, 'height' => height })
+ allow(attachment).to receive_messages(analyzed?: true, metadata: { 'width' => width, 'height' => height })
end
context 'when height is greater than width' do