Rename Enterprise#available_variants to distributed_variants to remove ambiguity between supplied/distributed variants

This commit is contained in:
Rohan Mitchell
2013-04-05 16:51:51 +11:00
parent 5649a50e28
commit f66ff0f8b1
4 changed files with 12 additions and 13 deletions

View File

@@ -41,7 +41,7 @@ class Enterprise < ActiveRecord::Base
"#{id}-#{name.parameterize}"
end
def available_variants
def distributed_variants
Spree::Product.in_distributor(self).map { |product| product.variants + [product.master] }.flatten
end

View File

@@ -16,7 +16,7 @@ class DistributorChangeValidator
def available_distributors enterprises
enterprises.select do |e|
(@order.line_item_variants - e.available_variants).empty?
(@order.line_item_variants - e.distributed_variants).empty?
end
end
end
end

View File

@@ -25,7 +25,7 @@ describe DistributorChangeValidator do
line_item_variants = [variant1, variant3, variant5]
order.stub(:line_item_variants){ line_item_variants }
enterprise = double(:enterprise)
enterprise.stub(:available_variants){ line_item_variants } # Exactly the same variants as the order
enterprise.stub(:distributed_variants){ line_item_variants } # Exactly the same variants as the order
subject.available_distributors([enterprise]).should == [enterprise]
end
@@ -37,7 +37,7 @@ describe DistributorChangeValidator do
line_item_variants = [variant1, variant3, variant5]
order.stub(:line_item_variants){ line_item_variants }
enterprise = double(:enterprise)
enterprise.stub(:available_variants){ [] } # No variants
enterprise.stub(:distributed_variants){ [] } # No variants
subject.available_distributors([enterprise]).should_not include enterprise
end
@@ -51,9 +51,9 @@ describe DistributorChangeValidator do
line_item_variants = [variant1, variant3, variant5]
order.stub(:line_item_variants){ line_item_variants }
enterprise_with_some_variants = double(:enterprise)
enterprise_with_some_variants.stub(:available_variants){ [variant1, variant3] } # Only some variants
enterprise_with_some_variants.stub(:distributed_variants){ [variant1, variant3] } # Only some variants
enterprise_with_some_plus_extras = double(:enterprise)
enterprise_with_some_plus_extras.stub(:available_variants){ [variant1, variant2, variant3, variant4] } # Only some variants, plus extras
enterprise_with_some_plus_extras.stub(:distributed_variants){ [variant1, variant2, variant3, variant4] } # Only some variants, plus extras
subject.available_distributors([enterprise_with_some_variants]).should_not include enterprise_with_some_variants
subject.available_distributors([enterprise_with_some_plus_extras]).should_not include enterprise_with_some_plus_extras
@@ -68,7 +68,7 @@ describe DistributorChangeValidator do
line_item_variants = [variant1, variant3, variant5]
order.stub(:line_item_variants){ line_item_variants }
enterprise = double(:enterprise)
enterprise.stub(:available_variants){ [variant1, variant2, variant3, variant4, variant5] } # Excess variants
enterprise.stub(:distributed_variants){ [variant1, variant2, variant3, variant4, variant5] } # Excess variants
subject.available_distributors([enterprise]).should == [enterprise]
end
@@ -77,4 +77,4 @@ describe DistributorChangeValidator do
subject.available_distributors([]).should == []
end
end
end
end

View File

@@ -94,26 +94,25 @@ describe Enterprise do
end
end
# TODO: Rename to distributed_variants?
describe "finding variants distributed by the enterprise" do
it "finds the master variant" do
d = create(:distributor_enterprise)
p = create(:product, distributors: [d])
d.available_variants.should == [p.master]
d.distributed_variants.should == [p.master]
end
it "finds other variants" do
d = create(:distributor_enterprise)
p = create(:product, distributors: [d])
v = create(:variant, product: p)
d.available_variants.sort.should == [p.master, v].sort
d.distributed_variants.sort.should == [p.master, v].sort
end
it "finds variants distributed by order cycle" do
d = create(:distributor_enterprise)
p = create(:product)
oc = create(:simple_order_cycle, distributors: [d], variants: [p.master])
d.available_variants.should == [p.master]
d.distributed_variants.should == [p.master]
end
end
end