Add specs for splitting products by various distribution options

This commit is contained in:
Rohan Mitchell
2013-04-05 11:41:37 +11:00
parent f8ebb0c715
commit cf4fe269d1
2 changed files with 9 additions and 5 deletions

View File

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

View File

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