mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-23 05:28:53 +00:00
Raise error if distributor changed illegally
This commit is contained in:
@@ -6,6 +6,11 @@ Spree::Order.class_eval do
|
||||
line_items.empty?
|
||||
end
|
||||
|
||||
def distributor=(distributor)
|
||||
raise "You cannot change the distributor of an order with products" unless can_change_distributor?
|
||||
super(distributor)
|
||||
end
|
||||
|
||||
# before_validation :shipping_address_from_distributor
|
||||
|
||||
private
|
||||
|
||||
@@ -11,5 +11,7 @@
|
||||
%li.nowrap
|
||||
- if order.nil? || order.can_change_distributor?
|
||||
= link_to distributor.name, select_distributor_path(distributor)
|
||||
- else
|
||||
= distributor.name
|
||||
- if current_distributor && order.can_change_distributor?
|
||||
%li.nowrap= link_to 'Leave distributor', deselect_distributors_path
|
||||
|
||||
@@ -40,8 +40,8 @@ describe Spree::DistributorsController do
|
||||
d2 = create(:distributor)
|
||||
p = create(:product, :distributors => [d1])
|
||||
o = current_order(true)
|
||||
o.add_variant(p.master, 1)
|
||||
o.distributor = d1
|
||||
o.add_variant(p.master, 1)
|
||||
o.save!
|
||||
|
||||
# When I attempt to select a distributor
|
||||
@@ -57,8 +57,8 @@ describe Spree::DistributorsController do
|
||||
d = create(:distributor)
|
||||
p = create(:product, :distributors => [d])
|
||||
o = current_order(true)
|
||||
o.add_variant(p.master, 1)
|
||||
o.distributor = d
|
||||
o.add_variant(p.master, 1)
|
||||
o.save!
|
||||
|
||||
# When I attempt to deselect the distributor
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Order do
|
||||
it "provides permissions for changing distributor" do
|
||||
it "reveals permission for changing distributor" do
|
||||
p = build(:product)
|
||||
|
||||
subject.can_change_distributor?.should be_true
|
||||
subject.add_variant(p.master, 1)
|
||||
subject.can_change_distributor?.should be_false
|
||||
end
|
||||
|
||||
it "raises an exception if distributor is changed without permission" do
|
||||
p = build(:product)
|
||||
subject.add_variant(p.master, 1)
|
||||
subject.can_change_distributor?.should be_false
|
||||
|
||||
expect do
|
||||
subject.distributor = nil
|
||||
end.to raise_error "You cannot change the distributor of an order with products"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user