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 generating (legacy) dynamic method names for images

Damian Legawiec26d5fa714063
diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb
index c1661334e4..f7e47b9f24 100644
--- a/core/app/helpers/spree/base_helper.rb
+++ b/core/app/helpers/spree/base_helper.rb
@@ -273,7 +273,8 @@ module Spree
# Returns style of image or nil
def image_style_from_method_name(method_name)
- if method_name.to_s.match(/_image$/) && style = method_name.to_s.sub(/_image$/, '') && (style.in? Spree::Image.styles.with_indifferent_access)
+ style = method_name.to_s.sub(/_image$/, '')
+ if method_name.to_s.match(/_image$/) && Spree::Image.styles.keys.map(&:to_s).include?(style)
style
end
end
diff --git a/core/spec/helpers/base_helper_spec.rb b/core/spec/helpers/base_helper_spec.rb
index 336f2262d3..b3a14119b0 100644
--- a/core/spec/helpers/base_helper_spec.rb
+++ b/core/spec/helpers/base_helper_spec.rb
@@ -120,10 +120,23 @@ describe Spree::BaseHelper, type: :helper do
let(:product) { build(:product) }
before do
- Spree::Image.class_eval do
- styles[:very_strange] = '1x1'
- styles.merge!(foobar: '2x2')
+ module ImageDecorator
+ module ClassMethods
+ def styles
+ super.merge(
+ very_strange: '1x1',
+ foobar: '2x2'
+ )
+ end
+ end
+
+ def self.prepended(base)
+ base.singleton_class.prepend ClassMethods
+ end
end
+
+ Spree::Image.prepend(ImageDecorator)
+
allow_any_instance_of(described_class).to receive(:inline_svg_tag).and_return('<svg></svg>')
end