Skip to content

Instantly share code, notes, and snippets.

@ebenenglish
Last active January 30, 2018 15:28
Show Gist options
  • Save ebenenglish/98dfb01a1a960b18b4b9c971d5600b88 to your computer and use it in GitHub Desktop.
Save ebenenglish/98dfb01a1a960b18b4b9c971d5600b88 to your computer and use it in GitHub Desktop.
Newspaper models acceptance testing criteria.

Newspaper Models Acceptance Testing

(For the sake of brevity, not all classes and metadata fields appear in the console examples.)

Classes ✅

There should be 6 classes:

  • NewspaperTitle (PCDM Object)
  • NewspaperContainer (PCDM Object)
  • NewspaperIssue (PCDM Object)
  • NewspaperPage (PCDM FileSet)
  • NewspaperArticle (PCDM Object)
  • NewspaperArticleFileSet (PCDM FileSet)

Create ✅

For each model, I should be able to call .new and create a new instance of the class.

irb(main)> title = NewspaperTitle.new
=> #<NewspaperTitle id: nil, title: [], ... >

irb(main)> title.class
=> NewspaperTitle

irb(main)> issue = NewspaperIssue.new
=> #<NewspaperIssue id: nil, title: [], ... >

irb(main)> page = NewspaperPage.new
=> #<NewspaperPage id: nil, title: [], ... >

Save ❌

For each model, I should be able to call .save and persist the object in Fedora and Solr. (This should return false unless the required attributes are set.)

⚠️

Calling .save for Page and ArticleFileSet objects is failing with this error:

SystemStackError: stack level too deep

irb(main)> title.save
=> false

irb(main)> title.title = ["Foo"] # assuming title is required
=> ["Foo"]

irb(main)> title.save # id gets automatically generated
=> #<NewspaperTitle id: "abc123", title: ["Foo"], ... >

PCDM Mixins ✅

Each model should mix in the correct PCDM model class.

irb(main)> title.pcdm_object?
=> true

irb(main)> title.work?
=> true

irb(main)> title.pcdm_collection?
=> false

irb(main)> issue.pcdm_object?
=> true

irb(main)> page.file_set?
=> true

irb(main)> page.work?
=> false

Relationship Creation and Persistence ❎

Properly created relationships should be persisted.

⚠️

OK for title->issue relationships, can't fully test until .save is working for NewspaperPage objects.

# title->issue relationship
irb(main)> title.members = [issue]
=> [#<NewspaperIssue id: "def456", ... >]

irb(main)> title.save
=> true

irb(main)> title.member_ids
=> ["def456"]

irb(main)> title.members
=> [#<NewspaperIssue id: "def456", ... >]

irb(main)> issue.member_of
=> [#<NewspaperTitle id: "abc123" ... >]

# object->fileset relationship
# (default Hyrax parent->child direction OK for now)
irb(main)> issue.members = [page]
=> [#<NewspaperPage id: "ghi789", ... >]

irb(main)> issue.save
=> true

irb(main)> issue.members
=> [#<NewspaperPage id: "ghi789", ... >]

irb(main)> issue.member_ids
=> ["ghi789"]

irb(main)> issue.file_sets
=> [#<NewspaperPage id: "ghi789", ... >]

irb(main)> issue.file_set_ids
=> ["ghi789"]

irb(main)> page.member_of
=> [#<NewspaperIssue id: "def456", ... >]

irb(main)> page.parent
=> [#<NewspaperIssue id: "def456", ... >]

Relationship persistence for PCDM Object models should be reflected in Fedora and Solr.

NewspaperTitle

Fedora:

pcdm:hasMember http://localhost:8984/rest/dev/de/f4/56/def456  # child issue URI

Solr:

member_ids_ssim":["def456"]  # issue child id
NewspaperIssue

Fedora:

pcdm:hasMember http://localhost:8984/rest/dev/gh/i7/89/ghi789  # child file set URI

Solr:

member_ids_ssim":["ghi789"]                 # file set child id
file_set_ids_ssim":["ghi789"]               # file set child id

Metadata ✅

Each model class should have methods and attributes for the appropriate metadata fields defined in the Metadata Profile

For each field, multiple and required properties should be defined, and the correct predicate URI should be used.

⚠️

Seems good for the metadata attributes that have been implemented so far.

irb(main)> NewspaperTitle.properties
=> {"issn"=>#<ActiveTriples::NodeConfig:0x0000000396d810 @term=:issn, @predicate=#<RDF::URI:0x1cbe728 URI:http://id.loc.gov/vocabulary/identifiers/issn>, @class_name=nil, @cast=true, @opts={:multiple=>false}, @type=:string, @behaviors=[:stored_searchable] @multiple=false>, "publisher"=>#<ActiveFedora::Attributes::NodeConfig:0x0000000a57a238 @term=:publisher, @predicate=#<RDF::URI:0x26e9270 URI:http://purl.org/dc/elements/1.1/publisher>, @class_name=nil, @cast=true, @opts={:multiple=>true}, @multiple=true> ... }

irb(main)> NewspaperTitle.properties["issn"].predicate.to_s
=> "http://id.loc.gov/vocabulary/identifiers/issn"

irb(main)> NewspaperTitle.fields.include?(:issn)
=> true

irb(main)> title.attributes.include?("issn")
=> true

irb(main)> title.has_attribute?("publisher")
=> true

irb(main)> title.issn = "1234-5678"
=> "1234-5678"

irb(main)> title.issn
=> "1234-5678"

# attempting to assign a string to a multivalued field should return an error
irb(main)> title.publisher = "Charles Foster Kane"
ArgumentError: You attempted to set the property `publisher' to a scalar value. However, this property is declared as being multivalued.

irb(main)> title.publisher = ["Charles Foster Kane"]
=> ["Charles Foster Kane"]

Metadata values should be persisted on save.

irb(main)> title.publisher = ["Charles Foster Kane"]
=> ["Charles Foster Kane"]

irb(main)> title.save
=> true

irb(main)> title.publisher
=> ["Charles Foster Kane"]

Delete ⭕

For each model, I should be able to call .delete and delete the object. Question: should deletion of parents also delete children?

⚠️

Need .save working before this can be fully tested.

irb(main)> issue.delete
=> [#<NewspaperIssue id: "def456", ... >]

irb(main)> page.member_of
=> []

irb(main)> page.parent
=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment