mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Master variants are valid without unit value or description
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
Spree::Variant.class_eval do
|
||||
validates_presence_of :unit_value,
|
||||
if: -> v { %w(weight volume).include? v.product.variant_unit }
|
||||
if: -> v { %w(weight volume).include? v.product.variant_unit },
|
||||
unless: :is_master
|
||||
|
||||
validates_presence_of :unit_description,
|
||||
if: -> v { v.product.variant_unit.present? && v.unit_value.nil? }
|
||||
if: -> v { v.product.variant_unit.present? && v.unit_value.nil? },
|
||||
unless: :is_master
|
||||
end
|
||||
|
||||
@@ -29,7 +29,7 @@ module Spree
|
||||
let(:product) do
|
||||
product = create(:simple_product)
|
||||
create(:variant, product: product)
|
||||
product
|
||||
product.reload
|
||||
end
|
||||
|
||||
it "requires a unit" do
|
||||
|
||||
@@ -10,6 +10,7 @@ module Spree
|
||||
context "when the product's unit is #{unit}" do
|
||||
before do
|
||||
product.update_attribute :variant_unit, unit
|
||||
product.reload
|
||||
end
|
||||
|
||||
it "is valid when unit value is set and unit description is not" do
|
||||
@@ -22,12 +23,17 @@ module Spree
|
||||
variant.unit_value = nil
|
||||
variant.should_not be_valid
|
||||
end
|
||||
|
||||
it "has a valid master variant" do
|
||||
product.master.should be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when the product's unit is items" do
|
||||
before do
|
||||
product.update_attribute :variant_unit, 'items'
|
||||
product.reload
|
||||
end
|
||||
|
||||
it "is valid with only unit value set" do
|
||||
@@ -47,6 +53,10 @@ module Spree
|
||||
variant.unit_description = nil
|
||||
variant.should_not be_valid
|
||||
end
|
||||
|
||||
it "has a valid master variant" do
|
||||
product.master.should be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user