Add helper to generate a local/remote class for order cycle selection

This commit is contained in:
Rohan Mitchell
2013-02-01 11:44:28 +11:00
parent 456dfcf6db
commit 72a9286457
2 changed files with 38 additions and 0 deletions

View File

@@ -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

View 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