Sha256: 6ba6720279763b1d934ad25aae6c397a52f1ce1d5ae405364d9126495cfe04db

Contents?: true

Size: 1.22 KB

Versions: 37

Compression:

Stored size: 1.22 KB

Contents

describe Spotlight::SolrDocument::AtomicUpdates, type: :model do
  let(:blacklight_solr) { double }
  subject do
    SolrDocument.new.extend(described_class)
  end

  before do
    allow(subject).to receive_messages(blacklight_solr: blacklight_solr)
  end

  describe '#reindex' do
    before do
      allow(subject).to receive_messages(to_solr: { id: 'doc_id', a: 1, b: 2 })
    end

    context 'when the index is not writable' do
      before do
        allow(Spotlight::Engine.config).to receive_messages(writable_index: false)
      end

      it "doesn't write" do
        expect(blacklight_solr).not_to receive(:update)
        subject.reindex
      end
    end

    it 'sends an atomic update request' do
      expected = {
        params: { commitWithin: 500 },
        data: [{ id: 'doc_id', a: { set: 1 }, b: { set: 2 } }].to_json,
        headers: { 'Content-Type' => 'application/json' }
      }
      expect(blacklight_solr).to receive(:update).with(expected)
      subject.reindex
    end

    it 'cowardlies refuse to index a document if the only value is an id' do
      allow(subject).to receive_messages(to_solr: { id: 'doc_id' })
      expect(blacklight_solr).not_to receive(:update)
      subject.reindex
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
blacklight-spotlight-1.4.1 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-1.4.0 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-1.3.0 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-1.2.0 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-1.1.0 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-1.0.0 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-1.0.0.alpha2 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-1.0.0.alpha1 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-0.34.1 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-0.34.0 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-0.33.3 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-0.33.2 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-0.33.1 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-0.33.0 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-0.32.0 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-0.31.0 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-0.30.0 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-0.29.1 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-0.29.0 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-0.28.3 spec/models/spotlight/solr_document/atomic_updates_spec.rb