mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add specs for splitting products by various distribution options
This commit is contained in:
@@ -8,7 +8,7 @@ module OpenFoodWeb
|
||||
# If a distributor is provided, split the list of products into local (at that
|
||||
# distributor) and remote (at another distributor). If a distributor is not
|
||||
# provided, perform no split.
|
||||
def split_products_by_distribution(products, distributor)
|
||||
def split_products_by_distribution(products, distributor, order_cycle)
|
||||
products_local = products_remote = nil
|
||||
|
||||
if distributor
|
||||
|
||||
@@ -5,26 +5,30 @@ describe OpenFoodWeb::SplitProductsByDistribution do
|
||||
let(:subject) { products_splitter.new }
|
||||
|
||||
|
||||
it "does nothing when no distributor is selected" do
|
||||
it "does nothing when no distributor or order cycle is selected" do
|
||||
orig_products = (1..3).map { |i| build(:product) }
|
||||
|
||||
products, products_local, products_remote = subject.split_products_by_distribution orig_products, nil
|
||||
products, products_local, products_remote = subject.split_products_by_distribution orig_products, nil, nil
|
||||
|
||||
products.should == orig_products
|
||||
products_local.should be_nil
|
||||
products_remote.should be_nil
|
||||
end
|
||||
|
||||
it "splits products when a distributor is selected" do
|
||||
it "splits products by product distribution when a distributor is selected" do
|
||||
d1 = build(:distributor_enterprise)
|
||||
d2 = build(:distributor_enterprise)
|
||||
orig_products = [build(:product, :distributors => [d1]),
|
||||
build(:product, :distributors => [d2])]
|
||||
|
||||
products, products_local, products_remote = subject.split_products_by_distribution orig_products, d1
|
||||
products, products_local, products_remote = subject.split_products_by_distribution orig_products, d1, nil
|
||||
|
||||
products.should be_nil
|
||||
products_local.should == [orig_products[0]]
|
||||
products_remote.should == [orig_products[1]]
|
||||
end
|
||||
|
||||
it "splits products by order cycle distribution when a distributor is selected"
|
||||
it "splits products by order cycle when an order cycle is selected"
|
||||
it "splits products by both order cycle and distributor when both are selected"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user