# encoding: UTF-8 describe "Subject fields (searchworks.rb)" do before(:all) do @ns_decl = "xmlns='#{Mods::MODS_NS}'" @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' @subject_mods = " #{@genre} #{@cart_coord} #{@s_genre} #{@geo} #{@geo_code} #{@hier_geo_country} #{@s_name} #{@occupation} #{@temporal} #{@s_title} #{@topic} " m_no_subject = "notit" @ng_mods_no_subject = Nokogiri::XML(m_no_subject) end before(:each) do @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(@subject_mods) @ng_mods = Nokogiri::XML(@subject_mods) end context "search fields" do context "topic_search" do it "should be nil if there are no values in the MODS" do m = "" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.topic_search).to eq [] end it "should contain subject subelement data" do expect(@smods_rec.topic_search).to include(@topic) end it "should not contain other subject element data" do expect(@smods_rec.topic_search).not_to include(@cart_coord) expect(@smods_rec.topic_search).not_to include(@s_genre) expect(@smods_rec.topic_search).not_to include(@geo) expect(@smods_rec.topic_search).not_to include(@geo_code) expect(@smods_rec.topic_search).not_to include(@hier_geo_country) expect(@smods_rec.topic_search).not_to include(@s_name) expect(@smods_rec.topic_search).not_to include(@occupation) expect(@smods_rec.topic_search).not_to include(@temporal) expect(@smods_rec.topic_search).not_to include(@s_title) end it "should not be nil if there are only subject/topic elements (no )" do m = "#{@topic}" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.topic_search).to eq([@topic]) end context "topic subelement" do it "should have a separate value for each topic element" do m = " first second third " @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.topic_search).to eq(['first', 'second', 'third']) end it "should be empty if there are only empty values in the MODS" do m = "notit" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.topic_search).to eq [] end end end # topic_search context "subject_other_search" do it "should be nil if there are no values in the MODS" do m = "" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.subject_other_search).to eq [] end it "should contain subject SUBelement data" do expect(@smods_rec.subject_other_search).to include(@s_name) end it "should contain subject subelement data" do expect(@smods_rec.subject_other_search).to include(@occupation) end it "should contain subject SUBelement data" do @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(@subject_mods) expect(@smods_rec.subject_other_search).to include(@s_title) end it "should not contain other subject element data" do expect(@smods_rec.subject_other_search).not_to include(@genre) expect(@smods_rec.subject_other_search).not_to include(@cart_coord) expect(@smods_rec.subject_other_search).not_to include(@s_genre) expect(@smods_rec.subject_other_search).not_to include(@geo) expect(@smods_rec.subject_other_search).not_to include(@geo_code) expect(@smods_rec.subject_other_search).not_to include(@hier_geo_country) expect(@smods_rec.subject_other_search).not_to include(@temporal) expect(@smods_rec.subject_other_search).not_to include(@topic) end it "should not be nil if there are only subject/name elements" do m = "#{@s_name}" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.subject_other_search).to eq([@s_name]) end it "should not be nil if there are only subject/occupation elements" do m = "#{@occupation}" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.subject_other_search).to eq([@occupation]) end it "should not be nil if there are only subject/titleInfo elements" do m = "#{@s_title}" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.subject_other_search).to eq([@s_title]) end context "occupation subelement" do it "should have a separate value for each occupation element" do m = " first second third " @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.subject_other_search).to eq(['first', 'second', 'third']) end it "should be nil if there are only empty values in the MODS" do m = "notit" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.subject_other_search).to eq [] end end end # subject_other_search context "subject_other_subvy_search" do it "should be nil if there are no values in the MODS" do @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(@ng_mods_no_subject.to_s) expect(@smods_rec.subject_other_subvy_search).to eq [] end it "should contain subject subelement data" do expect(@smods_rec.subject_other_subvy_search).to include(@temporal) end it "should contain subject SUBelement data" do expect(@smods_rec.subject_other_subvy_search).to include(@s_genre) end it "should not contain other subject element data" do expect(@smods_rec.subject_other_subvy_search).not_to include(@genre) expect(@smods_rec.subject_other_subvy_search).not_to include(@cart_coord) expect(@smods_rec.subject_other_subvy_search).not_to include(@geo) expect(@smods_rec.subject_other_subvy_search).not_to include(@geo_code) expect(@smods_rec.subject_other_subvy_search).not_to include(@hier_geo_country) expect(@smods_rec.subject_other_subvy_search).not_to include(@s_name) expect(@smods_rec.subject_other_subvy_search).not_to include(@occupation) expect(@smods_rec.subject_other_subvy_search).not_to include(@topic) expect(@smods_rec.subject_other_subvy_search).not_to include(@s_title) end it "should not be nil if there are only subject/temporal elements (no subject/genre)" do m = "#{@temporal}" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.subject_other_subvy_search).to eq([@temporal]) end it "should not be nil if there are only subject/genre elements (no subject/temporal)" do m = "#{@s_genre}" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.subject_other_subvy_search).to eq([@s_genre]) end context "temporal subelement" do it "should have a separate value for each temporal element" do m = " 1890-1910 20th century another " @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.subject_other_subvy_search).to eq(['1890-1910', '20th century', 'another']) end it "should be nil if there are only empty values in the MODS" do m = "notit" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.subject_other_subvy_search).to eq [] end end context "genre subelement" do it "should have a separate value for each genre element" do m = " first second third " @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.subject_other_subvy_search).to eq(['first', 'second', 'third']) end it "should be nil if there are only empty values in the MODS" do m = "notit" @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.subject_other_subvy_search).to eq [] end end end # subject_other_subvy_search context "subject_all_search" do it "should be nil if there are no values in the MODS" do @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(@ng_mods_no_subject.to_s) expect(@smods_rec.subject_all_search).to eq [] end it "should not contain cartographic sub element" do expect(@smods_rec.subject_all_search).not_to include(@cart_coord) end it "should not include codes from hierarchicalGeographic sub element" do expect(@smods_rec.subject_all_search).not_to include(@geo_code) end it "should contain all other subject subelement data" do @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(@subject_mods) ## need to re-allow/expect :info message with newly assigned object expect(@smods_rec.subject_all_search).to include(@s_genre) expect(@smods_rec.subject_all_search).to include(@geo) expect(@smods_rec.subject_all_search).to include(@hier_geo_country) expect(@smods_rec.subject_all_search).to include(@s_name) expect(@smods_rec.subject_all_search).to include(@occupation) expect(@smods_rec.subject_all_search).to include(@temporal) expect(@smods_rec.subject_all_search).to include(@s_title) expect(@smods_rec.subject_all_search).to include(@topic) end end # subject_all_search end # search fields context "facet fields" do context "topic_facet" do it "should include topic subelement" do expect(@smods_rec.topic_facet).to include(@topic) end it "should include sw_subject_names" do expect(@smods_rec.topic_facet).to include(@s_name) end it "should include sw_subject_titles" do expect(@smods_rec.topic_facet).to include(@s_title) end it "should include occupation subelement" do expect(@smods_rec.topic_facet).to include(@occupation) end it "should have the trailing punctuation removed" do m = " comma, semicolon; backslash \\ internal, punct;uation " @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.topic_facet).to include('comma') expect(@smods_rec.topic_facet).to include('semicolon') expect(@smods_rec.topic_facet).to include('backslash') expect(@smods_rec.topic_facet).to include('internal, punct;uation') end it "should be nil if there are no values" do @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(@ng_mods_no_subject.to_s) expect(@smods_rec.topic_facet).to eq [] end end context "geographic_facet" do it "should call geographic_search" do expect(@smods_rec).to receive(:geographic_search) @smods_rec.geographic_facet end it "should be like geographic_search with the trailing punctuation (and preceding spaces) removed" do m = " comma, semicolon; backslash \\ internal, punct;uation " @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.geographic_facet).to include('comma') expect(@smods_rec.geographic_facet).to include('semicolon') expect(@smods_rec.geographic_facet).to include('backslash') expect(@smods_rec.geographic_facet).to include('internal, punct;uation') end it "should be empty if there are no values" do @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(@ng_mods_no_subject.to_s) expect(@smods_rec.geographic_facet).to eq [] end end context "era_facet" do it "should be temporal subelement with the trailing punctuation removed" do m = " comma, semicolon; backslash \\ internal, punct;uation " @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(m) expect(@smods_rec.era_facet).to include('comma') expect(@smods_rec.era_facet).to include('semicolon') expect(@smods_rec.era_facet).to include('backslash') expect(@smods_rec.era_facet).to include('internal, punct;uation') end it "should be empty if there are no values" do @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(@ng_mods_no_subject.to_s) expect(@smods_rec.era_facet).to eq [] end end end # facet fields end