mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add helper to generate a local/remote class for order cycle selection
This commit is contained in:
@@ -2,4 +2,14 @@ module OrderCyclesHelper
|
||||
def coordinating_enterprises
|
||||
Enterprise.is_distributor.order('name')
|
||||
end
|
||||
|
||||
def order_cycle_local_remote_class(distributor, order_cycle)
|
||||
if distributor.nil?
|
||||
''
|
||||
elsif order_cycle.distributors.include? distributor
|
||||
' local'
|
||||
else
|
||||
' remote'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
28
spec/helpers/order_cycles_helper_spec.rb
Normal file
28
spec/helpers/order_cycles_helper_spec.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe OrderCyclesHelper do
|
||||
subject do
|
||||
obj = Object.new
|
||||
obj.extend(OrderCyclesHelper)
|
||||
end
|
||||
|
||||
describe "generating local/remote classes for order cycle selection" do
|
||||
it "returns blank when no distributor selected" do
|
||||
subject.order_cycle_local_remote_class(nil, double(:order_cycle)).should == ''
|
||||
end
|
||||
|
||||
it "returns local when the order cycle includes the current distributor" do
|
||||
distributor = double(:enterprise)
|
||||
order_cycle = double(:order_cycle, distributors: [distributor])
|
||||
|
||||
subject.order_cycle_local_remote_class(distributor, order_cycle).should == ' local'
|
||||
end
|
||||
|
||||
it "returns remote when the order cycle does not include the current distributor" do
|
||||
distributor = double(:enterprise)
|
||||
order_cycle = double(:order_cycle, distributors: [])
|
||||
|
||||
subject.order_cycle_local_remote_class(distributor, order_cycle).should == ' remote'
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user