# encoding: UTF-8 require 'spec_helper' describe "Searchworks mixin for Stanford::Mods::Record" do before(:all) do @smods_rec = Stanford::Mods::Record.new @ns_decl = "xmlns='#{Mods::MODS_NS}'" end context "sw subject raw methods" do before(:all) do @genre = 'genre top level' @cart_coord = '6 00 S, 71 30 E' @s_genre = 'genre in subject' @geo = 'Somewhere' @geo_code = 'us' @hier_geo_country = 'France' @s_name = 'name in subject' @occupation = 'worker bee' @temporal = 'temporal' @s_title = 'title in subject' @topic = 'topic' m = " #{@genre} #{@cart_coord} #{@s_genre} #{@geo} #{@geo_code} #{@hier_geo_country} #{@s_name} #{@occupation} #{@temporal} #{@s_title} #{@topic} " @smods_rec.from_str m @sw_geographic_search = @smods_rec.sw_geographic_search @sw_subject_titles = @smods_rec.sw_subject_titles @sw_subject_names = @smods_rec.sw_subject_names end context "sw_subject_names" do it "should contain values" do expect(@sw_subject_names).to include(@s_name) end it "should not contain non-name subject subelements" do expect(@sw_subject_names).not_to include(@cart_coord) expect(@sw_subject_names).not_to include(@s_genre) expect(@sw_subject_names).not_to include(@geo) expect(@sw_subject_names).not_to include(@geo_code) expect(@sw_subject_names).not_to include(@hier_geo_country) expect(@sw_subject_names).not_to include(@occupation) expect(@sw_subject_names).not_to include(@temporal) expect(@sw_subject_names).not_to include(@topic) expect(@sw_subject_names).not_to include(@s_title) end it "should not contain subject/name/role" do m = " Alterman, Eric Eric Alterman creator cre " @smods_rec.from_str m expect(@smods_rec.sw_subject_names.find { |sn| sn =~ /cre/ }).to be_nil end it "should not contain subject/name/affiliation" do m = " Dr. Brown, B. F. Chemistry Dept., American University " @smods_rec.from_str m expect(@smods_rec.sw_subject_names.find { |sn| sn =~ /Chemistry/ }).to be_nil end it "should not contain subject/name/description" do m = " Abrams, Michael American artist, 20th c. " @smods_rec.from_str m expect(@smods_rec.sw_subject_names.find { |sn| sn =~ /artist/ }).to be_nil end it "should not include top level name element" do m = " Abrams, Michael American artist, 20th c. " @smods_rec.from_str m expect(@smods_rec.sw_subject_names).to eq([]) end it "should have one value for each name element" do m = " first second third " @smods_rec.from_str m expect(@smods_rec.sw_subject_names).to eq(['first', 'second', 'third']) end it "should be an empty Array if there are no values in the mods" do m = "notit" @smods_rec.from_str m expect(@smods_rec.sw_subject_names).to eq([]) end it "should be an empty Array if there are empty values in the mods" do m = "notit" @smods_rec.from_str m expect(@smods_rec.sw_subject_names).to eq([]) end context "combining subelements" do before(:all) do m = " first second " @smods_rec.from_str m end it "uses a ', ' as the separator by default" do expect(@smods_rec.sw_subject_names).to eq ['first, second'] end it "honors any string value passed in for the separator" do expect(@smods_rec.sw_subject_names(' --')).to eq(['first --second']) end end end # sw_subject_names context "sw_subject_titles" do it "should contain subelement values" do expect(@sw_subject_titles).to include(@s_title) end it "should not contain non-name subject subelements" do expect(@sw_subject_titles).not_to include(@cart_coord) expect(@sw_subject_titles).not_to include(@s_genre) expect(@sw_subject_titles).not_to include(@geo) expect(@sw_subject_titles).not_to include(@geo_code) expect(@sw_subject_titles).not_to include(@hier_geo_country) expect(@sw_subject_titles).not_to include(@s_name) expect(@sw_subject_titles).not_to include(@occupation) expect(@sw_subject_titles).not_to include(@temporal) expect(@sw_subject_titles).not_to include(@topic) end it "should not include top level titleInfo element" do m = "Oklahoma" @smods_rec.from_str m expect(@smods_rec.sw_subject_titles).to eq([]) end it "should have one value for each titleInfo element" do m = " first second third " @smods_rec.from_str m expect(@smods_rec.sw_subject_titles).to eq(['first', 'second', 'third']) end it "should be an empty Array if there are no values in the mods" do m = "notit" @smods_rec.from_str m expect(@smods_rec.sw_subject_titles).to eq([]) end it "should be an empty Array if there are empty values in the mods" do m = "</titleInfo></subject><note>notit</note></mods>" @smods_rec.from_str m expect(@smods_rec.sw_subject_titles).to eq([]) end context "combining subelements" do before(:all) do m = "<mods #{@ns_decl}> <subject> <titleInfo> <title>first second " @smods_rec.from_str m end it "uses a ' ' as the separator by default" do expect(@smods_rec.sw_subject_titles).to eq ['first second'] end it "honors any string value passed in for the separator" do expect(@smods_rec.sw_subject_titles(' --')).to eq(['first --second']) end it "includes all subelements in the order of occurrence" do m = " 1 2 3 4 5 " @smods_rec.from_str m expect(@smods_rec.sw_subject_titles).to eq(['1 2 3 4 5']) end end end # sw_subject_titles context "sw_geographic_search" do it "should contain subject subelement data" do expect(@sw_geographic_search).to include(@geo) end it "should contain subject subelement data" do expect(@sw_geographic_search).to include(@hier_geo_country) end it "should contain translation of subelement data with translated authorities" do m = "e-er" @smods_rec.from_str m expect(@smods_rec.sw_geographic_search).to include('Estonia') end it "should not contain other subject element data" do expect(@sw_geographic_search).not_to include(@genre) expect(@sw_geographic_search).not_to include(@cart_coord) expect(@sw_geographic_search).not_to include(@s_genre) expect(@sw_geographic_search).not_to include(@s_name) expect(@sw_geographic_search).not_to include(@occupation) expect(@sw_geographic_search).not_to include(@temporal) expect(@sw_geographic_search).not_to include(@topic) expect(@sw_geographic_search).not_to include(@s_title) end it "should be [] if there are no values in the MODS" do m = "notit" @smods_rec.from_str m expect(@smods_rec.sw_geographic_search).to eq([]) end it "should not be empty Array if there are only subject/geographic elements" do m = "#{@geo}" @smods_rec.from_str m expect(@smods_rec.sw_geographic_search).to eq([@geo]) end it "should not be empty Array if there are only subject/hierarchicalGeographic" do m = "#{@hier_geo_country}" @smods_rec.from_str m expect(@smods_rec.sw_geographic_search).to eq([@hier_geo_country]) end it "should not be empty Array if there are only subject/geographicCode elements" do m = "e-er" @smods_rec.from_str m expect(@smods_rec.sw_geographic_search).to eq(['Estonia']) end context "geographic subelement" do it "should have a separate value for each geographic element" do m = " Mississippi Tippah County Washington (D.C.) " @smods_rec.from_str m expect(@smods_rec.sw_geographic_search).to eq(['Mississippi', 'Tippah County', 'Washington (D.C.)']) end it "should be empty Array if there are only empty values in the MODS" do m = "notit" @smods_rec.from_str m expect(@smods_rec.sw_geographic_search).to eq([]) end end context "hierarchicalGeographic subelement" do it "should have a separate value for each hierarchicalGeographic element" do m = " first second third " @smods_rec.from_str m expect(@smods_rec.sw_geographic_search).to eq(['first', 'second', 'third']) end it "should be empty Array if there are only empty values in the MODS" do m = "notit" @smods_rec.from_str m expect(@smods_rec.sw_geographic_search).to eq([]) end context "combining subelements" do before(:all) do m = " Canada British Columbia Vancouver " @smods_rec.from_str m end it "uses a space as the separator by default" do expect(@smods_rec.sw_geographic_search).to eq ['Canada British Columbia Vancouver'] end it "honors any string value passed in for the separator" do expect(@smods_rec.sw_geographic_search(' --')).to eq(['Canada --British Columbia --Vancouver']) end end end # hierarchicalGeographic context "geographicCode subelement" do before(:all) do m = " n-us-md e-er mg us " @smods_rec.from_str m @geo_search_from_codes = @smods_rec.sw_geographic_search end it "should not add untranslated values" do expect(@geo_search_from_codes).not_to include('n-us-md') expect(@geo_search_from_codes).not_to include('e-er') expect(@geo_search_from_codes).not_to include('mg') expect(@geo_search_from_codes).not_to include('us') end it "should translate marcgac codes" do expect(@geo_search_from_codes).to include('Estonia') end it "should translate marccountry codes" do expect(@geo_search_from_codes).to include('Madagascar') end it "should not translate other codes" do expect(@geo_search_from_codes).not_to include('United States') end it "should have a separate value for each geographicCode element" do m = " e-er mg n-us-md " @smods_rec.from_str m expect(@smods_rec.sw_geographic_search).to eq(['Estonia', 'Madagascar', 'Maryland']) end it "should be empty Array if there are only empty values in the MODS" do m = "notit" @smods_rec.from_str m expect(@smods_rec.sw_geographic_search).to eq([]) end it "should add the translated value if it wasn't present already" do m = " Somewhere e-er " @smods_rec.from_str m expect(@smods_rec.sw_geographic_search.size).to eq(2) expect(@smods_rec.sw_geographic_search).to include('Estonia') end it "should not add the translated value if it was already present" do m = " Estonia e-er " @smods_rec.from_str m expect(@smods_rec.sw_geographic_search.size).to eq(1) expect(@smods_rec.sw_geographic_search).to eq(['Estonia']) end end end # sw_geographic_search end # context sw subject methods end