Sha256: 36345158971df1256a980c39a737f5e81199e7317d2ff81d8971235232443590

Contents?: true

Size: 1.62 KB

Versions: 8

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe ThinkingSphinx::Deletion do
  describe '.perform' do
    let(:connection) { double('connection', :execute => nil) }
    let(:index)      { double('index', :name => 'foo_core',
      :document_id_for_key => 14, :type => 'plain', :distributed? => false) }

    before :each do
      allow(ThinkingSphinx::Connection).to receive(:take).and_yield(connection)
      allow(Riddle::Query).to receive_messages :update => 'UPDATE STATEMENT'
    end

    context 'index is SQL-backed' do
      it "updates the deleted flag to false" do
        expect(connection).to receive(:execute).
          with('UPDATE foo_core SET sphinx_deleted = 1 WHERE id IN (14)')

        ThinkingSphinx::Deletion.perform index, 7
      end

      it "doesn't care about Sphinx errors" do
        allow(connection).to receive(:execute).
          and_raise(ThinkingSphinx::ConnectionError.new(''))

        expect {
          ThinkingSphinx::Deletion.perform index, 7
        }.not_to raise_error
      end
    end

    context "index is real-time" do
      before :each do
        allow(index).to receive_messages :type => 'rt'
      end

      it "deletes the record to false" do
        expect(connection).to receive(:execute).
          with('DELETE FROM foo_core WHERE id = 14')

        ThinkingSphinx::Deletion.perform index, 7
      end

      it "doesn't care about Sphinx errors" do
        allow(connection).to receive(:execute).
          and_raise(ThinkingSphinx::ConnectionError.new(''))

        expect {
          ThinkingSphinx::Deletion.perform index, 7
        }.not_to raise_error
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
thinking-sphinx-4.4.1 spec/thinking_sphinx/deletion_spec.rb
thinking-sphinx-4.4.0 spec/thinking_sphinx/deletion_spec.rb
thinking-sphinx-4.3.2 spec/thinking_sphinx/deletion_spec.rb
thinking-sphinx-4.3.1 spec/thinking_sphinx/deletion_spec.rb
thinking-sphinx-4.3.0 spec/thinking_sphinx/deletion_spec.rb
thinking-sphinx-4.2.0 spec/thinking_sphinx/deletion_spec.rb
thinking-sphinx-4.1.0 spec/thinking_sphinx/deletion_spec.rb
thinking-sphinx-4.0.0 spec/thinking_sphinx/deletion_spec.rb