require 'spec_helper' require 'rexml/document' include ActiveFedora describe ActiveFedora::Base do before(:all) do class OralHistory < ActiveFedora::Base include ActiveFedora::Relationships # Imitating DataMapper ... has_relationship "parts", :is_part_of, :inbound => true # These are all the properties that don't quite fit into Qualified DC # Put them on the object itself (in the properties datastream) for now. has_metadata :name => "properties", :type => ActiveFedora::MetadataDatastream do |m| m.field "narrator", :string m.field "interviewer", :string m.field "transcript_editor", :text m.field "bio", :string m.field "notes", :text m.field "hard_copy_availability", :text m.field "hard_copy_location", :text m.field "other_contributor", :string m.field "restrictions", :text m.field "series", :string m.field "location", :string end # has_metadata :name=>"arbitrary_xml", :type=> ActiveFedora::NokogiriDatastream do |m| # m.root_property :myxml, "my_xml", "http://www.example.gov/schema/v3" # end has_metadata :name=>"mods_article", :type=> Hydra::ModsArticleDatastream has_metadata :name => "dublin_core", :type => ActiveFedora::QualifiedDublinCoreDatastream do |m| # Default :multiple => true # # on retrieval, these will be pluralized and returned as arrays # ie. subject_entries = my_oral_history.dublin_core.subjects # # aimint to use method-missing to support calling methods like # my_oral_history.subjects OR my_oral_history.titles OR EVEN my_oral_history.title whenever possible # Setting new Types for dates and text content m.field "creation_date", :date, :xml_node => "date" m.field "abstract", :text, :xml_node => "abstract" m.field "rights", :text, :xml_node => "rights" # Setting up special named fields m.field "subject_heading", :string, :xml_node => "subject", :encoding => "LCSH" m.field "spatial_coverage", :string, :xml_node => "spatial", :encoding => "TGN" m.field "temporal_coverage", :string, :xml_node => "temporal", :encoding => "Period" m.field "type", :string, :xml_node => "type", :encoding => "DCMITYPE" m.field "alt_title", :string, :xml_node => "alternative" end has_metadata :name => "significant_passages", :type => ActiveFedora::MetadataDatastream do |m| m.field "significant_passage", :text end has_metadata :name => "sensitive_passages", :type => ActiveFedora::MetadataDatastream do |m| m.field "sensitive_passage", :text end end sample_location = "Boston, Massachusetts" sample_notes = 'Addelson, Frances. (1973?) "The Induced Abortion," American Journal of Ortho-Psychiatry, Addelson, Frances. "Abortion: Source of Guilt or Growth," National Journal of Gynecology and Obstetrics., Addelson, Frances. "First Zionist Novel," Jewish Frontier.' sample_other_contributor = 'any other contributors, people or corporate names (eg. Temple Israel)' sample_transcript_editor = 'Siegel, Cheryl' sample_hard_copy_availability = <<-END Yes, please contact the Jewish Women\\\'s Archive for more information on using this source. END sample_narrator = 'Addelson, Frances' sample_bio = <<-END Rochelle Ruthchild interviewed Frances Addleson on October 18, November 14, and December 10, 1997. The interview thoroughly examined the trajectory of Frances\' life from birth until the time of the interview. As a young child, Frances\' father died during the influenza epidemic, and her mother was not equipped to care for her and her siblings. Consequently, they were placed in a Jewish foster home. Although her experience was mostly positive, this experience would leave life-long effects. Frances attended Radcliffe upon the urging of a mentor and later obtained her Master\'s degree in social work from Simmons College in 1954. In the 1940\'s, she returned to work while her children were still young; a rather unusual event for that time period. While working as a social worker at Beth Israel Hospital in the early 1970\'s, she helped counsel countless women who came to the hospital seeking abortions before the procedure was officially legalized during the landmark Roe vs. Wade decision in 1973. Frances would later write two articles that were published in medical journals about her experience during this time. Although not a very religious person, Frances felt connected to the Jewish notion of social justice and remained very active until an accident in the late 1990\'s. END sample_interviewer = "Ruthchild, & Rochelle" @properties_sample_values2 = Hash[:narrator => "Narrator1 & Narrator2", :interviewer => "Interviewer", :transcript_editor => "Transcript Editor", :bio => "Biographic info", :notes => "My Note\\\'s a good one", :hard_copy_availability => "Yes", :hard_copy_location => "Archives", :other_contributor => "Sally Ride", :restrictions => "None", :series => "My Series", :location => "location"] @properties_sample_values = Hash[:narrator => sample_narrator, :interviewer => sample_interviewer, :transcript_editor => sample_transcript_editor, :bio => sample_bio, :notes => sample_notes, :hard_copy_availability => sample_hard_copy_availability, :hard_copy_location => "Archives", :other_contributor => sample_other_contributor, :restrictions => "None", :series => "My Series", :location => sample_location] @dublin_core_sample_values = Hash[:creator => 'Matt && McClain', :publisher => 'Jewish Women\\\'s Archive', :description => "description", :identifier => "jwa:sample_pid", :title => "title", :alt_title => "alt_title", :subject => "subject", :subject_heading => "subject heading", :creation_date => "2008-07-02T05:09:42.015Z", :language => "language", :spatial_coverage => "spatial coverage", :temporal_coverage => "temporal coverage", :abstract => "abstract", :rights => "rights", :type => "type", :extent => "extent", :format => "format", :medium => "medium"] @signigicant_passages_sample_values = {} @sensitive_passages_sample_values = {} @sample_xml = "REMOVEDREMOVEDOralHistorychangeme:14527subject headingtyperightspublishercreation datejwa:sample_pidformatextentlanguagedescriptiontitlemediumspatial coveragealt_titletemporal coveragesubjectcreatorabstractSally RideTranscript EditorNoneBiographic infoMy SeriesMy NotelocationYesNarratorArchivesInterviewer" end before(:each) do @test_history = OralHistory.new end after(:each) do end after(:all) do Object.send(:remove_const, :OralHistory) end it "should be an instance of ActiveFedora::Base" do @test_history.should be_kind_of(ActiveFedora::Base) end it "should create proxies to all the datastreams" do properties_ds = @test_history.datastreams["properties"] dublin_core_ds = @test_history.datastreams["dublin_core"] @test_history.should_not respond_to(:properties) @test_history.properties.should be properties_ds @test_history.should respond_to(:properties) OralHistory.new.should respond_to(:properties) end it "should push all of the metadata fields into solr" do # TODO: test must test values using solr symbol names (ie. _field, _text and _date) properties_ds = @test_history.datastreams["properties"] dublin_core_ds = @test_history.datastreams["dublin_core"] @properties_sample_values.each_pair do |field, value| properties_ds.send("#{field.to_s}_values=", [value]) end @dublin_core_sample_values.each_pair do |field, value| dublin_core_ds.send("#{field.to_s}_values=", [value]) end @test_history.save @solr_result = OralHistory.find_by_solr(@test_history.pid)[0] @properties_sample_values.each_pair do |field, value| (@solr_result["#{field.to_s}_t"] || @solr_result["#{field.to_s}_dt"]).should == [::Solrizer::Extractor.format_node_value(value)] end @dublin_core_sample_values.each_pair do |field, value| dublin_core_ds.send("#{field.to_s}_values").should == [value] end end it "should have Qualified Dublin core, with custom accessors" do #xml = REXML::Document.new(@test_history.to_xml.to_s) dublin_core_ds = @test_history.datastreams["dublin_core"] dublin_core_ds.subject_heading_values = "My Subject Heading" dc_xml = REXML::Document.new(dublin_core_ds.to_dc_xml) dc_xml.root.elements["dcterms:subject"].text.should == "My Subject Heading" dc_xml.root.elements["dcterms:subject"].attributes["xsi:type"].should == "LCSH" end it "should support #find_by_solr" do solr_result = OralHistory.find(:all) solr_result.should_not be_nil end describe '#new' do it "should support custom pids" do oh = OralHistory.new(:pid=>"uuid:blah-blah-blah") oh.pid.should == "uuid:blah-blah-blah" end end end