Sha256: e72192e61b434419dd8be36dcbadca3180d271a2660914ded2006d1c88d5dc85

Contents?: true

Size: 1.29 KB

Versions: 12

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

describe Spotlight::SolrDocument::AtomicUpdates, type: :model do
  subject do
    SolrDocument.new.extend(described_class)
  end

  let(:blacklight_solr) { double }

  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 }, timestamp: { set: nil } }].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' }, timestamp: { set: nil })
      expect(blacklight_solr).not_to receive(:update)
      subject.reindex
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
blacklight-spotlight-3.0.0.rc4 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-3.0.0.rc3 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-3.0.0.rc2 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-3.0.0.rc1 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-3.0.0.alpha.10 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-3.0.0.alpha.9 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-3.0.0.alpha.8 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-3.0.0.alpha.7 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-3.0.0.alpha.6 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-3.0.0.alpha.5 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-3.0.0.alpha.4 spec/models/spotlight/solr_document/atomic_updates_spec.rb
blacklight-spotlight-3.0.0.alpha.3 spec/models/spotlight/solr_document/atomic_updates_spec.rb