From 65b760b119ac0f9a89f24d13a44ddde8838ce462 Mon Sep 17 00:00:00 2001 From: Guido Oliveira Date: Thu, 27 May 2021 17:54:36 -0300 Subject: [PATCH] Add validations to variant_override model --- app/models/variant_override.rb | 2 ++ spec/models/spree/line_item_spec.rb | 10 ---------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/app/models/variant_override.rb b/app/models/variant_override.rb index 9fd26b1ed4..66a93e473b 100644 --- a/app/models/variant_override.rb +++ b/app/models/variant_override.rb @@ -15,6 +15,8 @@ class VariantOverride < ApplicationRecord validates :variant, presence: true # Default stock can be nil, indicating stock should not be reset or zero, meaning reset to zero. Need to ensure this can be set by the user. validates :default_stock, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true + validates :price, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true + validates :count_on_hand, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true default_scope { where(permission_revoked_at: nil) } diff --git a/spec/models/spree/line_item_spec.rb b/spec/models/spree/line_item_spec.rb index a98685bab4..07d575f80c 100644 --- a/spec/models/spree/line_item_spec.rb +++ b/spec/models/spree/line_item_spec.rb @@ -264,16 +264,6 @@ module Spree li.cap_quantity_at_stock! expect(li.quantity).to eq 2 end - - context "when count on hand is negative" do - before { vo.update(count_on_hand: -3) } - - it "caps at zero" do - v.__send__(:stock_item).update_column(:count_on_hand, -2) - li.cap_quantity_at_stock! - expect(li.reload.quantity).to eq 0 - end - end end end