Sha256: 6b99c2380a8d4f9d6589c06df33530e68087f086108f8e6e68b018c50f69e0ea

Contents?: true

Size: 1.23 KB

Versions: 22

Compression:

Stored size: 1.23 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 :number
      category :text
    end

    require 'ostruct'

    thing = OpenStruct.new number: 1, text: "ohai"
    other = OpenStruct.new number: 2, text: "ohai kthxbye"

    data.add thing
    data.add other

    try = Picky::Search.new data

    try.search("text:kthxbye").ids.should == [2]
  end

  it 'can be given a different id (source based)' do
    require 'ostruct'

    things = []
    things << OpenStruct.new(number: 1, text: "ohai")
    things << OpenStruct.new(number: 2, text: "ohai kthxbye")

    data = Picky::Index.new :id do
      source { things }

      id :number, format: 'to_i'
      category :text
    end

    data.index

    try = Picky::Search.new data

    try.search("text:kthxbye").ids.should == [2]
  end

  it 'default is id' do
    index = Picky::Index.new :id do
      category :text
    end

    require 'ostruct'

    thing = OpenStruct.new id: 1, text: "ohai"
    other = OpenStruct.new id: 2, text: "ohai kthxbye"

    index.add thing
    index.add other

    try = Picky::Search.new index

    try.search("text:kthxbye").ids.should == [2]
  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
picky-4.31.3 spec/functional/id_spec.rb
picky-4.31.2 spec/functional/id_spec.rb
picky-4.31.1 spec/functional/id_spec.rb
picky-4.31.0 spec/functional/id_spec.rb
picky-4.30.0 spec/functional/id_spec.rb
picky-4.29.0 spec/functional/id_spec.rb
picky-4.28.1 spec/functional/id_spec.rb
picky-4.27.1 spec/functional/id_spec.rb
picky-4.27.0 spec/functional/id_spec.rb
picky-4.26.2 spec/functional/id_spec.rb
picky-4.26.1 spec/functional/id_spec.rb
picky-4.26.0 spec/functional/id_spec.rb
picky-4.25.3 spec/functional/id_spec.rb
picky-4.25.2 spec/functional/id_spec.rb
picky-4.25.1 spec/functional/id_spec.rb
picky-4.25.0 spec/functional/id_spec.rb
picky-4.24.0 spec/functional/id_spec.rb
picky-4.23.2 spec/functional/id_spec.rb
picky-4.23.1 spec/functional/id_spec.rb
picky-4.23.0 spec/functional/id_spec.rb