mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-12 03:50:22 +00:00
Order cycle can have the same enterprise participating as supplier, coordinator and distributor
This commit is contained in:
@@ -11,7 +11,7 @@ class Exchange < ActiveRecord::Base
|
|||||||
has_many :enterprise_fees, :through => :exchange_fees
|
has_many :enterprise_fees, :through => :exchange_fees
|
||||||
|
|
||||||
validates_presence_of :order_cycle, :sender, :receiver
|
validates_presence_of :order_cycle, :sender, :receiver
|
||||||
validates_uniqueness_of :sender_id, :scope => [:order_cycle_id, :receiver_id]
|
validates_uniqueness_of :sender_id, :scope => [:order_cycle_id, :receiver_id, :incoming]
|
||||||
|
|
||||||
accepts_nested_attributes_for :variants
|
accepts_nested_attributes_for :variants
|
||||||
|
|
||||||
|
|||||||
@@ -13,13 +13,17 @@ describe Exchange do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be valid when sender and receiver pair are not unique for its order cycle" do
|
it "should not be valid when (sender, receiver, direction) set are not unique for its order cycle" do
|
||||||
e1 = create(:exchange)
|
e1 = create(:exchange)
|
||||||
|
|
||||||
e2 = build(:exchange,
|
e2 = build(:exchange,
|
||||||
:order_cycle => e1.order_cycle, :sender => e1.sender, :receiver => e1.receiver)
|
:order_cycle => e1.order_cycle, :sender => e1.sender, :receiver => e1.receiver, :incoming => e1.incoming)
|
||||||
e2.should_not be_valid
|
e2.should_not be_valid
|
||||||
|
|
||||||
|
e2.incoming = !e2.incoming
|
||||||
|
e2.should be_valid
|
||||||
|
e2.incoming = !e2.incoming
|
||||||
|
|
||||||
e2.receiver = create(:enterprise)
|
e2.receiver = create(:enterprise)
|
||||||
e2.should be_valid
|
e2.should be_valid
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user