spec/unit/properties_spec.rb in om-0.1.6 vs spec/unit/properties_spec.rb in om-0.1.7
- old
+ new
@@ -13,14 +13,20 @@
# Could add support for multiple root declarations.
# For now, assume that any modsCollections have already been broken up and fed in as individual mods documents
# root :mods_collection, :path=>"modsCollection",
# :attributes=>[],
# :subelements => :mods
-
+
+
root_property :mods, "mods", "http://www.loc.gov/mods/v3", :attributes=>["id", "version"], :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-2.xsd"
+
+ property :title_info, :path=>"titleInfo",
+ :convenience_methods => {
+ :main_title => {:path=>"title"},
+ :language => {:path=>{:attribute=>"lang"}},
+ }
-
property :name_, :path=>"name",
:attributes=>[:xlink, :lang, "xml:lang", :script, :transliteration, {:type=>["personal", "enumerated", "corporate"]} ],
:subelements=>["namePart", "displayForm", "affiliation", :role, "description"],
:default_content_path => "namePart",
:convenience_methods => {
@@ -35,11 +41,29 @@
property :role, :path=>"role",
:parents=>[:name_],
:attributes=>[ { "type"=>["text", "code"] } , "authority"],
:default_content_path => "roleTerm"
-
+ property :journal, :path=>'relatedItem', :attributes=>{:type=>"host"},
+ :subelements=>[:title_info, :origin_info, :issue],
+ :convenience_methods => {
+ :issn => {:path=>"identifier", :attributes=>{:type=>"issn"}},
+ }
+
+ property :issue, :path=>'part',
+ :subelements=>[:start_page, :end_page],
+ :convenience_methods => {
+ :volume => {:path=>"detail", :attributes=>{:type=>"volume"}},
+ :level => {:path=>"detail", :attributes=>{:type=>"level"}},
+ # Hack to support provisional spot for start & end page (nesting was too deep for this version of OM)
+ :citation_start_page => {:path=>"pages", :attributes=>{:type=>"start"}},
+ :citation_end_page => {:path=>"pages", :attributes=>{:type=>"end"}},
+ :foo => {:path=>"foo", :attributes=>{:type=>"ness"}},
+ :publication_date => {:path=>"date"}
+ }
+ property :start_page, :path=>"extent", :attributes=>{:unit=>"pages"}, :default_content_path => "start"
+ property :end_page, :path=>"extent", :attributes=>{:unit=>"pages"}, :default_content_path => "end"
end
class FakeOtherOx < Nokogiri::XML::Document
include OM::XML::Properties
@@ -125,21 +149,34 @@
FakeOxMods.properties[:name_][:convenience_methods][:role][:xpath].should == '//oxns:name/oxns:role'
FakeOxMods.properties[:name_][:convenience_methods][:role][:xpath_relative].should == 'oxns:role'
FakeOxMods.properties[:name_][:convenience_methods][:role][:xpath_constrained].should == '//oxns:name[contains(oxns:role/oxns:roleTerm, "#{constraint_value}")]'.gsub('"', '\"')
end
- it "should create an accessor for the created property" do
- pending
- FakeOXMods.accessors.should have_key(:name_)
+ it "supports treating attributes as properties" do
+ FakeOxMods.properties[:title_info][:convenience_methods][:language][:xpath].should == '//oxns:titleInfo/@lang'
+ FakeOxMods.properties[:title_info][:convenience_methods][:language][:xpath_relative].should == '@lang'
+ FakeOxMods.properties[:title_info][:convenience_methods][:language][:xpath_constrained].should == '//oxns:titleInfo[contains(@lang, "#{constraint_value}")]'.gsub('"', '\"')
end
- it "should create accessors for subelements" do
- pending
- FakeOXMods.accessors[:name_][:children][:role][:children].should have_key(:family_name)
+ it "should support deep nesting of properties" do
+ pending "requires property method to be recursive"
+
+ FakeOxMods.properties[:journal][:convenience_methods][:issue][:convenience_methods][:volume].should == {:xpath_constrained=>"//oxns:part[contains(oxns:detail[@type=\\\"volume\\\"], \\\"\#{constraint_value}\\\")]", :path=>"detail", :attributes=>{:type=>"volume"}, :xpath=>"//oxns:part/oxns:detail[@type=\"volume\"]", :xpath_relative=>"oxns:detail[@type=\"volume\"]"}
+ prop_info = FakeOxMods.property_info_for([:journal, :issue, :volume])
+ prop_info[:xpath_constrained].should == "//oxns:part[contains(oxns:detail[@type=\\\"volume\\\"], \\\"\#{constraint_value}\\\")]"
+ prop_info[:xpath].should == "//oxns:part/oxns:detail[@type=\"volume\"]"
+ prop_info[:xpath_relative].should == "oxns:detail[@type=\"volume\"]"
end
- it "should not overwrite default property info when adding a variant property" do
+ it "should support even deeper nesting of properties" do
+ pending "requires property method to be recursive"
+
+ FakeOxMods.properties[:journal][:convenience_methods][:issue][:convenience_methods][:start_page].should == {:xpath_constrained=>"//oxns:part[contains(oxns:detail[@type=\\\"volume\\\"], \\\"\#{constraint_value}\\\")]", :path=>"detail", :attributes=>{:type=>"volume"}, :xpath=>"//oxns:part/oxns:detail[@type=\"volume\"]", :xpath_relative=>"oxns:detail[@type=\"volume\"]"}
+ FakeOxMods.property_info_for([:journal, :issue, :end_page]).should == ""
+ end
+
+ it "should not overwrite default property info when adding a variant property" do
FakeOxMods.properties[:name_].should_not equal(FakeOxMods.properties[:person])
FakeOxMods.properties[:name_][:convenience_methods].should_not equal(FakeOxMods.properties[:person][:convenience_methods])
FakeOxMods.properties[:name_][:xpath].should_not == FakeOxMods.properties[:person][:xpath]
FakeOxMods.properties[:name_][:convenience_methods][:date][:xpath_constrained].should_not == FakeOxMods.properties[:person][:convenience_methods][:date][:xpath_constrained]
@@ -245,9 +282,16 @@
FakeOxMods.builder_template([:person,:role]).should == simple_role_builder_template
marcrelator_role_builder_template = 'xml.role( :type=>\'code\', :authority=>\'marcrelator\' ) { xml.roleTerm( \'#{builder_new_value}\' ) }'
FakeOxMods.builder_template([:role], {:attributes=>{"type"=>"code", "authority"=>"marcrelator"}} ).should == marcrelator_role_builder_template
FakeOxMods.builder_template([:person,:role], {:attributes=>{"type"=>"code", "authority"=>"marcrelator"}} ).should == marcrelator_role_builder_template
+ end
+
+ it "should work with deeply nested properties" do
+ pending "requires property method to be recursive"
+
+ FakeOxMods.builder_template([:journal, :issue, :volume]).should == "fixme"
+ FakeOxMods.builder_template([:journal, :issue, :start_page]).should == "fixme"
end
end
describe "#applicable_attributes" do