mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
Adding a standard variant upon initialisation of a new instance of Spree::Product
This commit is contained in:
@@ -32,6 +32,7 @@ Spree::Product.class_eval do
|
||||
validates_presence_of :variant_unit_name,
|
||||
if: -> p { p.variant_unit == 'items' }
|
||||
|
||||
after_initialize :ensure_first_standard_variant, :if => :new_record?
|
||||
after_initialize :set_available_on_to_now, :if => :new_record?
|
||||
after_save :update_units
|
||||
after_touch :touch_distributors
|
||||
@@ -205,4 +206,7 @@ Spree::Product.class_eval do
|
||||
Spree::OptionType.where('name LIKE ?', 'unit_%%')
|
||||
end
|
||||
|
||||
def ensure_first_standard_variant
|
||||
self.variants << Spree::Variant.new
|
||||
end
|
||||
end
|
||||
|
||||
@@ -85,6 +85,14 @@ module Spree
|
||||
end
|
||||
end
|
||||
|
||||
context "instatiating a new product" do
|
||||
let!(:product) { Spree::Product.new }
|
||||
|
||||
it "creates a standard (non-master) variant when created" do
|
||||
product.variants.should_not be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context "when the unit is items" do
|
||||
it "is valid when unit name is set and unit scale is not" do
|
||||
product.variant_unit = 'items'
|
||||
@@ -122,7 +130,6 @@ module Spree
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "scopes" do
|
||||
describe "in_supplier" do
|
||||
|
||||
Reference in New Issue
Block a user