Skip to content

Commit

Permalink
constituent_service checks parent and child objects for not dark or c…
Browse files Browse the repository at this point in the history
…itation_only
  • Loading branch information
ndushay committed Aug 27, 2019
1 parent b3f9d99 commit 6b47ce6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/services/constituent_service.rb
Expand Up @@ -16,7 +16,7 @@ def initialize(parent_druid:)
# subsequent calls will erase the previous changes.
# @param [Array<String>] 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)
Expand All @@ -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
Expand All @@ -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
13 changes: 7 additions & 6 deletions spec/services/constituent_service_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 6b47ce6

Please sign in to comment.