diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb index da28643ebe..3ac04651bc 100644 --- a/app/helpers/order_cycles_helper.rb +++ b/app/helpers/order_cycles_helper.rb @@ -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 diff --git a/spec/helpers/order_cycles_helper_spec.rb b/spec/helpers/order_cycles_helper_spec.rb new file mode 100644 index 0000000000..d284bdf82e --- /dev/null +++ b/spec/helpers/order_cycles_helper_spec.rb @@ -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