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:
Jean-Baptiste Bellet
2022-07-05 16:35:33 +02:00
parent b2a0310e6f
commit c39b00b6c2
2 changed files with 6 additions and 3 deletions

View File

@@ -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?

View File

@@ -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