mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Create OrderCycleFormApplicator, for interfacing between front-end form and OrderCycle exchanges model.
This commit is contained in:
18
lib/open_food_web/order_cycle_form_applicator.rb
Normal file
18
lib/open_food_web/order_cycle_form_applicator.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
module OpenFoodWeb
|
||||
class OrderCycleFormApplicator
|
||||
def initialize(order_cycle)
|
||||
@order_cycle = order_cycle
|
||||
end
|
||||
|
||||
def go!
|
||||
@order_cycle.incoming_exchanges.each do |exchange|
|
||||
add_exchange(exchange[:enterprise_id], @order_cycle.coordinator_id)
|
||||
end
|
||||
end
|
||||
|
||||
def add_exchange(sender_id, receiver_id)
|
||||
@order_cycle.exchanges.create! :sender_id => sender_id, :receiver_id => receiver_id
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
18
spec/lib/open_food_web/order_cycle_form_applicator.rb
Normal file
18
spec/lib/open_food_web/order_cycle_form_applicator.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
require 'open_food_web/order_cycle_form_applicator'
|
||||
|
||||
module OpenFoodWeb
|
||||
describe OrderCycleFormApplicator do
|
||||
it "creates new exchanges for incoming_exchanges" do
|
||||
coordinator_id = 123
|
||||
supplier_id = 456
|
||||
|
||||
oc = double(:order_cycle, :coordinator_id => coordinator_id, :incoming_exchanges => [{:enterprise_id => supplier_id}])
|
||||
|
||||
applicator = OrderCycleFormApplicator.new(oc)
|
||||
|
||||
applicator.should_receive(:add_exchange).with(supplier_id, coordinator_id)
|
||||
|
||||
applicator.go!
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user