Skip to content

Commit

Permalink
Merge pull request #4896 from sul-dlss/fix-remove-release-tags-migrator
Browse files Browse the repository at this point in the history
Make RemoveReleaseTags migrator a little smarter
  • Loading branch information
jcoyne authored Apr 17, 2024
2 parents 8301cbc + e9f2c4b commit 6de07a0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/services/migrators/remove_release_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ module Migrators
# Migrator that will be used to remove release tags.
class RemoveReleaseTags < Base
def migrate?
(ar_cocina_object.is_a?(Dro) || ar_cocina_object.is_a?(Collection)) && ar_cocina_object.administrative.key?('releaseTags')
(ar_cocina_object.is_a?(Dro) || ar_cocina_object.is_a?(Collection)) &&
ar_cocina_object.administrative.key?('releaseTags') &&
ar_cocina_object.administrative.fetch('releaseTags').present?
end

def migrate
Expand Down
31 changes: 27 additions & 4 deletions spec/services/migrators/remove_release_tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,45 @@
subject(:migrator) { described_class.new(ar_cocina_object) }

let(:ar_cocina_object) { create(:ar_dro) }
let(:tags) do
[
{
who: 'mjg',
what: 'self',
date: '2021-12-28T00:09:00.000+00:00',
to: 'Earthworks',
release: true
}
]
end

describe '#migrate?' do
subject { migrator.migrate? }

context 'when a dro' do
let(:ar_cocina_object) { create(:ar_dro, administrative: { hasAdminPolicy: 'druid:hy787xj5878', releaseTags: [] }) }
context 'when a dro with tags' do
let(:ar_cocina_object) { create(:ar_dro, administrative: { hasAdminPolicy: 'druid:hy787xj5878', releaseTags: tags }) }

it { is_expected.to be true }
end

context 'when a collection' do
let(:ar_cocina_object) { create(:ar_collection, administrative: { hasAdminPolicy: 'druid:hy787xj5878', releaseTags: [] }) }
context 'when a collection with tags' do
let(:ar_cocina_object) { create(:ar_collection, administrative: { hasAdminPolicy: 'druid:hy787xj5878', releaseTags: tags }) }

it { is_expected.to be true }
end

context 'when a dro without tags' do
let(:ar_cocina_object) { create(:ar_dro, administrative: { hasAdminPolicy: 'druid:hy787xj5878', releaseTags: [] }) }

it { is_expected.to be false }
end

context 'when a collection without tags' do
let(:ar_cocina_object) { create(:ar_collection, administrative: { hasAdminPolicy: 'druid:hy787xj5878', releaseTags: [] }) }

it { is_expected.to be false }
end

context 'when an APO' do
let(:ar_cocina_object) { create(:ar_admin_policy) }

Expand Down

0 comments on commit 6de07a0

Please sign in to comment.