spec/functional/range_queries_spec.rb in picky-4.11.2 vs spec/functional/range_queries_spec.rb in picky-4.11.3

- old
+ new

@@ -83,7 +83,55 @@ # it 'handles combined range/partial queries' do # # TODO This still needs to be refined. It is madness. # # # try.search('198-200*').ids.should == [8,3,1,4,5,7,6,2] # end + + describe 'custom ranges' do + class Wrap12Hours + include Enumerable + + def initialize(min, max) + @hours = 12 + @min = min.to_i + @top = max.to_i + @top += @hours if @top < @min + end + + def each + @min.upto(@top).each do |i| + yield (i % @hours).to_s + end + end + end + + let(:index) do + index = Picky::Index.new :range_queries do + category :hour, + ranging: Wrap12Hours, + partial: Picky::Partial::None.new + end + + rangy = Struct.new :id, :hour + + index.add rangy.new(1, 0) + index.add rangy.new(2, 1) + index.add rangy.new(3, 4) + index.add rangy.new(4, 5) + index.add rangy.new(5, 11) + index.add rangy.new(6, 10) + index.add rangy.new(7, 2) + index.add rangy.new(8, 3) + + index + end + + it 'allows injection of custom range classes' do + try.search('hour:10-2').ids.should == [6, 5, 1, 2, 7] + end + + it 'allows injection of custom range classes' do + try.search('hour:0-11').ids.should == [1, 2, 7, 8, 3, 4, 6, 5] + end + end -end \ No newline at end of file +end