Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #345 from sul-dlss/combinable-items
Combinable items
- Loading branch information
Showing
5 changed files
with
61 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
# Clears the contentMetadata datastream to the default, wiping out any members. | ||
# item MUST allow modification, or save! will raise error | ||
class ResetContentMetadataService | ||
def initialize(druid:, type: 'image') | ||
@druid = druid | ||
def initialize(item:, type: 'image') | ||
@item = item | ||
@type = type | ||
end | ||
|
||
def reset | ||
work = ItemQueryService.find_modifiable_item(@druid) | ||
work.contentMetadata.content = "<contentMetadata objectId='#{work.id}' type='#{@type}'/>" | ||
work.save! | ||
@item.contentMetadata.content = "<contentMetadata objectId='#{@item.id}' type='#{@type}'/>" | ||
@item.save! | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe ItemQueryService do | ||
subject(:service) { described_class } | ||
|
||
let(:druid) { 'ab123cd4567' } | ||
let(:item) { instantiate_fixture('druid:ab123cd4567', Dor::Item) } | ||
|
||
before do | ||
allow(Dor::Item).to receive(:find).and_return(item) | ||
end | ||
|
||
describe '.find_combinable_item' do | ||
it 'raises error if object does not allow modification' do | ||
allow(item).to receive(:allows_modification?).and_return(false) | ||
expect { service.find_combinable_item('ab123cd4567') }.to raise_error(RuntimeError, 'Item druid:ab123cd4567 is not open for modification') | ||
end | ||
it 'raises error if object is dark' do | ||
dra = instance_double(Dor::RightsAuth, dark?: true, citation_only?: false) | ||
rights_ds = instance_double(Dor::RightsMetadataDS, dra_object: dra) | ||
allow(item).to receive(:rightsMetadata).and_return(rights_ds) | ||
allow(item).to receive(:allows_modification?).and_return(true) | ||
expect { service.find_combinable_item('ab123cd4567') }.to raise_error(RuntimeError, 'Item druid:ab123cd4567 is dark') | ||
end | ||
it 'raises error if object is citation_only' do | ||
dra = instance_double(Dor::RightsAuth, dark?: false, citation_only?: true) | ||
rights_ds = instance_double(Dor::RightsMetadataDS, dra_object: dra) | ||
allow(item).to receive(:rightsMetadata).and_return(rights_ds) | ||
allow(item).to receive(:allows_modification?).and_return(true) | ||
expect { service.find_combinable_item('ab123cd4567') }.to raise_error(RuntimeError, 'Item druid:ab123cd4567 is citation_only') | ||
end | ||
it 'returns item otherwise' do | ||
dra = instance_double(Dor::RightsAuth, dark?: false, citation_only?: false) | ||
rights_ds = instance_double(Dor::RightsMetadataDS, dra_object: dra) | ||
allow(item).to receive(:rightsMetadata).and_return(rights_ds) | ||
allow(item).to receive(:allows_modification?).and_return(true) | ||
service.find_combinable_item('ab123cd4567') | ||
end | ||
end | ||
end |