Sha256: ec84974b0d6d344304b731eb81a2f7cfc2694ba3392a58fd2d4ed45f69df3dca

Contents?: true

Size: 1.29 KB

Versions: 14

Compression:

Stored size: 1.29 KB

Contents

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

describe 'more_like_this' do
  before :all do
    Sunspot.remove_all
    @posts = [
      Post.new(:body => "one two three", :tags => %w(ruby sunspot rsolr)),
      Post.new(:body => "four five six", :tags => %w(ruby solr lucene)),
      Post.new(:body => "two three four", :tags => %w(python sqlalchemy)),
      Post.new(:body => "three four five", :tags => %w(ruby sunspot mat)),
      Post.new(:body => "six seven eight", :tags => %w(bogus airplane))
    ]
    Sunspot.index!(@posts)
  end

  it 'should return results for all MLT fields' do
    Sunspot.more_like_this(@posts.first).results.to_set.should == @posts[1..3].to_set
  end

  it 'should return results for specified text field' do
    Sunspot.more_like_this(@posts.first) do 
      fields :body
    end.results.to_set.should == @posts[2..3].to_set
  end

  it 'should return empty result set if no results' do
    Sunspot.more_like_this(@posts.last) do
      with(:title, 'bogus')
    end.results.should == []
  end

  describe 'when non-indexed object searched' do
    before(:each) { @mlt = Sunspot.more_like_this(Post.new) }

    it 'should return empty result set' do
      @mlt.results.should == []
    end

    it 'shoult return a total of 0' do
      @mlt.total.should == 0
    end
  end
end

Version data entries

14 entries across 14 versions & 5 rubygems

Version Path
erichummel-sunspot-1.2.1g spec/integration/more_like_this_spec.rb
erichummel-sunspot-1.2.1f spec/integration/more_like_this_spec.rb
erichummel-sunspot-1.2.1b spec/integration/more_like_this_spec.rb
erichummel-sunspot-1.2.1a spec/integration/more_like_this_spec.rb
lisausa-sunspot-1.2.1.1 spec/integration/more_like_this_spec.rb
ruben-sunspot-1.1.4 spec/integration/more_like_this_spec.rb
ruben-sunspot-1.1.3 spec/integration/more_like_this_spec.rb
ruben-sunspot-1.1.2 spec/integration/more_like_this_spec.rb
sunspot-1.2.1 spec/integration/more_like_this_spec.rb
sunspot-1.2.0 spec/integration/more_like_this_spec.rb
ruben-sunspot-1.1.1 spec/integration/more_like_this_spec.rb
ruben-sunspot-1.1.0 spec/integration/more_like_this_spec.rb
nuatt_sunspot-1.1.0.3 spec/integration/more_like_this_spec.rb
sunspot-1.1.0 spec/integration/more_like_this_spec.rb