mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-03 22:06:07 +00:00
Cannot remove all variants from a product
This commit is contained in:
@@ -23,6 +23,7 @@ Spree::Product.class_eval do
|
||||
|
||||
before_validation :ensure_standard_variant, if: :new_record?
|
||||
|
||||
validates_presence_of :variants, message: "Product must have at least one variant"
|
||||
validates_presence_of :supplier
|
||||
validates :primary_taxon, presence: { message: "^Product Category can't be blank" }
|
||||
validates :tax_category_id, presence: { message: "^Tax Category can't be blank" }, if: "Spree::Config.products_require_tax_category"
|
||||
|
||||
@@ -8,7 +8,7 @@ module Spree
|
||||
it { should belong_to(:primary_taxon) }
|
||||
it { should have_many(:product_distributions) }
|
||||
end
|
||||
|
||||
|
||||
describe "validations and defaults" do
|
||||
it "is valid when built from factory" do
|
||||
build(:product).should be_valid
|
||||
@@ -61,6 +61,14 @@ module Spree
|
||||
end
|
||||
|
||||
|
||||
it "does not allow only standard variant to be deleted" do
|
||||
product = create(:simple_product)
|
||||
expect(product.variants(:reload).length).to eq 1
|
||||
product.variants = []
|
||||
expect(product.save).to be_false
|
||||
expect(product.errors[:variants]).to include "Product must have at least one variant"
|
||||
end
|
||||
|
||||
context "when the product has variants" do
|
||||
let(:product) do
|
||||
product = create(:simple_product)
|
||||
|
||||
Reference in New Issue
Block a user