Sha256: 0e40e1a7eb2cd269f382745fa64cd8102b6f72ea701386b456f8152072ed7e13

Contents?: true

Size: 1.53 KB

Versions: 29

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

RSpec.describe Spotlight::UploadFieldConfig do
  describe '#label' do
    it 'accepts a proc and calls it' do
      label = -> { 'returned string' }
      expect(described_class.new(field_name: 'something', label: label).label).to eq 'returned string'
    end

    it 'returns any non-proc value' do
      expect(described_class.new(field_name: 'something', label: 'String').label).to eq 'String'
    end

    it 'falls back to the field name when no label is given' do
      expect(described_class.new(field_name: 'something').label).to eq 'something'
    end
  end

  describe '#solr_field' do
    it 'is an alias of the #solr_field method so it can be polymorphic with other Blacklight configurations' do
      expect(described_class.new(field_name: 'something').solr_field).to eq 'something'
    end
  end

  describe '#solr_fields' do
    it 'is backwards compatible with the old way of configuring fields' do
      expect(described_class.new(field_name: 'something').solr_fields).to eq ['something']
    end
  end

  describe '#data_to_solr' do
    it 'returns a hash of the various solr fields mapped to the provided value' do
      expect(described_class.new(field_name: 'something', solr_fields: %w[a b]).data_to_solr('value')).to eq 'a' => 'value', 'b' => 'value'
    end

    it 'supports configuring a lambda to pre-process data for a field' do
      expect(described_class.new(field_name: 'something', solr_fields: [int_field: ->(value) { value.to_i }]).data_to_solr('123value')).to eq int_field: 123
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
blacklight-spotlight-3.4.0 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.3.0 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.2.0 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.1.0 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.0.3 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.0.2 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.0.1 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.0.0 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.0.0.rc6 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.0.0.rc5 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.0.0.rc4 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.0.0.rc3 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.0.0.rc2 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.0.0.rc1 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.0.0.alpha.10 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.0.0.alpha.9 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.0.0.alpha.8 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.0.0.alpha.7 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.0.0.alpha.6 spec/lib/spotlight/upload_field_config_spec.rb
blacklight-spotlight-3.0.0.alpha.5 spec/lib/spotlight/upload_field_config_spec.rb