Do not allow deselecting distributor after product added to cart at controller level

This commit is contained in:
Rohan Mitchell
2012-06-24 14:56:27 +10:00
parent d3c80e99fc
commit 7b92fcb614
2 changed files with 21 additions and 3 deletions

View File

@@ -24,8 +24,11 @@ module Spree
def deselect
order = current_order(true)
order.distributor = nil
order.save!
if order.line_items.empty?
order.distributor = nil
order.save!
end
redirect_back_or_default(root_path)
end

View File

@@ -52,6 +52,21 @@ describe Spree::DistributorsController do
o.distributor.should == d1
end
it "does not allow deselecting distributors"
it "does not allow deselecting distributors" do
# Given a distributor and an order with a product
d = create(:distributor)
p = create(:product, :distributors => [d])
o = current_order(true)
o.add_variant(p.master, 1)
o.distributor = d
o.save!
# When I attempt to deselect the distributor
spree_get :deselect
# Then my distributor should remain unchanged
o.reload
o.distributor.should == d
end
end
end