Sha256: 8c3699fc8dc5e58d171c63fd0326d1124dcf17499bc35a09969969211fe06710

Contents?: true

Size: 1.95 KB

Versions: 4

Compression:

Stored size: 1.95 KB

Contents

module Ddr::Models
  RSpec.describe HasStructMetadata, type: :model, structural_metadata: true do

    let(:item) { Item.new(pid: 'test:2') }

    describe "#structures" do
      context "no existing structural metadata" do
        it "should return nil" do
          expect(item.structure).to eq(nil)
        end
      end
      context "existing structural metadata" do
        before { item.datastreams[Ddr::Datastreams::STRUCT_METADATA].content = simple_structure_xml }
        it "should return the structural metadata" do
          expect(item.structure.to_xml).to be_equivalent_to(simple_structure_xml)
        end
      end
    end

    describe "indexing" do
      let(:expected_json) { nested_structure_to_json }
      before do
        item.datastreams[Ddr::Datastreams::STRUCT_METADATA].content = nested_structure_xml
        flocat_x = instance_double("Structures::FLocat", effective_use: 'foo')
        flocat_y = instance_double("Structures::FLocat", effective_use: 'bar')
        flocat_z = instance_double("Structures::FLocat", effective_use: 'baz')
        file_a = instance_double("Structures::File", repo_ids: [ 'test:7' ], flocats: [ flocat_x ])
        file_b = instance_double("Structures::File", repo_ids: [ 'test:8' ], flocats: [ flocat_y ])
        file_c = instance_double("Structures::File", repo_ids: [ 'test:9' ], flocats: [ flocat_z ])
        allow(Structures::File).to receive(:find).with(an_instance_of(Ddr::Models::Structure), 'abc') { file_a }
        allow(Structures::File).to receive(:find).with(an_instance_of(Ddr::Models::Structure), 'def') { file_b }
        allow(Structures::File).to receive(:find).with(an_instance_of(Ddr::Models::Structure), 'ghi') { file_c }
      end
      it "should index the JSON representation of the structures" do
        indexing = item.to_solr
        expect(indexing.keys).to include(Ddr::Index::Fields::STRUCTURE)
        expect(indexing[Ddr::Index::Fields::STRUCTURE]).to eq(expected_json)
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ddr-models-2.7.2 spec/models/has_struct_metadata_spec.rb
ddr-models-2.7.1 spec/models/has_struct_metadata_spec.rb
ddr-models-2.7.0 spec/models/has_struct_metadata_spec.rb
ddr-models-2.7.0.rc1 spec/models/has_struct_metadata_spec.rb