Skip to content

Instantly share code, notes, and snippets.

@flyingzumwalt
Last active December 17, 2015 09:29
Show Gist options
  • Save flyingzumwalt/5588067 to your computer and use it in GitHub Desktop.
Save flyingzumwalt/5588067 to your computer and use it in GitHub Desktop.
Sample Test for behavior of Mads::List
require 'spec_helper'
describe MadsDatastream::List do
before do
@complexSubject = MadsComplexSubject.new pid: "zzXXXXXXX1"
end
# subject is a MadsDatastream::List retrieved from calling elementList MadsComplexSubject object. elementList returns an Array of MadsDatastream::List objects.
# subject returns the first MadsDatastream::List object from that Array
subject do
return @complexSubject.elementList.first
end
it "should work with update_attributes" do
# Need to decide between these:
# Option 1: Less repetitive, assumes elements grouped by type
params = {elementList: {temporalElement: ["xy", "yz"], topicElement:["ab", "bc"]}}
# Option 2: More repetitive, more literal reflection of "ordered list" model. Allows mixing types within order (ie. temporal then topic then another temporal)
params = {elementList: [{temporalElement:"xy"}, {temporalElement:"yz"}, {topicElement:"ab"}, {topicElement:"bc"}]}
@complexSubject.update_attributes(params)
end
it "should allow direct manipulation of its list elements" do
# This is how it currently works. Requires a lot of work to insert/update values, but it works.
temporalElement = MadsDatastream::List::TemporalElement.new(elementList.first.graph)
temporalElement.elementValue = "17th Century"
subject[0] = temporalElement
subject.graph.dump(:rdfxml).should == "... etc ..."
end
it "should allow generic access to all elements in the list, while also allowing variation of RDF Node Type" do
subject.temporalElement << "17th Centry"
classnames = ["TopicElement", "TemporalElement", "OccupationElement", "GeographicElement", "GenreFormElement", "TermsOfAddressNameElement", "NameElement", "DateNameElement"
"GivenNameElement", "FamilyNameElement", "FullNameElement"]
# Use the downcased type name for each RDF type to set the values
classnames.each do |classname|
downcased_classname = classname[0,1].downcase + classname[1..-1]
subject.send(downcased_classname.to_sym) << "Sample Value for #{classname}"
end
subject.size.should == classnames.list
# Make sure that the values were set, accessing them using the generic `element` method that returns all elements in the list.
classnames.each_with_index do |classname, index|
downcased_classname = classname[0,1].downcase + classname[1..-1]
full_classname = "MadsDatastream::List::"+classname
subject.element[index].should be_kind_of full_classname.constantize
subject.element[index].first.elementValue.should == "Sample Value for #{classname}"
subject.send(downcased_classname.to_sym).should == subject.element[index].first
end
end
# Using TemporalElement as example here. The same behaviors should apply for all of the Element classes defined for this list
describe "temporalElement" do
it "should automatically build entries when empty" do
subject.temporalElement.first.should be_nil
subject.temporalElement.first = "16th Centry"
subject.temporalElement.first.class.should == MadsDatastream::List::TemporalElement
subject.temporalElement.first.elementValue.should == "16th Century"
end
it "should support array insertion operator" do
subject.temporalElement << "16th Centry"
subject.temporalElement << "17th Centry"
subject.temporalElement[0].elementValue.should == "16th Century"
subject.temporalElement[1].elementValue.should == "17th Century"
end
it "should allow access to the elementValues within temporalElements" do
subject.temporalElement.first = "Blah"
subject.temporalElement.first.elementValue.should == "Blah"
subject.temporalElement.first.elementValue = "Blargh."
subject.temporalElement.first.elementValue.should == "Blargh."
end
end
it "should build rdf graph" do
subject.temporalElement.first = "16th Centry"
subject.temporalElement << "17th Centry"
subject.geographicElement = "Australia"
subject.geographicElement << "Papua New Guinea"
xml =<<END
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:mads="http://www.loc.gov/mads/rdf/v1#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:dams="http://library.ucsd.edu/ontology/dams#">
<mads:ComplexSubject rdf:about="http://library.ucsd.edu/ark:/20775/zzXXXXXXX1">
<mads:elementList rdf:parseType="Collection">
<mads:TemporalElement>
<mads:elementValue>16th century</mads:elementValue>
</mads:TemporalElement>
<mads:TemporalElement>
<mads:elementValue>17th century</mads:elementValue>
</mads:TemporalElement>
<mads:GeographicElement>
<mads:elementValue>Australia</mads:elementValue>
</mads:GeographicElement>
<mads:GeographicElement>
<mads:elementValue>Papua New Guinea</mads:elementValue>
</mads:GeographicElement>
</mads:elementList>
</mads:ComplexSubject>
</rdf:RDF>
END
subject.first.graph.dump(:rdfxml).should be_equivalent_to xml
end
end

##Simple Subject

BuiltWorkPlace
CulturalContext
Function
GenreForm
Geographic
Iconography
ScientificName
StylePeriod
Technique
Temporal
Topic

##Subject Name

Name
ConferenceName
CorporateName
FamilyName
PersonalName

Subject Name SubElements

NameElement
DateNameElement
FamilyNameElement
FullNameElement
GivenNameElement
TermsOfAddressNameElement

Complex Subject

Simple Subjects or Subject Names

Supporting Lists in MADS RDF in the DAMS Hydra Head

Behaviors to Satisfy

  • Lists may have various types of elements within them
  • each List Element is a wrapper around its elementValue

We want to support this while keeping the api simple & readable.

We also need to be able to manipulate these lists in HTML forms then submit the changes through HTTP POST parameters.

Notes

This is a sample of test coverage. Before implementing this, we should make sure we've designed the API properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment