Sha256: a19213f365783d6abbf7c9c21e1c472b09a7007f58978b369d04a0191f4bef20

Contents?: true

Size: 1.32 KB

Versions: 29

Compression:

Stored size: 1.32 KB

Contents

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

describe Sunspot::Search::HitEnumerable do
  subject do
    Class.new do
      include Sunspot::Search::HitEnumerable
    end.new
  end

  describe "#hits" do
    before do
      subject.stub(:solr_docs).and_return([{"id" => "Post 1", "score" => 3.14}])
      subject.stub(:highlights_for)
    end

    it "retrieves the raw Solr response from #solr_docs and constructs Hit objects" do
      Sunspot::Search::Hit.should_receive(:new).
                           with({"id" => "Post 1", "score" => 3.14}, anything, anything)

      subject.hits
    end

    it "constructs Hit objects with highlights" do
      subject.should_receive(:highlights_for).with({"id" => "Post 1", "score" => 3.14})

      subject.hits
    end

    it "returns only verified hits if :verify => true is passed" do
      Sunspot::Search::Hit.any_instance.stub(:result).and_return(nil)

      subject.hits(:verify => true).should be_empty
    end

    it "returns an empty array if no results are available from Solr" do
      subject.stub(:solr_docs).and_return(nil)

      subject.hits.should == []
    end

    it "provides #populate_hits so that querying for one hit result will eager load the rest" do
      Sunspot::Search::Hit.any_instance.should_receive(:result=)

      subject.populate_hits
    end
  end
end

Version data entries

29 entries across 29 versions & 6 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot-2.2.7/spec/api/hit_enumerable_spec.rb
sunspot-2.2.7 spec/api/hit_enumerable_spec.rb
sunspot-2.2.6 spec/api/hit_enumerable_spec.rb
sunspot-2.2.5 spec/api/hit_enumerable_spec.rb
sunspot-2.2.4 spec/api/hit_enumerable_spec.rb
sunspot-2.2.3 spec/api/hit_enumerable_spec.rb
sunspot-2.2.2 spec/api/hit_enumerable_spec.rb
sunspot-2.2.1 spec/api/hit_enumerable_spec.rb
sunspot-2.2.0 spec/api/hit_enumerable_spec.rb
sunspot-2.1.1 spec/api/hit_enumerable_spec.rb
sunspot-2.1.0 spec/api/hit_enumerable_spec.rb
sunspot-2.0.0 spec/api/hit_enumerable_spec.rb
sunspot-2.0.0.pre.130115 spec/api/hit_enumerable_spec.rb
gojee-sunspot-2.0.5 spec/api/hit_enumerable_spec.rb
sunspot-2.0.0.pre.120925 spec/api/hit_enumerable_spec.rb
sunspot_solr-2.0.0.pre.120924 sunspot/spec/api/hit_enumerable_spec.rb
sunspot_rails-2.0.0.pre.120924 sunspot/spec/api/hit_enumerable_spec.rb
sunspot-2.0.0.pre.120924 sunspot/spec/api/hit_enumerable_spec.rb
gojee-sunspot-2.0.4 spec/api/hit_enumerable_spec.rb
gojee-sunspot-2.0.2 spec/api/hit_enumerable_spec.rb