mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
do not set on_demand and on_hand if variant has errors
+ update specs Co-Authored-By: Maikel <maikel@email.org.au>
This commit is contained in:
@@ -114,6 +114,11 @@ module Sets
|
||||
|
||||
variant = product.variants.create(variant_attributes)
|
||||
|
||||
if variant.errors.present?
|
||||
product.errors.merge!(variant.errors)
|
||||
return false
|
||||
end
|
||||
|
||||
begin
|
||||
variant.on_demand = on_demand if on_demand.present?
|
||||
variant.on_hand = on_hand.to_i if on_hand.present?
|
||||
|
||||
@@ -173,10 +173,8 @@ describe Sets::ProductSet do
|
||||
end
|
||||
|
||||
it 'does not create variant and notifies bugsnag still raising the exception' do
|
||||
expect(Bugsnag).to receive(:notify)
|
||||
number_of_variants = Spree::Variant.all.size
|
||||
expect { product_set.save }
|
||||
.to raise_error(StandardError)
|
||||
expect(product_set.save).to eq(false)
|
||||
expect(Spree::Variant.all.size).to eq number_of_variants
|
||||
expect(Spree::Variant.last.sku).not_to eq('321')
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user