require 'spec_helper' describe Spree::OrdersController do def current_user controller.current_user end it "selects distributors" do d = create(:distributor_enterprise) p = create(:product, :distributors => [d]) spree_get :select_distributor, :id => d.id response.should be_redirect order = subject.current_order(false) order.distributor.should == d end it "deselects distributors" do d = create(:distributor_enterprise) p = create(:product, :distributors => [d]) order = subject.current_order(true) order.distributor = d order.save! spree_get :deselect_distributor response.should be_redirect order.reload order.distributor.should be_nil end context "adding a group buy product to the cart" do it "sets a variant attribute for the max quantity" do distributor_product = create(:distributor_enterprise) p = create(:product, :distributors => [distributor_product], :group_buy => true) order = subject.current_order(true) order.should_receive(:set_variant_attributes).with(p.master, {'max_quantity' => '3'}) controller.stub(:current_order).and_return(order) expect do spree_post :populate, :variants => {p.master.id => 1}, :variant_attributes => {p.master.id => {:max_quantity => 3}}, :distributor_id => distributor_product.id end.to change(Spree::LineItem, :count).by(1) end end end