Sha256: a807888a701bda54720eae91ccd740675c5c05b8e9a60774350d4106288483c3

Contents?: true

Size: 1.97 KB

Versions: 34

Compression:

Stored size: 1.97 KB

Contents

module Ddr::Models
  RSpec.describe HasChildren do

    subject { FactoryGirl.create(:item) }

    describe "#first_child" do
      describe "when the object has no children" do
        it "should return nil" do
          expect(subject.first_child).to be_nil
        end
      end
      describe "when the object has children" do
        let(:child1) { FactoryGirl.create(:component) }
        let(:child2) { FactoryGirl.create(:component) }
        let(:child3) { FactoryGirl.create(:component) }
        before do
          child1.local_id = "test002"
          child1.save!
          child2.local_id = "test001"
          child2.save!
          child3.local_id = "test003"
          child3.save!
          subject.children << child1
          subject.children << child2
          subject.children << child3
          subject.save!
        end
        describe "when the object has structural metadata" do
          before do
            struct_map = <<-EOS
              <mets xmlns="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink">
                <structMap TYPE="default">
                  <div ORDER="1">
                    <fptr CONTENTIDS="#{child3.id}" />
                  </div>
                  <div ORDER="2">
                    <fptr CONTENTIDS="#{child2.id}" />
                  </div>
                  <div ORDER="3">
                    <fptr CONTENTIDS="#{child1.id}" />
                  </div>
                </structMap>
              </mets>
            EOS
            subject.structMetadata.content = struct_map
            subject.save!
          end
          it "should return the first child based on structural metadata order" do
            expect(subject.first_child).to eq(child3)
          end
        end
        describe "when the object does not have structural metadata" do

          it "should return the first child as sorted by local ID" do
            expect(subject.first_child).to eq(child2)
          end
        end
      end
    end

  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
ddr-models-3.0.8 spec/models/has_children_spec.rb
ddr-models-3.0.7 spec/models/has_children_spec.rb
ddr-models-3.0.6 spec/models/has_children_spec.rb
ddr-models-3.0.5 spec/models/has_children_spec.rb
ddr-models-3.0.4 spec/models/has_children_spec.rb
ddr-models-3.0.3 spec/models/has_children_spec.rb
ddr-models-3.0.2 spec/models/has_children_spec.rb
ddr-models-3.0.1 spec/models/has_children_spec.rb
ddr-models-3.0.0 spec/models/has_children_spec.rb
ddr-models-3.0.0.rc6 spec/models/has_children_spec.rb
ddr-models-3.0.0.rc5 spec/models/has_children_spec.rb
ddr-models-3.0.0.rc4 spec/models/has_children_spec.rb
ddr-models-3.0.0.rc3 spec/models/has_children_spec.rb
ddr-models-3.0.0.rc2 spec/models/has_children_spec.rb
ddr-models-3.0.0.rc1 spec/models/has_children_spec.rb
ddr-models-3.0.0.beta.22 spec/models/has_children_spec.rb
ddr-models-3.0.0.beta.21 spec/models/has_children_spec.rb
ddr-models-3.0.0.beta.20 spec/models/has_children_spec.rb
ddr-models-3.0.0.beta.18 spec/models/has_children_spec.rb
ddr-models-3.0.0.beta.17 spec/models/has_children_spec.rb