mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-25 05:45:15 +00:00
On enterprise page, do not display products outside of the outgoing exchange
This commit is contained in:
@@ -10,7 +10,48 @@ describe EnterprisesController do
|
||||
assigns(:suppliers).should == [s]
|
||||
end
|
||||
|
||||
context "shopping for a distributor" do
|
||||
describe "displaying an enterprise and its products" do
|
||||
let(:p) { create(:simple_product, supplier: s) }
|
||||
let(:s) { create(:supplier_enterprise) }
|
||||
let!(:c) { create(:distributor_enterprise) }
|
||||
let(:d1) { create(:distributor_enterprise) }
|
||||
let(:d2) { create(:distributor_enterprise) }
|
||||
let(:oc1) { create(:simple_order_cycle) }
|
||||
let(:oc2) { create(:simple_order_cycle) }
|
||||
|
||||
it "displays products for the selected (order_cycle -> outgoing exchange)" do
|
||||
create(:exchange, order_cycle: oc1, sender: s, receiver: c, variants: [p.master])
|
||||
create(:exchange, order_cycle: oc1, sender: c, receiver: d1, variants: [p.master])
|
||||
|
||||
controller.stub(:current_distributor) { d1 }
|
||||
controller.stub(:current_order_cycle) { oc1 }
|
||||
|
||||
spree_get :show, {id: d1}
|
||||
|
||||
assigns(:products).should include p
|
||||
end
|
||||
|
||||
it "does not display other products in the order cycle or in the distributor" do
|
||||
# Given a product that is in this order cycle on a different distributor
|
||||
create(:exchange, order_cycle: oc1, sender: s, receiver: c, variants: [p.master])
|
||||
create(:exchange, order_cycle: oc1, sender: c, receiver: d2, variants: [p.master])
|
||||
|
||||
# And is also in this distributor in a different order cycle
|
||||
create(:exchange, order_cycle: oc2, sender: s, receiver: c, variants: [p.master])
|
||||
create(:exchange, order_cycle: oc2, sender: c, receiver: d1, variants: [p.master])
|
||||
|
||||
# When I view the enterprise page for d1 x oc1
|
||||
controller.stub(:current_distributor) { d1 }
|
||||
controller.stub(:current_order_cycle) { oc1 }
|
||||
spree_get :show, {id: d1}
|
||||
|
||||
# Then I should not see the product
|
||||
assigns(:products).should_not include p
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "shopping for a distributor" do
|
||||
|
||||
before(:each) do
|
||||
@current_distributor = create(:distributor_enterprise)
|
||||
@@ -69,7 +110,7 @@ describe EnterprisesController do
|
||||
end
|
||||
end
|
||||
|
||||
context "BaseController: handling order cycles expiring mid-order" do
|
||||
describe "BaseController: handling order cycles expiring mid-order" do
|
||||
it "clears the order and displays an expiry message" do
|
||||
oc = double(:order_cycle, id: 123, expired?: true)
|
||||
controller.stub(:current_order_cycle) { oc }
|
||||
|
||||
@@ -172,9 +172,9 @@ describe OrderCycle do
|
||||
@e2 = create(:exchange,
|
||||
order_cycle: @oc, sender: @oc.coordinator, receiver: @d2)
|
||||
|
||||
@p0 = create(:product)
|
||||
@p1 = create(:product)
|
||||
@p2 = create(:product)
|
||||
@p0 = create(:simple_product)
|
||||
@p1 = create(:simple_product)
|
||||
@p2 = create(:simple_product)
|
||||
@p2_v = create(:variant, product: @p2)
|
||||
|
||||
@e0.variants << @p0.master
|
||||
@@ -196,6 +196,10 @@ describe OrderCycle do
|
||||
@oc.variants_distributed_by(@d2).should == [@p1.master]
|
||||
end
|
||||
|
||||
it "reports on the products distributed by a particular distributor" do
|
||||
@oc.products_distributed_by(@d2).should == [@p1]
|
||||
end
|
||||
|
||||
it "reports on the products exchanged" do
|
||||
@oc.products.sort.should == [@p0, @p1, @p2]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user