Skip to content

Instantly share code, notes, and snippets.

@flyingzumwalt
Last active December 17, 2015 12:59
Show Gist options
  • Save flyingzumwalt/5613587 to your computer and use it in GitHub Desktop.
Save flyingzumwalt/5613587 to your computer and use it in GitHub Desktop.
Aspirational representation of how redesigned ActiveFedora::RDFNode would work.
describe "DamsResource" do
describe "MADS accessors" do
before do
params = {
myResource: {
topic: "Cosmology",
temporal: "16th Century",
personalName: {
fullName: "Jefferson, Thomas",
dateName: "1743-1826"
},
personalName: {
fullName: "Hemings, Sally",
},
corporateName: {
name: "University of California, San Diego.",
name: "University Library",
},
complexSubject: {
personalName: {
fullName: "Jeffersion, Thomas",
dateName: "1743-1826"
},
topic: "Presidency",
temporal: "1801-1809"
},
}
}
@resource = DamsResource.new()
@resource.update_attributes(params[:myResource])
end
it "should support topic, temporal" do
# TopicElement
@resource.topic.should == ["Cosmology"]
# OR ??? @resource.topic.should == ["Cosmology", "Presidency"] ???
# TemporalElement
@resource.temporal.should == ["16th Century"]
# OR ??? @resource.temporal.should == ["16th Century", "1801-1809"] ???
end
describe "personalName" do
it "should support MADS.PersonalName structures" do
@resource.personalName(0).fullName.should == ["Jefferson, Thomas"]
@resource.personalName(0).fullName(0).elementValue.should == "Jefferson, Thomas"
@resource.personalName(0).dateName.should == ["1743-1826"]
@resource.personalName(1).fullName.should == ["Hemings, Sally"]
end
it "should aggregate subelement values in authoritativeLabel" do
@resource.personalName.should == ["Jefferson, Thomas, 1743-1826", "Hemings, Sally"]
@resource.personalName(0).authoritativeLabel.should == "Jefferson, Thomas, 1743-1826"
end
it "Insertion Operator `<<` when given a String should create a PersonalNameElement and put the string into its FullNameElement" do
@resource.personalName << "Jefferson Randolph, Martha"
@resource.personalName.should == ["Jefferson, Thomas, 1743-1826", "Hemings, Sally", "Jefferson Randolph, Martha"]
@resource.personalName(1).fullName.should == ["Jefferson Randolph, Martha"]
end
it "Insertion Operator `<<` when given a Node should simply insert it" do
new_name = MADS::PersonalName.new(@resource.graph)
new_name.fullName = "Callender, James T."
new_name.dateName = "1802"
@resource.personalName << new_name
@resource.personalName(1).authoritativeLabel.should == "Callender, James T., 1802"
@resource.personalName(1).fullName.should == ["Callender, James T."]
@resource.personalName(1).dateName.should == ["1802"]
end
it "Insertion Operator `<<` when given a Hash should use update_attributes behavior" do
@resource.personalName << {fullName:"Callender, James T.", dateName: "1802"}
@resource.personalName(1).authoritativeLabel.should == "Callender, James T., 1802"
@resource.personalName(1).fullName.should == ["Callender, James T."]
@resource.personalName(1).dateName.should == ["1802"]
end
end
it "should support MADS.CorporateName structures" do
@resource.corporateName.should == ["University of California, San Diego., University Library"]
@resource.corporateName(0).fullName.should == ["University of California, San Diego."]
@resource.corporateName(0).dateName.should == ["University Library"]
end
describe "complexSubject" do
it "should support MADS.ComplexSubject structures" do
@resource.complexSubject(0).personalName.should == ["Jefferson, Thomas, 1743-1826"]
@resource.complexSubject(0).topic.should == ["Presidency"]
@resource.complexSubject(0).temporal.should == ["1801-1809"]
end
it "should aggregate subelement values in authoritativeLabel" do
@resource.complexSubject.should == ["Jefferson, Thomas, 1743-1826--Presidency--1801-1809"]
@resource.complexSubject(0).authoritativeLabel.should == "Jefferson, Thomas, 1743-1826--Presidency--1801-1809"
end
end
it "should create proper XML when stuff has been inserted" do
@resource.personalName << "Jefferson Randolph, Martha"
@resource.complexSubject << {personalName: "Callender, James T.", topic:"Newspapers"}
@resource.content.should be_equivalent_to fixture("damsSubjectExpectedOutput.rdf.xml")
end
end
end
<mads:Topic>
<mads:authoritativeLabel>Cosmology</mads:authoritativeLabel>
<mads:elementList rdf:parseType="Collection">
<mads:TopicElement>
<mads:elementValue>Cosmology</mads:elementValue>
</mads:TopicElement>
</mads:elementList>
</mads:Topic>
<mads:Temporal>
<mads:authoritativeLabel>16th Century</mads:authoritativeLabel>
<mads:elementList rdf:parseType="Collection">
<mads:TemporalElement>
<mads:elementValue>16th Century</mads:elementValue>
</mads:TemporalElement>
</mads:elementList>
</mads:Temporal>
<mads:PersonalName>
<mads:authoritativeLabel>Jefferson, Thomas, 1743-1826</mads:authoritativeLabel>
<mads:elementList rdf:parseType="Collection">
<mads:FullNameElement>
<mads:elementValue>Jefferson, Thomas,</mads:elementValue>
</mads:FullNameElement>
<mads:DateNameElement>
<mads:elementValue>1743-1826</mads:elementValue>
</mads:DateNameElement>
</mads:elementList>
</mads:PersonalName>
<mads:CorporateName>
<mads:authoritativeLabel>University of California, San Diego. University Library</mads:authoritativeLabel>
<mads:elementList rdf:parseType="Collection">
<mads:NameElement>
<mads:elementValue>University of California, San Diego.</mads:elementValue>
</mads:NameElement>
<mads:NameElement>
<mads:elementValue>University Library</mads:elementValue>
</mads:NameElement>
</mads:elementList>
</mads:CorporateName>
<mads:ComplexSubject>
<mads:authoritativeLabel>Jefferson, Thomas, 1743-1826--Presidency--1801-1809</mads:authortiativeLabel>
<mads:componentList rdf:parseType="Collection">
<mads:PersonalName>
<mads:authoritativeLabel>Jefferson, Thomas, 1743-1826</mads:authoritativeLabel>
<mads:elementList rdf:parseType="Collection">
<mads:FullNameElement>
<mads:elementValue>Jefferson, Thomas,</mads:elementValue>
</mads:FullNameElement>
<mads:DateNameElement>
<mads:elementValue>1743-1826</mads:elementValue>
</mads:DateNameElement>
</mads:elementList>
</mads:PersonalName>
<mads:Topic>
<mads:authoritativeLabel>Presidency</mads:authoritativeLabel>
<mads:elementList rdf:parseType="Collection">
<mads:TopicElement>
<mads:elementValue>Presidency</mads:elementValue>
</mads:TopicElement>
</mads:elementList>
</mads:Topic>
<mads:Temporal>
<mads:authoritativeLabel>1801-1809</mads:authoritativeLabel>
<mads:elementList rdf:parseType="Collection">
<mads:TemporalElement>
<mads:elementValue>1801-1809</mads:elementValue>
</mads:TemporalElement>
</mads:elementList>
</mads:Temporal>
</mads:componentList>
</mads:ComplexSubject>
require 'spec_helper'
describe ActiveFedora::RDFDatastream do
describe "a new instance" do
its(:metadata?) { should be_true}
its(:content_changed?) { should be_false}
end
describe "an instance that exists in the datastore, but hasn't been loaded" do
before do
class DummyMADS < RDF::Vocabulary("http://www.loc.gov/mads/rdf/v1#")
property :Topic
property :TopicElement
property :elementList
property :authoritativeLabel
class Topic
include ActiveFedora::RdfObject
# rdf_type DummyMADS.Topic
map_predicates do |map|
map.elementList(in: DummyMADS, to: "elementList", class_name:"DummyMADS::ElementList")
#map.default! [:elementList, :topicElement]
#map.computed!(:authoritativeLabel, in: DummyMADS, to: "authoritativeLabel", sources: [:elementList])
end
end
class ElementList
include ActiveFedora::RdfObject
rdf_type DummyMADS.elementList
map_predicates do |map|
map.topicElement(in: DummyMADS, to: "TopicElement")
end
end
end
class ComplexRDFDatastream < ActiveFedora::NtriplesRDFDatastream
map_predicates do |map|
map.topic(in: DummyMADS, to: "Topic", class_name:"DummyMADS::Topic")
end
end
@ds = ComplexRDFDatastream.new(stub('inner object', :pid=>'foo', :new? =>true), 'descMetadata')
end
after do
Object.send(:remove_const, :ComplexRDFDatastream)
Object.send(:remove_const, :DummyMADS)
end
subject { @ds }
describe "complex properties" do
it "should support assignment operator, assertion operator, and computed properties" do
# @ds.topic.build
# @ds.topic.first.elementList.build
# @ds.topic[0].elementList[0].topicElement = "Cosmology"
# puts @ds.graph.dump(:rdfxml)
# puts @ds.graph.dump(:ntriples)
@ds.topic = ["Cosmology"]
@ds.topic << "Quantum States"
debugger
# What it's currently able to do:
#
# @ds.topic
# =>
[#<DummyMADS::Topic:0x00000101f0a4b8 @graph=#<RDF::Repository:0x80fbd828()>, @rdf_subject=#<RDF::Node:0x80e1465c(_:g2162247260)>>, #<DummyMADS::Topic:0x00000101f084b0 @graph=#<RDF::Repository:0x80fbd828()>, @rdf_subject=#<RDF::Node:0x80f8e104(_:g2163794180)>>]
#
# @ds.topic[0].value
# => ["Cosmology"]
@ds.topic.should == ["Cosmology", "Quantum States"]
#@ds.topic[0].elementList[0].topicElement.should == "Cosmology"
@ds.topic(0).elementList.topicElement.should == "Cosmology"
@ds.topic(0).authoritativeLabel.should == "Cosmology"
expected_xml = '<mads:Topic>
<mads:authoritativeLabel>Cosmology</mads:authoritativeLabel>
<mads:elementList rdf:parseType="Collection">
<mads:TopicElement>
<mads:elementValue>Cosmology</mads:elementValue>
</mads:TopicElement>
</mads:elementList>
</mads:Topic>
<mads:Topic>
<mads:authoritativeLabel>Quantum States</mads:authoritativeLabel>
<mads:elementList rdf:parseType="Collection">
<mads:TopicElement>
<mads:elementValue>Quantum States</mads:elementValue>
</mads:TopicElement>
</mads:elementList>
</mads:Topic>'
@ds.content.should be_equivalent_to expected_xml
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment