diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb new file mode 100644 index 0000000000..bb2d2be1aa --- /dev/null +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -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 diff --git a/spec/controllers/orders_controller_spec.rb b/spec/controllers/orders_controller_spec.rb new file mode 100644 index 0000000000..b78ab3b034 --- /dev/null +++ b/spec/controllers/orders_controller_spec.rb @@ -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