Sha256: 54971f2263a6ae38e744f05af6cb0cf5d880b5c0a5ccaecc0e28b747bb372c6e

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

require File.join(File.dirname(__FILE__), 'spec_helper')

describe 'keyword search' do
  before :all do
    Sunspot.remove_all
    @posts = []
    @posts << Post.new(:title => 'The toast elects the insufficient spirit',
                       :body => 'Does the wind write?')
    @posts << Post.new(:title => 'A nail abbreviates the recovering insight outside the moron',
                       :body => 'The interpreted strain scans the buffer around the upper temper')
    @posts << Post.new(:title => 'The toast abbreviates the recovering spirit',
                       :body => 'Does the wind interpret the buffer?')
    Sunspot.index!(*@posts)
    @comment = Namespaced::Comment.new(:body => 'Hey there where ya goin, not exactly knowin, who says you have to call just one place toast.')
    Sunspot.index!(@comment)
  end

  it 'matches a single keyword out of a single field' do
    results = Sunspot.search(Post) { keywords 'toast' }.results
    [0, 2].each { |i| results.should include(@posts[i]) }
    [1].each { |i| results.should_not include(@posts[i]) }
  end

  it 'matches multiple words out of a single field' do
    results = Sunspot.search(Post) { keywords 'elects toast' }.results
    results.should == [@posts[0]]
  end

  it 'matches multiple words in multiple fields' do
    results = Sunspot.search(Post) { keywords 'toast wind' }.results
    [0, 2].each { |i| results.should include(@posts[i]) }
    [1].each { |i| results.should_not include(@posts[i]) }
  end

  it 'matches multiple types' do
    results = Sunspot.search(Post, Namespaced::Comment) do
      keywords 'toast'
    end.results
    [@posts[0], @posts[2], @comment].each  { |obj| results.should include(obj) }
    results.should_not include(@posts[1])
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
outoftime-sunspot-0.8.8 spec/integration/keyword_search_spec.rb
outoftime-sunspot-0.8.9 spec/integration/keyword_search_spec.rb