Sha256: d6a6cff6098dfe9f70a3f345aec196f9c5dbe31bf862d5b1ca0a6a0494b04e1d

Contents?: true

Size: 1.87 KB

Versions: 24

Compression:

Stored size: 1.87 KB

Contents

describe Spotlight::FieldMetadata do
  let(:exhibit) { FactoryBot.create(:exhibit) }
  let(:repository) { double }
  let(:blacklight_config) do
    Blacklight::Configuration.new do |config|
      config.add_facet_field 'a'
      config.add_facet_field 'b'
      config.add_facet_field 'some_key', field: 'c'
    end
  end

  let(:facet_response) do
    {
      facet_counts: {
        facet_fields: {
          a: { 'a' => 1, 'b' => 2, 'c' => 3 },
          b: { 'b' => 1 },
          c: { 7 => 1, 8 => 2, 9 => 3 }
        },

        facet_queries: {
          'a:[* TO *]' => 5,
          'b:[* TO *]' => 10,
          'c:[* TO *]' => 15
        }
      }
    }.with_indifferent_access
  end

  subject { described_class.new(exhibit, repository, blacklight_config) }

  before do
    allow(repository).to receive(:search).with(an_instance_of(SearchBuilder)).and_return(Blacklight::Solr::Response.new(facet_response, {}))
  end

  describe '#field' do
    it 'has a document count' do
      expect(subject.field('a')[:document_count]).to eq 5
      expect(subject.field('b')[:document_count]).to eq 10
      expect(subject.field('some_key')[:document_count]).to eq 15
    end

    it 'has a value count' do
      expect(subject.field('a')[:value_count]).to eq 3
      expect(subject.field('b')[:value_count]).to eq 1
      expect(subject.field('some_key')[:value_count]).to eq 3
    end

    it 'gets a list of top terms' do
      expect(subject.field('a')[:terms]).to match_array %w(a b c)
      expect(subject.field('b')[:terms]).to match_array %w(b)
      expect(subject.field('some_key')[:terms]).to match_array [7, 8, 9]
    end

    context 'for a missing field' do
      it 'has reasonable default values' do
        expect(subject.field('d')[:document_count]).to eq 0
        expect(subject.field('d')[:value_count]).to eq 0
        expect(subject.field('d')[:terms]).to be_empty
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
blacklight-spotlight-2.4.1 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.4.0 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.3.3 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.3.2 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.3.1 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.3.0 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.2.1 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.2.0 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.1.0 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.0.2 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.0.1 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.0.0 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.0.0.rc6 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.0.0.rc5 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.0.0.rc4 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.0.0.rc3 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.0.0.rc2 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-2.0.0.rc1 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-1.5.1 spec/models/spotlight/field_metadata_spec.rb
blacklight-spotlight-1.4.1 spec/models/spotlight/field_metadata_spec.rb