mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #3923 from luisramos0/prod_image_error
User friendly error when creating a product with an image in an unsupported format
This commit is contained in:
@@ -33,6 +33,10 @@ Spree::Admin::ProductsController.class_eval do
|
||||
delete_stock_params_and_set_after do
|
||||
super
|
||||
end
|
||||
rescue Paperclip::Errors::NotIdentifiedByImageMagickError
|
||||
invoke_callbacks(:create, :fails)
|
||||
@object.errors.add(:base, t('spree.admin.products.image_upload_error'))
|
||||
respond_with(@object)
|
||||
end
|
||||
|
||||
def update
|
||||
|
||||
@@ -3066,6 +3066,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
error_saving_payment: Error saving payment
|
||||
submitting_payment: Submitting payment...
|
||||
products:
|
||||
image_upload_error: "The product image was not recognised. Please upload an image in PNG or JPG format."
|
||||
|
||||
new:
|
||||
title: 'New Product'
|
||||
unit_name_placeholder: 'eg. bunches'
|
||||
|
||||
@@ -147,6 +147,25 @@ describe Spree::Admin::ProductsController, type: :controller do
|
||||
spree_post :create, product: product_attrs, button: 'add_another'
|
||||
expect(response).to redirect_to spree.new_admin_product_path
|
||||
end
|
||||
|
||||
describe "when user uploads an image in an unsupported format" do
|
||||
it "does not throw an exception" do
|
||||
product_image = ActionDispatch::Http::UploadedFile.new({
|
||||
:filename => 'unsupported_image_format.exr',
|
||||
:content_type => 'application/octet-stream',
|
||||
:tempfile => Tempfile.new('unsupported_image_format.exr')
|
||||
})
|
||||
product_attrs_with_image = product_attrs.merge(
|
||||
images_attributes: {
|
||||
'0' => { attachment: product_image }
|
||||
})
|
||||
|
||||
expect do
|
||||
spree_put :create, product: product_attrs_with_image
|
||||
end.not_to raise_error Paperclip::Errors::NotIdentifiedByImageMagickError
|
||||
expect(response.status).to eq 200
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "updating" do
|
||||
|
||||
Reference in New Issue
Block a user