Sha256: 5cb9738fd981ff18fe376d1a2ee2e71b9979d9666c4feb627b4a30914aad4a35

Contents?: true

Size: 1.84 KB

Versions: 11

Compression:

Stored size: 1.84 KB

Contents

require 'spec_helper'

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

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

      describe "#structure" 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 }
          it "should return the structural metadata" do
            expect(item.structure.to_xml).to be_equivalent_to(simple_structure)
          end
        end
      end

      describe "#build_default_structure" do
        let(:components) { [ Component.new(pid: 'test:5', identifier: [ 'abc002' ]),
                             Component.new(pid: 'test:6', identifier: [ 'abc001' ]),
                             Component.new(pid: 'test:7', identifier: [ 'abc003' ])
                           ] }
        let(:expected) { FactoryGirl.build(:simple_structure) }
        before { allow(item).to receive(:find_children) { simple_structure_query_response } }
        it "should build the appropriate structural metadata" do
          results = item.build_default_structure
          expect(results).to be_equivalent_to(expected)
        end
      end

      describe "indexing" do
        let(:expected_json) { multiple_struct_maps_structure_to_json }
        before { item.datastreams[Ddr::Datastreams::STRUCT_METADATA].content = multiple_struct_maps_structure }
        it "should index the JSON representation of the structure" do
          indexing = item.to_solr
          expect(indexing.keys).to include(Ddr::IndexFields::STRUCT_MAPS)
          expect(indexing[Ddr::IndexFields::STRUCT_MAPS]).to eq(expected_json)
        end
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ddr-models-2.0.1 spec/models/has_struct_metadata_spec.rb
ddr-models-2.0.0 spec/models/has_struct_metadata_spec.rb
ddr-models-2.0.0.rc6 spec/models/has_struct_metadata_spec.rb
ddr-models-2.0.0.rc5 spec/models/has_struct_metadata_spec.rb
ddr-models-2.0.0.rc4 spec/models/has_struct_metadata_spec.rb
ddr-models-2.0.0.rc3 spec/models/has_struct_metadata_spec.rb
ddr-models-2.0.0.rc2 spec/models/has_struct_metadata_spec.rb
ddr-models-2.0.0.rc1 spec/models/has_struct_metadata_spec.rb
ddr-models-2.0.0.pre.5 spec/models/has_struct_metadata_spec.rb
ddr-models-2.0.0.pre.4 spec/models/has_struct_metadata_spec.rb
ddr-models-2.0.0.pre.3 spec/models/has_struct_metadata_spec.rb