mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Require a distributor when adding a product to the cart
This commit is contained in:
11
app/controllers/spree/orders_controller_decorator.rb
Normal file
11
app/controllers/spree/orders_controller_decorator.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
Spree::OrdersController.class_eval do
|
||||
before_filter :populate_order_distributor, :only => :populate
|
||||
|
||||
def populate_order_distributor
|
||||
@distributor = Spree::Distributor.find params[:distributor_id]
|
||||
if @distributor.nil?
|
||||
return false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
14
spec/controllers/orders_controller_spec.rb
Normal file
14
spec/controllers/orders_controller_spec.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::OrdersController do
|
||||
context "adding the first product to the cart" do
|
||||
it "does nothing if the user does not specify a distributor" do
|
||||
create(:distributor)
|
||||
p = create(:product)
|
||||
|
||||
expect do
|
||||
spree_put :populate, :variants => {p.id => 1}
|
||||
end.to change(Spree::LineItem, :count).by(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user