mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #8325 from achauve/3976-improve-error-handling-of-unsupported-image-formats
Improve error handling of unsupported image formats
This commit is contained in:
@@ -56,8 +56,13 @@ module Spree
|
||||
def no_attachment_errors
|
||||
return if attachment.errors.empty?
|
||||
|
||||
errors.add :attachment,
|
||||
"Paperclip returned errors for file '#{attachment_file_name}' - check ImageMagick installation or image source file."
|
||||
if errors.all? {|e| e.type == "Paperclip::Errors::NotIdentifiedByImageMagickError"}
|
||||
attachment.errors.clear
|
||||
errors.add :base, I18n.t('spree.admin.products.image_upload_error')
|
||||
else
|
||||
errors.add :attachment,
|
||||
I18n.t('spree.admin.products.paperclip_image_error', attachment_file_name: attachment_file_name)
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
= render partial: 'spree/shared/error_messages', locals: { target: @image }
|
||||
|
||||
= form_for [:admin, @product, @image], url: admin_product_images_path(@product, @image, @url_filters), html: { multipart: true } do |f|
|
||||
%fieldset
|
||||
%legend{ align: "center" }= t('spree.new_image')
|
||||
= render partial: 'form', locals: { f: f }
|
||||
.form-buttons.filter-actions.actions
|
||||
= button t('spree.actions.update'), 'icon-refresh'
|
||||
= button t('actions.create'), 'icon-ok'
|
||||
%span.or= t('spree.or')
|
||||
= link_to_with_icon 'icon-remove', t('spree.actions.cancel'), admin_product_images_url(@product, @url_filters), id: 'cancel_link', class: 'button'
|
||||
|
||||
|
||||
@@ -3726,6 +3726,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
no_payment_via_admin_backend: Paypal payments cannot be captured in the Backoffice
|
||||
products:
|
||||
image_upload_error: "The product image was not recognised. Please upload an image in PNG or JPG format."
|
||||
paperclip_image_error: "Paperclip returned errors for file '%{attachment_file_name}' - check ImageMagick installation or image source file."
|
||||
new:
|
||||
title: "New Product"
|
||||
new_product: "New Product"
|
||||
|
||||
@@ -484,7 +484,7 @@ describe '
|
||||
page.find('a#new_image_link').click
|
||||
|
||||
attach_file('image_attachment', file_path)
|
||||
click_button "Update"
|
||||
click_button "Create"
|
||||
|
||||
uri = URI.parse(current_url)
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.admin_product_images_path(product, filter)
|
||||
@@ -540,6 +540,23 @@ describe '
|
||||
expect("#{uri.path}?#{uri.query}").to eq spree.admin_product_images_path(product, filter)
|
||||
end
|
||||
|
||||
it "checks error when creating product image with unsupported format", js: true do
|
||||
unsupported_image_file_path = Rails.root + "README.md"
|
||||
product = create(:simple_product, supplier: @supplier2)
|
||||
|
||||
image = File.open(File.expand_path('../../../app/assets/images/logo-white.png', __dir__))
|
||||
Spree::Image.create(viewable_id: product.master.id, viewable_type: 'Spree::Variant',
|
||||
alt: "position 1", attachment: image, position: 1)
|
||||
|
||||
visit spree.admin_product_images_path(product)
|
||||
page.find('a#new_image_link').click
|
||||
attach_file('image_attachment', unsupported_image_file_path)
|
||||
click_button "Create"
|
||||
|
||||
expect(page).to have_text "The product image was not recognised."
|
||||
expect(page).to have_text "Please upload an image in PNG or JPG format."
|
||||
end
|
||||
|
||||
it "deleting product images", js: true do
|
||||
product = create(:simple_product, supplier: @supplier2)
|
||||
image = File.open(File.expand_path('../../../app/assets/images/logo-white.png', __dir__))
|
||||
|
||||
Reference in New Issue
Block a user