Sha256: 4f0317d6d827d8cc14f31804a40493305f19173bc8953163c8dd3741bdd162a3

Contents?: true

Size: 1.46 KB

Versions: 17

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module ThinkingSphinx
  module Middlewares; end
  class  Search; end
end

require 'thinking_sphinx/middlewares/middleware'
require 'thinking_sphinx/middlewares/stale_id_checker'
require 'thinking_sphinx/search/stale_ids_exception'

describe ThinkingSphinx::Middlewares::StaleIdChecker do
  let(:app)        { double('app') }
  let(:middleware) { ThinkingSphinx::Middlewares::StaleIdChecker.new app }
  let(:context)    { {:raw => [], :results => []} }
  let(:model)      { double('model') }

  def raw_result(id, model_name)
    {'sphinx_internal_id' => id, 'sphinx_internal_class' => model_name}
  end

  describe '#call' do
    it 'passes the call on if there are no nil results' do
      context[:raw] << raw_result(24, 'Article')
      context[:raw] << raw_result(42, 'Article')

      context[:results] << double('instance', :id => 24)
      context[:results] << double('instance', :id => 42)

      expect(app).to receive(:call)

      middleware.call [context]
    end

    it "raises a stale id exception if ActiveRecord doesn't return ids" do
      context[:raw] << raw_result(24, 'Article')
      context[:raw] << raw_result(42, 'Article')

      context[:results] << double('instance', :id => 24)
      context[:results] << nil

      expect {
        middleware.call [context]
      }.to raise_error(ThinkingSphinx::Search::StaleIdsException) { |err|
        expect(err.ids).to eq([42])
        expect(err.context).to eq(context)
      }
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

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