From 4974c22dfb31ecce3b2891508c3729c772b5b9f2 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Fri, 21 Dec 2018 11:15:01 -0600 Subject: [PATCH] Deprecate Item#public_xml --- lib/dor/models/concerns/publishable.rb | 1 + lib/dor/services/publish_metadata_service.rb | 2 +- spec/models/concerns/publishable_spec.rb | 305 +++---------------- spec/services/public_xml_service_spec.rb | 216 +++++++++++++ 4 files changed, 267 insertions(+), 257 deletions(-) create mode 100644 spec/services/public_xml_service_spec.rb diff --git a/lib/dor/models/concerns/publishable.rb b/lib/dor/models/concerns/publishable.rb index 400dca6a..c7344353 100644 --- a/lib/dor/models/concerns/publishable.rb +++ b/lib/dor/models/concerns/publishable.rb @@ -58,6 +58,7 @@ def public_relationships def public_xml PublicXmlService.new(self).to_xml end + deprecation_deprecate public_xml: 'Use PublicXmlService#to_xml instead' # Copies this object's public_xml to the Purl document cache if it is world discoverable # otherwise, it prunes the object's metadata from the document cache diff --git a/lib/dor/services/publish_metadata_service.rb b/lib/dor/services/publish_metadata_service.rb index 65c9cf5b..dae15539 100644 --- a/lib/dor/services/publish_metadata_service.rb +++ b/lib/dor/services/publish_metadata_service.rb @@ -30,7 +30,7 @@ def transfer_metadata %w(identityMetadata contentMetadata rightsMetadata).each do |stream| transfer_to_document_store(item.datastreams[stream].content.to_s, stream) if item.datastreams[stream] end - transfer_to_document_store(item.public_xml, 'public') + transfer_to_document_store(PublicXmlService.new(item).to_xml, 'public') transfer_to_document_store(PublicDescMetadataService.new(self).to_xml, 'mods') end diff --git a/spec/models/concerns/publishable_spec.rb b/spec/models/concerns/publishable_spec.rb index 81693520..a39f6d31 100644 --- a/spec/models/concerns/publishable_spec.rb +++ b/spec/models/concerns/publishable_spec.rb @@ -4,100 +4,40 @@ class PublishableItem < ActiveFedora::Base include Dor::Identifiable - include Dor::Contentable include Dor::Publishable - include Dor::Describable - include Dor::Processable - include Dor::Releaseable include Dor::Rightsable - include Dor::Governable include Dor::Itemizable end -class DescribableItem < ActiveFedora::Base - include Dor::Identifiable - include Dor::Describable - include Dor::Processable -end - -class ItemizableItem < ActiveFedora::Base - include Dor::Itemizable - include Dor::Describable -end - -describe Dor::Publishable do - before(:each) do - stub_config +RSpec.describe Dor::Publishable do + before do Dor.configure do stacks do host 'stacks.stanford.edu' end end end - after { unstub_config } - before do - @item = instantiate_fixture('druid:ab123cd4567', PublishableItem) - @collection = instantiate_fixture('druid:ab123cd4567', Dor::Collection) - @apo = instantiate_fixture('druid:fg890hi1234', Dor::AdminPolicyObject) - allow(@item).to receive(:admin_policy_object).and_return(@apo) - @mods = <<-EOXML - - druid:ab123cd4567 - - EOXML - - @rights = <<-EOXML - - - (c) Copyright 2010 by Sebastian Jeremias Osterfeld - - - - - stanford:stanford - - - - by-sa - CC Attribution Share Alike license - - - EOXML - - @rels = <<-EOXML - - - - - - - - - - EOXML - - @item.contentMetadata.content = '' - @item.descMetadata.content = @mods - @item.rightsMetadata.content = @rights - @item.rels_ext.content = @rels - allow_any_instance_of(Dor::PublicDescMetadataService).to receive(:ng_xml).and_return(Nokogiri::XML(@mods)) # calls Item.find and not needed in general tests - allow(OpenURI).to receive(:open_uri).with('https://purl-test.stanford.edu/ab123cd4567.xml').and_return('') + let(:item) do + instantiate_fixture('druid:ab123cd4567', PublishableItem) end it 'has a rightsMetadata datastream' do - expect(@item.datastreams['rightsMetadata']).to be_a(ActiveFedora::OmDatastream) + expect(item.datastreams['rightsMetadata']).to be_a(ActiveFedora::OmDatastream) end describe '#build_rightsMetadata_datastream' do + let(:apo) { instantiate_fixture('druid:fg890hi1234', Dor::AdminPolicyObject) } + let(:rights_md) { apo.defaultObjectRights.content } + + before do + allow(item).to receive(:admin_policy_object).and_return(apo) + end + it 'copies the default object rights' do - rights_md = @apo.defaultObjectRights.content - expect(@item.datastreams['rightsMetadata'].ng_xml.to_s).not_to be_equivalent_to(rights_md) - @item.build_rightsMetadata_datastream(@item.rightsMetadata) - expect(@item.datastreams['rightsMetadata'].ng_xml.to_s).to be_equivalent_to(rights_md) + expect(item.datastreams['rightsMetadata'].ng_xml.to_s).not_to be_equivalent_to(rights_md) + item.build_rightsMetadata_datastream(item.rightsMetadata) + expect(item.datastreams['rightsMetadata'].ng_xml.to_s).to be_equivalent_to(rights_md) end end @@ -106,7 +46,6 @@ class ItemizableItem < ActiveFedora::Base expect(Deprecation).to receive(:warn) end subject { item.thumb } - let(:item) { @item } let(:service) { instance_double(Dor::ThumbnailService, thumb: 'Test Result') } it 'calls the thumbnail service' do @@ -120,14 +59,15 @@ class ItemizableItem < ActiveFedora::Base expect(Deprecation).to receive(:warn).at_least(1).times end it 'should return nil if there is no contentMetadata datastream' do - expect(@collection.thumb_url).to be_nil + collection = instantiate_fixture('druid:ab123cd4567', Dor::Collection) + expect(collection.thumb_url).to be_nil end it 'should return nil if there is no contentMetadata' do - expect(@item.thumb_url).to be_nil + expect(item.thumb_url).to be_nil end it 'should find the first image as the thumb when no specific thumbs are specified' do - @item.contentMetadata.content = <<-XML + item.contentMetadata.content = <<-XML @@ -135,11 +75,11 @@ class ItemizableItem < ActiveFedora::Base XML - expect(@item.thumb_url).to eq('https://stacks.stanford.edu/image/iiif/ab123cd4567%2Fab123cd4567_05_0001/full/!400,400/0/default.jpg') + expect(item.thumb_url).to eq('https://stacks.stanford.edu/image/iiif/ab123cd4567%2Fab123cd4567_05_0001/full/!400,400/0/default.jpg') end it 'should find a page resource marked as thumb with the thumb attribute when there is a resource thumb specified but not the thumb attribute' do - @item.contentMetadata.content = <<-XML + item.contentMetadata.content = <<-XML @@ -154,11 +94,11 @@ class ItemizableItem < ActiveFedora::Base XML - expect(@item.encoded_thumb).to eq('ab123cd4567%2Fab123cd4567_05_0002.jp2') - expect(@item.thumb_url).to eq('https://stacks.stanford.edu/image/iiif/ab123cd4567%2Fab123cd4567_05_0002/full/!400,400/0/default.jpg') + expect(item.encoded_thumb).to eq('ab123cd4567%2Fab123cd4567_05_0002.jp2') + expect(item.thumb_url).to eq('https://stacks.stanford.edu/image/iiif/ab123cd4567%2Fab123cd4567_05_0002/full/!400,400/0/default.jpg') end it 'should find an externalFile image resource when there are no other images' do - @item.contentMetadata.content = <<-XML + item.contentMetadata.content = <<-XML @@ -169,11 +109,11 @@ class ItemizableItem < ActiveFedora::Base XML - expect(@item.encoded_thumb).to eq('cg767mn6478%2F2542A.jp2') - expect(@item.thumb_url).to eq('https://stacks.stanford.edu/image/iiif/cg767mn6478%2F2542A/full/!400,400/0/default.jpg') + expect(item.encoded_thumb).to eq('cg767mn6478%2F2542A.jp2') + expect(item.thumb_url).to eq('https://stacks.stanford.edu/image/iiif/cg767mn6478%2F2542A/full/!400,400/0/default.jpg') end it 'should find an externalFile page resource when there are no other images, even if objectId attribute is missing druid prefix' do - @item.contentMetadata.content = <<-XML + item.contentMetadata.content = <<-XML @@ -184,11 +124,11 @@ class ItemizableItem < ActiveFedora::Base XML - expect(@item.encoded_thumb).to eq('cg767mn6478%2F2542A.jp2') - expect(@item.thumb_url).to eq('https://stacks.stanford.edu/image/iiif/cg767mn6478%2F2542A/full/!400,400/0/default.jpg') + expect(item.encoded_thumb).to eq('cg767mn6478%2F2542A.jp2') + expect(item.thumb_url).to eq('https://stacks.stanford.edu/image/iiif/cg767mn6478%2F2542A/full/!400,400/0/default.jpg') end it 'should find an explicit externalFile thumb resource before another image resource, and encode the space' do - @item.contentMetadata.content = <<-XML + item.contentMetadata.content = <<-XML @@ -199,11 +139,11 @@ class ItemizableItem < ActiveFedora::Base XML - expect(@item.encoded_thumb).to eq('cg767mn6478%2F2542A%20withspace.jp2') - expect(@item.thumb_url).to eq('https://stacks.stanford.edu/image/iiif/cg767mn6478%2F2542A%20withspace/full/!400,400/0/default.jpg') + expect(item.encoded_thumb).to eq('cg767mn6478%2F2542A%20withspace.jp2') + expect(item.thumb_url).to eq('https://stacks.stanford.edu/image/iiif/cg767mn6478%2F2542A%20withspace/full/!400,400/0/default.jpg') end it 'should return nil if no thumb is identified' do - @item.contentMetadata.content = <<-XML + item.contentMetadata.content = <<-XML @@ -211,176 +151,29 @@ class ItemizableItem < ActiveFedora::Base XML - expect(@item.encoded_thumb).to be_nil - expect(@item.thumb_url).to be_nil + expect(item.encoded_thumb).to be_nil + expect(item.thumb_url).to be_nil end it 'should return nil if there is no contentMetadata datastream at all' do - @item.datastreams['contentMetadata'] = nil - expect(@item.encoded_thumb).to be_nil - expect(@item.thumb_url).to be_nil + item.datastreams['contentMetadata'] = nil + expect(item.encoded_thumb).to be_nil + expect(item.thumb_url).to be_nil end end describe '#public_xml' do - context 'there are no release tags' do - before :each do - expect(@item).to receive(:released_for).and_return({}) - @p_xml = Nokogiri::XML(@item.public_xml) - end - it 'does not include a releaseData element and any info in identityMetadata' do - expect(@p_xml.at_xpath('/publicObject/releaseData')).to be_nil - expect(@p_xml.at_xpath('/publicObject/identityMetadata/release')).to be_nil - end - end - - context 'produces xml with' do - let(:public_xml) { Nokogiri::XML(@item.public_xml) } - before(:each) do - @now = Time.now.utc - allow(Time).to receive(:now).and_return(@now) - end - - it 'an encoding of UTF-8' do - expect(public_xml.encoding).to match(/UTF-8/) - end - it 'an id attribute' do - expect(public_xml.at_xpath('/publicObject/@id').value).to match(/^druid:ab123cd4567/) - end - it 'a published attribute' do - expect(public_xml.at_xpath('/publicObject/@published').value).to eq(@now.xmlschema) - end - it 'a published version' do - expect(public_xml.at_xpath('/publicObject/@publishVersion').value).to eq('dor-services/' + Dor::VERSION) - end - it 'identityMetadata' do - expect(public_xml.at_xpath('/publicObject/identityMetadata')).to be - end - it 'no contentMetadata element' do - expect(public_xml.at_xpath('/publicObject/contentMetadata')).not_to be - end - - describe 'with contentMetadata present' do - before do - @item.contentMetadata.content = <<-XML - - - - - - - XML - end - it 'include contentMetadata' do - expect(public_xml.at_xpath('/publicObject/contentMetadata')).to be - end - end - - it 'rightsMetadata' do - expect(public_xml.at_xpath('/publicObject/rightsMetadata')).to be - end - it 'generated mods' do - expect(public_xml.at_xpath('/publicObject/mods:mods', 'mods' => 'http://www.loc.gov/mods/v3')).to be - end - - it 'generated dublin core' do - expect(public_xml.at_xpath('/publicObject/oai_dc:dc', 'oai_dc' => 'http://www.openarchives.org/OAI/2.0/oai_dc/')).to be - end - - it 'relationships' do - ns = { - 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', - 'hydra' => 'http://projecthydra.org/ns/relations#', - 'fedora' => 'info:fedora/fedora-system:def/relations-external#', - 'fedora-model' => 'info:fedora/fedora-system:def/model#' - } - expect(public_xml.at_xpath('/publicObject/rdf:RDF', ns)).to be - expect(public_xml.at_xpath('/publicObject/rdf:RDF/rdf:Description/fedora:isMemberOf', ns)).to be - expect(public_xml.at_xpath('/publicObject/rdf:RDF/rdf:Description/fedora:isMemberOfCollection', ns)).to be - expect(public_xml.at_xpath('/publicObject/rdf:RDF/rdf:Description/fedora:isConstituentOf', ns)).to be - expect(public_xml.at_xpath('/publicObject/rdf:RDF/rdf:Description/fedora-model:hasModel', ns)).not_to be - expect(public_xml.at_xpath('/publicObject/rdf:RDF/rdf:Description/hydra:isGovernedBy', ns)).not_to be - end - - it 'clones of the content of the other datastreams, keeping the originals in tact' do - expect(@item.datastreams['identityMetadata'].ng_xml.at_xpath('/identityMetadata')).to be - expect(@item.datastreams['contentMetadata'].ng_xml.at_xpath('/contentMetadata')).to be - expect(@item.datastreams['rightsMetadata'].ng_xml.at_xpath('/rightsMetadata')).to be - expect(@item.datastreams['RELS-EXT'].content).to be_equivalent_to @rels - end - - it 'does not add a thumb node if no thumb is present' do - expect(public_xml.at_xpath('/publicObject/thumb')).not_to be - end - - it 'include a thumb node if a thumb is present' do - @item.contentMetadata.content = <<-XML - - - - - - - - - - XML - p_xml = Nokogiri::XML(@item.public_xml) - expect(p_xml.at_xpath('/publicObject/thumb').to_xml).to be_equivalent_to('ab123cd4567/ab123cd4567_05_0002.jp2') - end - - it 'includes releaseData element from release tags' do - releases = public_xml.xpath('/publicObject/releaseData/release') - expect(releases.map(&:inner_text)).to eq %w[true true] - expect(releases.map{ |r| r['to'] }).to eq %w[Searchworks Some_special_place] - end - - it 'include a releaseData element when there is content inside it, but does not include this release data in identityMetadata' do - allow(@item).to receive(:released_for).and_return('' => { 'release' => 'foo' }) - p_xml = Nokogiri::XML(@item.public_xml) - expect(p_xml.at_xpath('/publicObject/releaseData/release').inner_text).to eq 'foo' - expect(p_xml.at_xpath('/publicObject/identityMetadata/release')).to be_nil - end - end - - context 'with a collection' do - let(:public_xml) { Nokogiri::XML(@item.public_xml) } - before(:each) do - @now = Time.now.utc - allow(Time).to receive(:now).and_return(@now) - end - - it 'publishes the expected datastreams' do - expect(public_xml.at_xpath('/publicObject/identityMetadata')).to be - expect(public_xml.at_xpath('/publicObject/rightsMetadata')).to be - expect(public_xml.at_xpath('/publicObject/mods:mods', 'mods' => 'http://www.loc.gov/mods/v3')).to be - expect(public_xml.at_xpath('/publicObject/rdf:RDF', 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')).to be - expect(public_xml.at_xpath('/publicObject/oai_dc:dc', 'oai_dc' => 'http://www.openarchives.org/OAI/2.0/oai_dc/')).to be - end - end - - describe '#public_xml' do - it 'handles externalFile references' do - correctPublicContentMetadata = Nokogiri::XML(read_fixture('hj097bm8879_publicObject.xml')).at_xpath('/publicObject/contentMetadata').to_xml - @item.contentMetadata.content = read_fixture('hj097bm8879_contentMetadata.xml') - - cover_item = instantiate_fixture('druid:cg767mn6478', Dor::Item) - allow(Dor).to receive(:find).with(cover_item.pid).and_return(cover_item) - title_item = instantiate_fixture('druid:jw923xn5254', Dor::Item) - allow(Dor).to receive(:find).with(title_item.pid).and_return(title_item) - - # generate publicObject XML and verify that the content metadata portion is correct and the correct thumb is present - public_xml = @item.public_xml - expect(Nokogiri::XML(public_xml).at_xpath('/publicObject/contentMetadata').to_xml).to be_equivalent_to(correctPublicContentMetadata) - expect(Nokogiri::XML(public_xml).at_xpath('/publicObject/thumb').to_xml).to be_equivalent_to('jw923xn5254/2542B.jp2') - end + it 'delegates to PublicXmlService' do + expect(Deprecation).to receive(:warn) + expect_any_instance_of(Dor::PublicXmlService).to receive(:to_xml) + item.public_xml end + end - describe '#publish_metadata' do - it 'calls the service' do - expect(Deprecation).to receive(:warn) - expect(Dor::PublishMetadataService).to receive(:publish).with(@item) - @item.publish_metadata - end + describe '#publish_metadata' do + it 'calls the service' do + expect(Deprecation).to receive(:warn) + expect(Dor::PublishMetadataService).to receive(:publish).with(item) + item.publish_metadata end end @@ -391,7 +184,7 @@ class ItemizableItem < ActiveFedora::Base end it 'hits the correct url' do expect(Deprecation).to receive(:warn) - expect(@item.publish_metadata_remotely).to be true + expect(item.publish_metadata_remotely).to be true end end end diff --git a/spec/services/public_xml_service_spec.rb b/spec/services/public_xml_service_spec.rb new file mode 100644 index 00000000..ead25ed2 --- /dev/null +++ b/spec/services/public_xml_service_spec.rb @@ -0,0 +1,216 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Dor::PublicXmlService do + let(:item) { instantiate_fixture('druid:ab123cd4567', Dor::Item) } + + subject(:service) { described_class.new(item) } + + describe '#to_xml' do + subject(:xml) { service.to_xml } + + after { unstub_config } + + let(:rels) do + <<-EOXML + + + + + + + + + + EOXML + end + + before do + stub_config + Dor.configure do + stacks do + host 'stacks.stanford.edu' + end + end + mods = <<-EOXML + + druid:ab123cd4567 + + EOXML + + rights = <<-EOXML + + + (c) Copyright 2010 by Sebastian Jeremias Osterfeld + + + + + stanford:stanford + + + + by-sa + CC Attribution Share Alike license + + + EOXML + + item.contentMetadata.content = '' + item.descMetadata.content = mods + item.rightsMetadata.content = rights + item.rels_ext.content = rels + allow_any_instance_of(Dor::PublicDescMetadataService).to receive(:ng_xml).and_return(Nokogiri::XML(mods)) # calls Item.find and not needed in general tests + allow(OpenURI).to receive(:open_uri).with('https://purl-test.stanford.edu/ab123cd4567.xml').and_return('') + WebMock.disable_net_connect! + end + let(:ng_xml) { Nokogiri::XML(xml) } + + context 'when there are no release tags' do + before do + expect(item).to receive(:released_for).and_return({}) + end + + it 'does not include a releaseData element and any info in identityMetadata' do + expect(ng_xml.at_xpath('/publicObject/releaseData')).to be_nil + expect(ng_xml.at_xpath('/publicObject/identityMetadata/release')).to be_nil + end + end + + context 'produces xml with' do + let(:now) { Time.now.utc } + before do + allow(Time).to receive(:now).and_return(now) + end + + it 'an encoding of UTF-8' do + expect(ng_xml.encoding).to match(/UTF-8/) + end + it 'an id attribute' do + expect(ng_xml.at_xpath('/publicObject/@id').value).to match(/^druid:ab123cd4567/) + end + it 'a published attribute' do + expect(ng_xml.at_xpath('/publicObject/@published').value).to eq(now.xmlschema) + end + it 'a published version' do + expect(ng_xml.at_xpath('/publicObject/@publishVersion').value).to eq('dor-services/' + Dor::VERSION) + end + it 'identityMetadata' do + expect(ng_xml.at_xpath('/publicObject/identityMetadata')).to be + end + it 'no contentMetadata element' do + expect(ng_xml.at_xpath('/publicObject/contentMetadata')).not_to be + end + + describe 'with contentMetadata present' do + before do + item.contentMetadata.content = <<-XML + + + + + + + XML + end + it 'include contentMetadata' do + expect(ng_xml.at_xpath('/publicObject/contentMetadata')).to be + end + end + + it 'rightsMetadata' do + expect(ng_xml.at_xpath('/publicObject/rightsMetadata')).to be + end + it 'generated mods' do + expect(ng_xml.at_xpath('/publicObject/mods:mods', 'mods' => 'http://www.loc.gov/mods/v3')).to be + end + + it 'generated dublin core' do + expect(ng_xml.at_xpath('/publicObject/oai_dc:dc', 'oai_dc' => 'http://www.openarchives.org/OAI/2.0/oai_dc/')).to be + end + + it 'relationships' do + ns = { + 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', + 'hydra' => 'http://projecthydra.org/ns/relations#', + 'fedora' => 'info:fedora/fedora-system:def/relations-external#', + 'fedora-model' => 'info:fedora/fedora-system:def/model#' + } + expect(ng_xml.at_xpath('/publicObject/rdf:RDF', ns)).to be + expect(ng_xml.at_xpath('/publicObject/rdf:RDF/rdf:Description/fedora:isMemberOf', ns)).to be + expect(ng_xml.at_xpath('/publicObject/rdf:RDF/rdf:Description/fedora:isMemberOfCollection', ns)).to be + expect(ng_xml.at_xpath('/publicObject/rdf:RDF/rdf:Description/fedora:isConstituentOf', ns)).to be + expect(ng_xml.at_xpath('/publicObject/rdf:RDF/rdf:Description/fedora-model:hasModel', ns)).not_to be + expect(ng_xml.at_xpath('/publicObject/rdf:RDF/rdf:Description/hydra:isGovernedBy', ns)).not_to be + end + + it 'clones of the content of the other datastreams, keeping the originals in tact' do + expect(item.datastreams['identityMetadata'].ng_xml.at_xpath('/identityMetadata')).to be + expect(item.datastreams['contentMetadata'].ng_xml.at_xpath('/contentMetadata')).to be + expect(item.datastreams['rightsMetadata'].ng_xml.at_xpath('/rightsMetadata')).to be + expect(item.datastreams['RELS-EXT'].content).to be_equivalent_to rels + end + + it 'does not add a thumb node if no thumb is present' do + expect(ng_xml.at_xpath('/publicObject/thumb')).not_to be + end + + it 'include a thumb node if a thumb is present' do + item.contentMetadata.content = <<-XML + + + + + + + + + + XML + expect(ng_xml.at_xpath('/publicObject/thumb').to_xml).to be_equivalent_to('ab123cd4567/ab123cd4567_05_0002.jp2') + end + + it 'includes releaseData element from release tags' do + releases = ng_xml.xpath('/publicObject/releaseData/release') + expect(releases.map(&:inner_text)).to eq %w[true true] + expect(releases.map{ |r| r['to'] }).to eq %w[Searchworks Some_special_place] + end + + it 'include a releaseData element when there is content inside it, but does not include this release data in identityMetadata' do + allow(item).to receive(:released_for).and_return('' => { 'release' => 'foo' }) + expect(ng_xml.at_xpath('/publicObject/releaseData/release').inner_text).to eq 'foo' + expect(ng_xml.at_xpath('/publicObject/identityMetadata/release')).to be_nil + end + end + + context 'with a collection' do + it 'publishes the expected datastreams' do + expect(ng_xml.at_xpath('/publicObject/identityMetadata')).to be + expect(ng_xml.at_xpath('/publicObject/rightsMetadata')).to be + expect(ng_xml.at_xpath('/publicObject/mods:mods', 'mods' => 'http://www.loc.gov/mods/v3')).to be + expect(ng_xml.at_xpath('/publicObject/rdf:RDF', 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')).to be + expect(ng_xml.at_xpath('/publicObject/oai_dc:dc', 'oai_dc' => 'http://www.openarchives.org/OAI/2.0/oai_dc/')).to be + end + end + + describe '#public_xml' do + it 'handles externalFile references' do + correct_content_md = Nokogiri::XML(read_fixture('hj097bm8879_publicObject.xml')).at_xpath('/publicObject/contentMetadata').to_xml + item.contentMetadata.content = read_fixture('hj097bm8879_contentMetadata.xml') + + cover_item = instantiate_fixture('druid:cg767mn6478', Dor::Item) + allow(Dor).to receive(:find).with(cover_item.pid).and_return(cover_item) + title_item = instantiate_fixture('druid:jw923xn5254', Dor::Item) + allow(Dor).to receive(:find).with(title_item.pid).and_return(title_item) + + # generate publicObject XML and verify that the content metadata portion is correct and the correct thumb is present + expect(ng_xml.at_xpath('/publicObject/contentMetadata').to_xml).to be_equivalent_to(correct_content_md) + expect(ng_xml.at_xpath('/publicObject/thumb').to_xml).to be_equivalent_to('jw923xn5254/2542B.jp2') + end + end + end +end