Sha256: 61985cb64fd275ada7d8331c95481bdf83320ccd4642cf93c0433b464ab182cb

Contents?: true

Size: 1.6 KB

Versions: 10

Compression:

Stored size: 1.6 KB

Contents

module ThinkingSphinx
  module Middlewares; end
end

require 'thinking_sphinx/middlewares/middleware'
require 'thinking_sphinx/middlewares/inquirer'

describe ThinkingSphinx::Middlewares::Inquirer do
  let(:app)            { double('app', :call => true) }
  let(:middleware)     { ThinkingSphinx::Middlewares::Inquirer.new app }
  let(:context)        { {:sphinxql => sphinx_sql} }
  let(:sphinx_sql)     { double('sphinx_sql',
    :to_sql => 'SELECT * FROM index') }
  let(:batch_inquirer) { double('batcher', :append_query => true,
    :results => [[:raw], [{'Variable_name' => 'meta', 'Value' => 'value'}]]) }

  before :each do
    context.stub(:log) do |notification, message, &block|
      block.call unless block.nil?
    end

    batch_class = double
    batch_class.stub(:new).and_return(batch_inquirer)

    stub_const 'Riddle::Query', double(:meta => 'SHOW META')
    stub_const 'ThinkingSphinx::Search::BatchInquirer', batch_class
  end

  describe '#call' do
    it "passes through the SphinxQL from a Riddle::Query::Select object" do
      batch_inquirer.should_receive(:append_query).with('SELECT * FROM index')
      batch_inquirer.should_receive(:append_query).with('SHOW META')

      middleware.call [context]
    end

    it "sets up the raw results" do
      middleware.call [context]

      context[:raw].should == [:raw]
    end

    it "sets up the meta results as a hash" do
      middleware.call [context]

      context[:meta].should == {'meta' => 'value'}
    end

    it "uses the raw values as the initial results" do
      middleware.call [context]

      context[:results].should == [:raw]
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
thinking-sphinx-3.1.0 spec/thinking_sphinx/middlewares/inquirer_spec.rb
thinking-sphinx-3.0.6 spec/thinking_sphinx/middlewares/inquirer_spec.rb
thinking-sphinx-3.0.5 spec/thinking_sphinx/middlewares/inquirer_spec.rb
thinking-sphinx-3.0.4 spec/thinking_sphinx/middlewares/inquirer_spec.rb
thinking-sphinx-3.0.3 spec/thinking_sphinx/middlewares/inquirer_spec.rb
thinking-sphinx-3.0.2 spec/thinking_sphinx/middlewares/inquirer_spec.rb
thinking-sphinx-3.0.1 spec/thinking_sphinx/middlewares/inquirer_spec.rb
thinking-sphinx-3.0.0 spec/thinking_sphinx/middlewares/inquirer_spec.rb
thinking-sphinx-3.0.0.rc spec/thinking_sphinx/middlewares/inquirer_spec.rb
thinking-sphinx-3.0.0.pre spec/thinking_sphinx/middlewares/inquirer_spec.rb