mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-09 03:20:21 +00:00
Only validate an image if it has been changed
Best viewed with whitespace ignored.
This commit is contained in:
@@ -300,7 +300,7 @@ module Spree
|
||||
end
|
||||
|
||||
def validate_image
|
||||
return if image.blank? || image.valid?
|
||||
return if image.blank? || !image.changed? || image.valid?
|
||||
|
||||
errors.add(:base, I18n.t('spree.admin.products.image_not_processable'))
|
||||
end
|
||||
|
||||
@@ -292,11 +292,19 @@ module Spree
|
||||
subject(:product) { create(:product_with_image) }
|
||||
|
||||
context "when the image is invalid" do
|
||||
before { expect(product.image).to receive(:valid?).and_return(false) }
|
||||
before { allow(product.image).to receive(:valid?).and_return(false) }
|
||||
|
||||
it "adds an error message to the base object" do
|
||||
expect(product).not_to be_valid
|
||||
expect(product.errors[:base]).to include('Image attachment is not a valid image.')
|
||||
context "and has been changed" do
|
||||
before { expect(product.image).to receive(:changed?).and_return(true) }
|
||||
|
||||
it "adds an error message to the base object" do
|
||||
expect(product).not_to be_valid
|
||||
expect(product.errors[:base]).to include('Image attachment is not a valid image.')
|
||||
end
|
||||
end
|
||||
|
||||
it "ignores if unchanged" do
|
||||
expect(product).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user