mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
OrdersController does not permit adding products with invalid distributors
This commit is contained in:
@@ -30,6 +30,12 @@ Spree::OrdersController.class_eval do
|
||||
return false unless variant.product.distributors.include? distributor
|
||||
end if params[:variants]
|
||||
|
||||
# -- If products in cart, distributor can't be changed
|
||||
order = current_order(false)
|
||||
if !order.nil? && order.distributor != distributor
|
||||
return false
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,6 +35,46 @@ describe Spree::OrdersController do
|
||||
# Then our order should have its distributor set to the chosen distributor
|
||||
current_order(false).distributor.should == d
|
||||
end
|
||||
end
|
||||
|
||||
context "adding a subsequent product to the cart" do
|
||||
before(:each) do
|
||||
# Given a product and a distributor
|
||||
@distributor = create(:distributor)
|
||||
@product = create(:product, :distributors => [@distributor])
|
||||
|
||||
# And the product is in the cart
|
||||
spree_put :populate, :variants => {@product.id => 1}, :distributor_id => @distributor.id
|
||||
current_order(false).line_items.map { |li| li.product }.should == [@product]
|
||||
current_order(false).distributor.should == @distributor
|
||||
end
|
||||
|
||||
it "does not add the product if the product is not available at the order's distributor" do
|
||||
# Given a product at another distributor
|
||||
d2 = create(:distributor)
|
||||
p2 = create(:product, :distributors => [d2])
|
||||
|
||||
# When I attempt to add the product to the cart
|
||||
spree_put :populate, :variants => {p2.id => 1}, :distributor_id => d2.id
|
||||
|
||||
# Then the product should not be added to the cart
|
||||
current_order(false).line_items.map { |li| li.product }.should == [@product]
|
||||
current_order(false).distributor.should == @distributor
|
||||
end
|
||||
|
||||
it "does not add the product if the product is not available at the given distributor" do
|
||||
# Given a product at another distributor
|
||||
d2 = create(:distributor)
|
||||
p2 = create(:product, :distributors => [d2])
|
||||
|
||||
# When I attempt to add the product to the cart with a fake distributor_id
|
||||
spree_put :populate, :variants => {p2.id => 1}, :distributor_id => @distributor.id
|
||||
|
||||
# Then the product should not be added to the cart
|
||||
current_order(false).line_items.map { |li| li.product }.should == [@product]
|
||||
current_order(false).distributor.should == @distributor
|
||||
end
|
||||
|
||||
it "does not add the product if the chosen distributor is different from the order's distributor"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -51,8 +51,18 @@ feature %q{
|
||||
|
||||
context "adding a subsequent product to the cart" do
|
||||
it "does not allow the user to choose a distributor" do
|
||||
# Instead, they see "Your distributor for this order is XYZ"
|
||||
pending
|
||||
# Given a product under a distributor
|
||||
d = create(:distributor)
|
||||
p = create(:product, :distributors => [d])
|
||||
|
||||
# And a product in my cart
|
||||
visit spree.product_path p
|
||||
click_button 'Add To Cart'
|
||||
|
||||
# When I go to add it again, I should not have a choice of distributor
|
||||
visit spree.product_path p
|
||||
page.should_not have_selector 'select#distributor_id'
|
||||
page.should have_selector 'p', :text => "Your distributor for this order is #{d.name}"
|
||||
end
|
||||
|
||||
it "does not allow the user to add a product from another distributor" do
|
||||
|
||||
Reference in New Issue
Block a user