Fix distribution_change_validator spec

This commit is contained in:
luisramos0
2019-03-02 12:09:51 +00:00
parent 351555d4e2
commit d7bd944af3
2 changed files with 19 additions and 17 deletions

View File

@@ -9,8 +9,10 @@ class DistributionChangeValidator
end
def variants_available_for_distribution(distributor, order_cycle)
product_distribution_variants = distributor.andand.product_distribution_variants || []
order_cycle_variants = order_cycle.andand.variants_distributed_by(distributor) || []
product_distribution_variants = []
product_distribution_variants = distributor.product_distribution_variants if distributor
order_cycle_variants = []
order_cycle_variants = order_cycle.variants_distributed_by(distributor) if order_cycle
product_distribution_variants + order_cycle_variants
end

View File

@@ -13,45 +13,45 @@ describe DistributionChangeValidator do
order.should_receive(:line_item_variants) { [1] }
subject.should_receive(:variants_available_for_distribution).
with(distributor, order_cycle) { [] }
subject.can_change_to_distribution?(distributor, order_cycle).should be false
expect(subject.can_change_to_distribution?(distributor, order_cycle)).to be false
end
it "returns true when all variants are available for the specified distribution" do
order.should_receive(:line_item_variants) { [1] }
subject.should_receive(:variants_available_for_distribution).
with(distributor, order_cycle) { [1] }
subject.can_change_to_distribution?(distributor, order_cycle).should be true
expect(subject.can_change_to_distribution?(distributor, order_cycle)).to be true
end
end
describe "finding variants that are available through a particular distribution" do
it "finds variants distributed by product distribution" do
v = double(:variant)
d = double(:distributor, product_distribution_variants: [v])
oc = double(:order_cycle, variants_distributed_by: [])
variant = double(:variant)
distributor = double(:distributor, product_distribution_variants: [variant])
order_cycle = double(:order_cycle, variants_distributed_by: [])
subject.variants_available_for_distribution(d, oc).should == [v]
expect(subject.variants_available_for_distribution(distributor, order_cycle)).to eq [variant]
end
it "finds variants distributed by product distribution when order cycle is nil" do
v = double(:variant)
d = double(:distributor, product_distribution_variants: [v])
variant = double(:variant)
distributor = double(:distributor, product_distribution_variants: [variant])
subject.variants_available_for_distribution(d, nil).should == [v]
expect(subject.variants_available_for_distribution(distributor, nil)).to eq [variant]
end
it "finds variants distributed by order cycle" do
v = double(:variant)
d = double(:distributor, product_distribution_variants: [])
oc = double(:order_cycle)
variant = double(:variant)
distributor = double(:distributor, product_distribution_variants: [])
order_cycle = double(:order_cycle)
oc.should_receive(:variants_distributed_by).with(d) { [v] }
order_cycle.should_receive(:variants_distributed_by).with(distributor) { [variant] }
subject.variants_available_for_distribution(d, oc).should == [v]
expect(subject.variants_available_for_distribution(distributor, order_cycle)).to eq [variant]
end
it "returns an empty array when distributor and order cycle are both nil" do
subject.variants_available_for_distribution(nil, nil).should == []
expect(subject.variants_available_for_distribution(nil, nil)).to eq []
end
end
end