Cannot remove all variants from a product

This commit is contained in:
Rob Harrington
2014-10-02 18:32:40 +10:00
parent 5e2fe56c22
commit a223a2d662
2 changed files with 10 additions and 1 deletions

View File

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

View File

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