Sha256: 99fb7b38348f1844ec60e3e2cdd21d6037aa14cb04252d97ad7f2ed5308179af
Contents?: true
Size: 1.82 KB
Versions: 2
Compression:
Stored size: 1.82 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 => double(:name => 'Article')) } let(:index) { double('index', :name => 'foo_core') } 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
thinking-sphinx-4.1.0 | spec/thinking_sphinx/middlewares/glazier_spec.rb |
thinking-sphinx-4.0.0 | spec/thinking_sphinx/middlewares/glazier_spec.rb |