Sha256: 642c55b137730ae3e24bcffea5cc42808aab9664dfe161bad66c44e0c6136e8f
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
# encoding: utf-8 # require 'spec_helper' describe "id option" do it 'can be given a different id (in-ruby based)' do data = Picky::Index.new :id do id :id category :text, partial: Picky::Partial::Postfix.new(from: 1) category :number end require 'ostruct' thing = OpenStruct.new id: 1, number: 2, text: "aabcdef bcdef" other = OpenStruct.new id: 2, number: 1, text: "abcdef bbcdef" data.add thing data.add other sorting_order = { thing.id => thing, other.id => other } try = Picky::Search.new data # Sort by number. # results = try.search("a") results.sort_by { |id| sorting_order[id].number } results.ids.should == [2,1] # Sort by text. # results = try.search("a") results.sort_by { |id| sorting_order[id].text } results.ids.should == [1,2] # Sort by number. # results = try.search("a* b") results.sort_by { |id| sorting_order[id].number } results.ids.should == [2,1] # Sort by text. # results = try.search("a* b") results.sort_by { |id| sorting_order[id].text } results.ids.should == [1,2] end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
picky-4.23.0 | spec/functional/sort_by_spec.rb |