Sha256: 27a42c3f7e77b8e36468223c6dbe8240c480a2faf86904e50c62754610297b4c

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

# encoding: utf-8
#
require 'spec_helper'

describe 'Search#only' do

  it 'offers the option only' do
    index = Picky::Index.new :only do
      category :text1
      category :text2
      category :text3
    end

    index.add Struct.new(:id, :text1, :text2, :text3).new(1, 'text1', 'text2', 'text3')

    try = Picky::Search.new index
    try.search('text1').ids.should == [1]
    try.search('text2').ids.should == [1]
    try.search('text3').ids.should == [1]

    try_again = Picky::Search.new index do
      only :text1
    end
    try_again.search('text1').ids.should == [1]
    try_again.search('text2').ids.should == []
    try_again.search('text3').ids.should == []

    try_again.only :text2, :text3
    try_again.search('text1').ids.should == []
    try_again.search('text2').ids.should == [1]
    try_again.search('text3').ids.should == [1]
    
    try_again.search('text1:text1').ids.should == []
    try_again.search('text2:text2').ids.should == [1]
    try_again.search('text3:text3').ids.should == [1]
    
    try_again.search('text1,text2,text3:text1').ids.should == []
    try_again.search('text1,text2:text1').ids.should == []
    try_again.search('text1,text3:text1').ids.should == []
    try_again.search('text2,text3:text1').ids.should == []
    
    try_again.search('text1,text2,text3:text2').ids.should == [1]
    try_again.search('text1,text2:text2').ids.should == [1]
    try_again.search('text1,text3:text2').ids.should == []
    try_again.search('text2,text3:text2').ids.should == [1]
    
    try_again.search('text1,text2,text3:text3').ids.should == [1]
    try_again.search('text1,text2:text3').ids.should == []
    try_again.search('text1,text3:text3').ids.should == [1]
    try_again.search('text2,text3:text3').ids.should == [1]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
picky-4.0.5 spec/functional/only_spec.rb