Sha256: dd88d873fadd7563979ffeb690f6219b955c20af8da4a59f15dac9069e6e6324

Contents?: true

Size: 1.9 KB

Versions: 15

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

module ThinkingSphinx
  module Middlewares; end
end

require 'thinking_sphinx/middlewares/middleware'
require 'thinking_sphinx/middlewares/glazier'

describe ThinkingSphinx::Middlewares::Glazier do
  let(:app)           { double('app', :call => true) }
  let(:middleware)    { ThinkingSphinx::Middlewares::Glazier.new app }
  let(:context)       { {:results => [result], :indices => [index],
    :meta => {}, :raw => [raw_result], :panes => []} }
  let(:result)        { double 'result', :id => 10, :class => model }
  let(:model)         { double 'model', :name => 'Article' }
  let(:index)         { double 'index', :name => 'foo_core', :model => model,
    :primary_key => :id }
  let(:search)        { double 'search', :options => {} }
  let(:glazed_result) { double 'glazed result' }
  let(:raw_result) {
    {'sphinx_internal_class' => 'Article', 'sphinx_internal_id' => 10} }

  describe '#call' do
    before :each do
      stub_const 'ThinkingSphinx::Search::Glaze', double(:new => glazed_result)

      allow(context).to receive_messages :search => search
    end

    context 'No panes provided' do
      before :each do
        context[:panes].clear
      end

      it "leaves the results as they are" do
        middleware.call [context]

        expect(context[:results]).to eq([result])
      end
    end

    context 'Panes provided' do
      let(:pane_class) { double('pane class') }

      before :each do
        context[:panes] << pane_class
      end

      it "replaces each result with a glazed version" do
        middleware.call [context]

        expect(context[:results]).to eq([glazed_result])
      end

      it "creates a glazed result for each result" do
        expect(ThinkingSphinx::Search::Glaze).to receive(:new).
          with(context, result, raw_result, [pane_class]).
          and_return(glazed_result)

        middleware.call [context]
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 spec/thinking_sphinx/middlewares/glazier_spec.rb
thinking-sphinx-5.5.1 spec/thinking_sphinx/middlewares/glazier_spec.rb
thinking-sphinx-5.5.0 spec/thinking_sphinx/middlewares/glazier_spec.rb
thinking-sphinx-5.4.0 spec/thinking_sphinx/middlewares/glazier_spec.rb
thinking-sphinx-5.3.0 spec/thinking_sphinx/middlewares/glazier_spec.rb
thinking-sphinx-5.2.1 spec/thinking_sphinx/middlewares/glazier_spec.rb
thinking-sphinx-5.2.0 spec/thinking_sphinx/middlewares/glazier_spec.rb
thinking-sphinx-5.1.0 spec/thinking_sphinx/middlewares/glazier_spec.rb
thinking-sphinx-5.0.0 spec/thinking_sphinx/middlewares/glazier_spec.rb
thinking-sphinx-4.4.1 spec/thinking_sphinx/middlewares/glazier_spec.rb
thinking-sphinx-4.4.0 spec/thinking_sphinx/middlewares/glazier_spec.rb
thinking-sphinx-4.3.2 spec/thinking_sphinx/middlewares/glazier_spec.rb
thinking-sphinx-4.3.1 spec/thinking_sphinx/middlewares/glazier_spec.rb
thinking-sphinx-4.3.0 spec/thinking_sphinx/middlewares/glazier_spec.rb
thinking-sphinx-4.2.0 spec/thinking_sphinx/middlewares/glazier_spec.rb