Sha256: 6c1e4c488fe3030786615d483cda493f0240ac381eb2a5e03afde8cc97c2b593

Contents?: true

Size: 1.86 KB

Versions: 14

Compression:

Stored size: 1.86 KB

Contents

require 'spec_helper'

describe Query::Live do

  before(:each) do
    # @category1  = Index::Category.new
    # @type_index = Index::Type.new :some_name, :some_result_type, @category1
    @index = stub :index
  end

  describe 'result_type' do
    before(:each) do
      @query = Query::Live.new 'some query', 0, @index
    end
    it "should return a specific type" do
      @query.result_type.should == Results::Live
    end
  end

  describe "execute" do
    before(:each) do
      @query = Query::Live.new @index
    end
    it "should get allocations" do
      @query.should_receive(:results_from).and_return stub(:results, :prepare! => true)
      @query.should_receive(:sorted_allocations).once

      @query.execute 'some_query', 0
    end
    it "should generate a max amount of results from allocations" do
      allocations = stub :allocations
      @query.should_receive(:sorted_allocations).and_return allocations

      @query.should_receive(:results_from).once.with(0, allocations).and_return stub(:results, :prepare! => true)

      @query.execute 'some query', 0
    end
  end

  describe "results_from" do
    describe "with empty ids" do
      before(:each) do
        @query = Query::Live.new 'some query', @index
        @allocations = stub :allocations, :total => 0, :ids => [], :to_result => :some_results, :process! => nil
      end
      it "should generate a result" do
        @query.results_from(@allocations).should be_kind_of Results::Live
      end
      it "should generate a result with 0 result count" do
        @query.results_from(@allocations).total.should == 0
      end
      it "should generate a result with 0 duration" do
        @query.results_from(@allocations).duration.should == 0
      end
      it "should generate a result with the allocations" do
        @query.results_from(0, @allocations).allocations.should == @allocations
      end
    end
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
picky-0.10.5 spec/lib/query/live_spec.rb
picky-0.10.4 spec/lib/query/live_spec.rb
picky-0.10.2 spec/lib/query/live_spec.rb
picky-0.10.1 spec/lib/query/live_spec.rb
picky-0.10.0 spec/lib/query/live_spec.rb
picky-0.9.4 spec/lib/query/live_spec.rb
picky-0.9.3 spec/lib/query/live_spec.rb
picky-0.9.2 spec/lib/query/live_spec.rb
picky-0.9.1 spec/lib/query/live_spec.rb
picky-0.9.0 spec/lib/query/live_spec.rb
picky-0.3.0 spec/lib/query/live_spec.rb
picky-0.2.4 spec/lib/query/live_spec.rb
picky-0.2.3 spec/lib/query/live_spec.rb
picky-0.2.2 spec/lib/query/live_spec.rb