Skip to content

Commit

Permalink
Merge pull request #38 from sul-dlss/add_apo_to_collections
Browse files Browse the repository at this point in the history
Add apo to collections
  • Loading branch information
justinlittman authored Jan 30, 2020
2 parents 18572db + c5cf119 commit 05d20ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/cocina/models/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ def self.from_dynamic(_dyn)
# Subschema for administrative concerns
class Administrative < Dry::Struct
attribute :releaseTags, Types::Strict::Array.of(ReleaseTag).meta(omittable: true)
# Allowing hasAdminPolicy to be omittable for now (until rolled out to consumers),
# but I think it's actually required for every DRO
attribute :hasAdminPolicy, Types::Coercible::String.optional.default(nil)

def self.from_dynamic(dyn)
params = {}
params[:releaseTags] = dyn['releaseTags'].map { |rt| ReleaseTag.from_dynamic(rt) } if dyn['releaseTags']
params[:hasAdminPolicy] = dyn['hasAdminPolicy']
Administrative.new(params)
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/cocina/models/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
access: {
},
administrative: {
hasAdminPolicy: 'druid:mx123cd4567',
releaseTags: [
{
who: 'Justin',
Expand All @@ -84,6 +85,7 @@
expect(collection.type).to eq collection_type
expect(collection.label).to eq 'My collection'

expect(collection.administrative.hasAdminPolicy).to eq 'druid:mx123cd4567'
expect(collection.administrative.releaseTags).to all(be_kind_of(Cocina::Models::ReleaseTag))
tag = collection.administrative.releaseTags.first
expect(tag.date).to eq DateTime.parse '2018-11-23T00:44:52Z'
Expand Down Expand Up @@ -153,6 +155,7 @@
"access": {
},
"administrative": {
"hasAdminPolicy":"druid:mx123cd4567",
"releaseTags": [
{
"who":"Justin",
Expand All @@ -178,6 +181,9 @@
expect(collection.attributes).to include(externalIdentifier: 'druid:12343234',
label: 'my collection',
type: collection_type)

expect(collection.administrative.hasAdminPolicy).to eq 'druid:mx123cd4567'

tags = collection.administrative.releaseTags
expect(tags).to all(be_instance_of Cocina::Models::ReleaseTag)
end
Expand Down

0 comments on commit 05d20ee

Please sign in to comment.