Show SVG product images

This commit is contained in:
Maikel Linke
2022-06-14 15:07:46 +10:00
parent f3f0a84915
commit 004c7eef9e
4 changed files with 17 additions and 4 deletions

View File

@@ -15,11 +15,15 @@ module Spree
validate :no_attachment_errors
def variant(name)
attachment.variant(SIZES[name])
if attachment.variable?
attachment.variant(SIZES[name])
else
attachment
end
end
def url(size)
return unless attachment.variable?
return unless attachment.attached?
Rails.application.routes.url_helpers.url_for(variant(size))
end

View File

@@ -240,5 +240,6 @@ module Openfoodnetwork
Rails.autoloaders.main.ignore(Rails.root.join('app/webpacker'))
config.active_storage.service = ENV["S3_BUCKET"].present? ? :amazon : :local
config.active_storage.content_types_to_serve_as_binary -= ["image/svg+xml"]
end
end

View File

@@ -21,11 +21,19 @@ module Spree
)
end
it "returns nil for unsupported formats" do
it "returns download link for unsupported formats" do
subject.attachment_blob.update_columns(
content_type: "application/octet-stream"
)
expect(subject.url(:small)).to match(
%r|^http://test\.host/rails/active_storage/blobs/redirect/.+/logo-black\.png$|
)
end
it "returns nil when the attachment is missing" do
subject.attachment = nil
expect(subject.url(:small)).to eq nil
end
end

View File

@@ -51,7 +51,7 @@ describe "spree/orders/show.html.haml" do
render
expect(rendered).to have_no_css("img[src*='logo.png']")
expect(rendered).to have_css("img[src*='logo.png']")
expect(rendered).to have_content("R123456789")
end
end