Sha256: 33190076d31d0c7a6f45e8e7198a0f48a76189e42f5e5eca6fa7b69b86c74d74

Contents?: true

Size: 1.63 KB

Versions: 11

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

describe Spotlight::SolrDocumentSidecar, type: :model do
  let(:exhibit) { FactoryBot.create(:exhibit) }

  before do
    allow(subject).to receive_messages exhibit: exhibit
    allow(subject).to receive_messages document: SolrDocument.new(id: 'doc_id')
  end

  describe '#to_solr' do
    before do
      subject.data = { 'a_tesim' => 1, 'b_tesim' => 2, 'c_tesim' => 3 }
    end

    its(:to_solr) { is_expected.to include id: 'doc_id' }
    its(:to_solr) { is_expected.to include "exhibit_#{exhibit.slug}_public_bsi".to_sym => true }
    its(:to_solr) { is_expected.to include 'a_tesim', 'b_tesim', 'c_tesim' }

    context 'with an uploaded item' do
      before do
        subject.data = { 'configured_fields' => { 'some_configured_field' => 'some value' } }
        allow(Spotlight::Resources::Upload).to receive(:fields).with(exhibit).and_return([uploaded_field_config])
      end

      let(:uploaded_field_config) do
        Spotlight::UploadFieldConfig.new(field_name: 'some_configured_field', solr_fields: ['the_solr_field'])
      end

      its(:to_solr) { is_expected.to include 'the_solr_field' => 'some value' }
    end

    context 'with blank fields' do
      before do
        subject.data = {
          'a_blank_field' => '',
          'a_blank_multivalued_field' => ['', ''],
          'a_multivalued_field_with_some_blanks' => ['', 'a']
        }
      end

      its(:to_solr) { is_expected.to include 'a_blank_field' => nil }
      its(:to_solr) { is_expected.to include 'a_blank_multivalued_field' => [] }
      its(:to_solr) { is_expected.to include 'a_multivalued_field_with_some_blanks' => ['a'] }
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

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