mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-09 03:20:21 +00:00
Extract stub building into private method
This commit is contained in:
@@ -17,11 +17,9 @@ describe OpenFoodWeb::SplitProductsByDistribution do
|
||||
|
||||
it "splits products by distributor when a distributor is selected" do
|
||||
distributor = double(:distributor)
|
||||
local_product, remote_product = double(:product), double(:product)
|
||||
local_product.should_receive(:in_distributor?).any_number_of_times.
|
||||
with(distributor).and_return(true)
|
||||
remote_product.should_receive(:in_distributor?).any_number_of_times.
|
||||
with(distributor).and_return(false)
|
||||
|
||||
local_product = build_product distributor, true, nil, false
|
||||
remote_product = build_product distributor, false, nil, false
|
||||
|
||||
products, products_local, products_remote = subject.split_products_by_distribution [local_product, remote_product], distributor, nil
|
||||
|
||||
@@ -32,11 +30,9 @@ describe OpenFoodWeb::SplitProductsByDistribution do
|
||||
|
||||
it "splits products by order cycle when an order cycle is selected" do
|
||||
order_cycle = double(:order_cycle)
|
||||
local_product, remote_product = double(:product), double(:product)
|
||||
local_product.should_receive(:in_order_cycle?).any_number_of_times.
|
||||
with(order_cycle).and_return(true)
|
||||
remote_product.should_receive(:in_order_cycle?).any_number_of_times.
|
||||
with(order_cycle).and_return(false)
|
||||
|
||||
local_product = build_product nil, false, order_cycle, true
|
||||
remote_product = build_product nil, false, order_cycle, false
|
||||
|
||||
products, products_local, products_remote = subject.split_products_by_distribution [local_product, remote_product], nil, order_cycle
|
||||
|
||||
@@ -49,28 +45,10 @@ describe OpenFoodWeb::SplitProductsByDistribution do
|
||||
distributor = double(:distributor)
|
||||
order_cycle = double(:order_cycle)
|
||||
|
||||
neither_product, distributor_product, order_cycle_product, both_product =
|
||||
double(:product), double(:product), double(:product), double(:product)
|
||||
|
||||
neither_product.should_receive(:in_distributor?).any_number_of_times.
|
||||
with(distributor).and_return(false)
|
||||
neither_product.should_receive(:in_order_cycle?).any_number_of_times.
|
||||
with(order_cycle).and_return(false)
|
||||
|
||||
distributor_product.should_receive(:in_distributor?).any_number_of_times.
|
||||
with(distributor).and_return(true)
|
||||
distributor_product.should_receive(:in_order_cycle?).any_number_of_times.
|
||||
with(order_cycle).and_return(false)
|
||||
|
||||
order_cycle_product.should_receive(:in_distributor?).any_number_of_times.
|
||||
with(distributor).and_return(false)
|
||||
order_cycle_product.should_receive(:in_order_cycle?).any_number_of_times.
|
||||
with(order_cycle).and_return(true)
|
||||
|
||||
both_product.should_receive(:in_distributor?).any_number_of_times.
|
||||
with(distributor).and_return(true)
|
||||
both_product.should_receive(:in_order_cycle?).any_number_of_times.
|
||||
with(order_cycle).and_return(true)
|
||||
neither_product = build_product distributor, false, order_cycle, false
|
||||
distributor_product = build_product distributor, true, order_cycle, false
|
||||
order_cycle_product = build_product distributor, false, order_cycle, true
|
||||
both_product = build_product distributor, true, order_cycle, true
|
||||
|
||||
orig_products = [neither_product, distributor_product, order_cycle_product, both_product]
|
||||
|
||||
@@ -80,4 +58,25 @@ describe OpenFoodWeb::SplitProductsByDistribution do
|
||||
products_local.should == [both_product]
|
||||
products_remote.should == [neither_product, distributor_product, order_cycle_product]
|
||||
end
|
||||
|
||||
|
||||
|
||||
private
|
||||
|
||||
def build_product(distributor, in_distributor, order_cycle, in_order_cycle)
|
||||
product = double(:product)
|
||||
|
||||
if distributor
|
||||
product.should_receive(:in_distributor?).any_number_of_times.
|
||||
with(distributor).and_return(in_distributor)
|
||||
end
|
||||
|
||||
if order_cycle
|
||||
product.should_receive(:in_order_cycle?).any_number_of_times.
|
||||
with(order_cycle).and_return(in_order_cycle)
|
||||
end
|
||||
|
||||
product
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user