Sha256: fb81f35575bc33901878d76925c00e6786d039c5225d4e80ddeb8ec00e808420

Contents?: true

Size: 1.4 KB

Versions: 57

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

RSpec.describe SolrDocument, api: true do
  describe "access methods" do
    let(:solrdoc) do
      described_class.new(id: '00282214', format: ['Book'], title_tsim: 'some-title')
    end

    describe "#[]" do
      subject { solrdoc[field] }

      context "with title_tsim" do
        let(:field) { :title_tsim }

        it { is_expected.to eq 'some-title' }
      end

      context "with format" do
        let(:field) { :format }

        it { is_expected.to eq ['Book'] }
      end
    end

    describe "#id" do
      subject { solrdoc.id }

      it { is_expected.to eq '00282214' }
    end
  end

  describe '.attribute' do
    subject(:title) { document.title }

    let(:doc_class) do
      Class.new(SolrDocument) do
        attribute :title, Blacklight::Types::String, 'title_tesim'
        attribute :author, Blacklight::Types::Array, 'author_tesim'
        attribute :date, Blacklight::Types::Date, 'date_dtsi'
      end
    end
    let(:document) do
      doc_class.new(id: '123',
                    title_tesim: ['Good Omens'],
                    author_tesim: ['Neil Gaiman', 'Terry Pratchett'],
                    date_dtsi: '1990-01-01T00:00:00Z')
    end

    it "casts the attributes" do
      expect(document.title).to eq 'Good Omens'
      expect(document.author).to eq ['Neil Gaiman', 'Terry Pratchett']
      expect(document.date).to eq Date.new(1990)
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
blacklight-7.31.0 spec/models/solr_document_spec.rb
blacklight-7.30.0 spec/models/solr_document_spec.rb
blacklight-7.29.0 spec/models/solr_document_spec.rb
blacklight-7.28.0 spec/models/solr_document_spec.rb
blacklight-7.27.1 spec/models/solr_document_spec.rb
blacklight-7.27.0 spec/models/solr_document_spec.rb
blacklight-7.26.1 spec/models/solr_document_spec.rb
blacklight-7.26.0 spec/models/solr_document_spec.rb
blacklight-7.25.3 spec/models/solr_document_spec.rb
blacklight-7.25.2 spec/models/solr_document_spec.rb
blacklight-7.25.1 spec/models/solr_document_spec.rb
blacklight-7.25.0 spec/models/solr_document_spec.rb
blacklight-7.24.0 spec/models/solr_document_spec.rb
blacklight-7.23.0.1 spec/models/solr_document_spec.rb
blacklight-7.23.0 spec/models/solr_document_spec.rb
blacklight-7.22.2 spec/models/solr_document_spec.rb
blacklight-7.22.1 spec/models/solr_document_spec.rb
blacklight-7.22.0 spec/models/solr_document_spec.rb
blacklight-7.21.2 spec/models/solr_document_spec.rb
blacklight-7.21.1 spec/models/solr_document_spec.rb