diff options
Diffstat (limited to 'spec/models/product_cart_spec.rb')
-rw-r--r-- | spec/models/product_cart_spec.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/spec/models/product_cart_spec.rb b/spec/models/product_cart_spec.rb index 2c4d9d1..46860d3 100644 --- a/spec/models/product_cart_spec.rb +++ b/spec/models/product_cart_spec.rb @@ -20,4 +20,14 @@ RSpec.describe ProductCart, type: :model do expect(another_product_cart.errors[:product_id]).to be_present end end + + describe '#product_quantity' do + it "validates the requested quantity against the product's available quantity" do + product = create(:product, available_quantity: 5) + another_product_cart = build(:product_cart, cart: product_cart.cart, product:, quantity: 10) + + expect(another_product_cart.save).to be_falsey + expect(another_product_cart.errors[:product_id][0]).to eq('not enough in existence') + end + end end |