From 6b47ce696a810bdad9e59b8eb9c93a1c3bdb55f9 Mon Sep 17 00:00:00 2001 From: Naomi Dushay Date: Tue, 27 Aug 2019 15:00:51 -0700 Subject: [PATCH] constituent_service checks parent and child objects for not dark or citation_only --- app/services/constituent_service.rb | 6 +++--- spec/services/constituent_service_spec.rb | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/services/constituent_service.rb b/app/services/constituent_service.rb index 00deba1ee2..7f656a7f8d 100644 --- a/app/services/constituent_service.rb +++ b/app/services/constituent_service.rb @@ -16,7 +16,7 @@ def initialize(parent_druid:) # subsequent calls will erase the previous changes. # @param [Array] child_druids the identifiers of the child objects def add(child_druids:) - ResetContentMetadataService.new(druid: parent_druid).reset + ResetContentMetadataService.new(druid: parent_druid).reset if parent # ensures parent is combinable child_druids.each do |child_druid| add_constituent(child_druid: child_druid) @@ -29,7 +29,7 @@ def add(child_druids:) attr_reader :parent_druid def add_constituent(child_druid:) - child = ItemQueryService.find_modifiable_item(child_druid) + child = ItemQueryService.find_combinable_item(child_druid) child.contentMetadata.ng_xml.search('//resource').each do |resource| parent.contentMetadata.add_virtual_resource(child.id, resource) end @@ -38,6 +38,6 @@ def add_constituent(child_druid:) end def parent - @parent ||= ItemQueryService.find_modifiable_item(parent_druid) + @parent ||= ItemQueryService.find_combinable_item(parent_druid) end end diff --git a/spec/services/constituent_service_spec.rb b/spec/services/constituent_service_spec.rb index 6940eec082..1cedc398fd 100644 --- a/spec/services/constituent_service_spec.rb +++ b/spec/services/constituent_service_spec.rb @@ -59,9 +59,10 @@ # Used in ContentMetadataDS#add_virtual_resource allow(parent.contentMetadata).to receive(:pid).and_return('druid:parent1') + allow(ItemQueryService).to receive(:find_combinable_item).with('druid:parent1').and_return(parent) allow(ItemQueryService).to receive(:find_modifiable_item).with('druid:parent1').and_return(parent) - allow(ItemQueryService).to receive(:find_modifiable_item).with('druid:child1').and_return(child1) - allow(ItemQueryService).to receive(:find_modifiable_item).with('druid:child2').and_return(child2) + allow(ItemQueryService).to receive(:find_combinable_item).with('druid:child1').and_return(child1) + allow(ItemQueryService).to receive(:find_combinable_item).with('druid:child2').and_return(child2) allow(Dor::Services::Client).to receive(:object).and_return(client) end @@ -88,9 +89,9 @@ end end - context 'when the parent is closed for modification' do + context 'when the parent is not combinable' do before do - allow(ItemQueryService).to receive(:find_modifiable_item).with(parent.id).and_raise('nope') + allow(ItemQueryService).to receive(:find_combinable_item).with(parent.id).and_raise('nope') end it 'merges nothing' do @@ -100,9 +101,9 @@ end end - context 'when the child is closed for modification' do + context 'when a child is not combinable' do before do - allow(ItemQueryService).to receive(:find_modifiable_item).with(child2.id).and_raise('not modifiable') + allow(ItemQueryService).to receive(:find_combinable_item).with(child2.id).and_raise('not modifiable') end it 'merges all the chidren before an error is encountered' do