# encoding: UTF-8 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 "languages" do it "should use the SearchWorks controlled vocabulary" do m = "per ara, dut" @smods_rec.from_str m langs = @smods_rec.sw_language_facet expect(langs.size).to eq(3) expect(langs).to include("Persian", "Arabic", "Dutch") expect(langs).not_to include("Dutch; Flemish") end it "should return a language string from lookup for a valid language code that has a type=code specified but no authority" do m = " eng" @smods_rec.from_str m langs = @smods_rec.sw_language_facet expect(langs.size).to eq(1) expect(langs).to eq ["English"] expect(langs).not_to include("eng") end it "should return nil for a language code that has a type=code specified but no authority" do m = " bogus" @smods_rec.from_str m langs = @smods_rec.sw_language_facet expect(langs.size).to be 1 expect(langs).to eq [nil] end it "should return nothing when the authority and type=code are specified but the language code cannot be found" do m = "bogus" @smods_rec.from_str m langs = @smods_rec.sw_language_facet expect(langs.size).to eq(0) end it "should return nothing for a language code that has no authority or type specified" do m = " bogus" @smods_rec.from_str m langs = @smods_rec.sw_language_facet expect(langs.size).to be 0 expect(langs).to eq [] end it "should return nothing for a language code that has an unknown authority and doesn't have a type specified" do m = " bogus" @smods_rec.from_str m langs = @smods_rec.sw_language_facet expect(langs.size).to be 0 expect(langs).to eq [] end it "should return nothing for a blank languageTerm node (even when the authority is valid)" do m = " " @smods_rec.from_str m langs = @smods_rec.sw_language_facet expect(langs.size).to be 0 expect(langs).to eq [] end it "should not have duplicates" do m = "engEnglish" @smods_rec.from_str m langs = @smods_rec.sw_language_facet expect(langs.size).to eq 1 expect(langs).to include "English" end end context "sw author methods" do before(:all) do m = " John Huston q Crusty The Clown 1990- Watchful Eye 1850- Exciting Prints plain conference family JerkThe " @smods_rec.from_str(m) end it "non-person authors (for author_other_facet)" do expect(@smods_rec.sw_impersonal_authors).to eq(['Watchful Eye, 1850-', 'Exciting Prints', 'plain', 'conference', 'family']) end it "corporate authors (for author_corp_display)" do expect(@smods_rec.sw_corporate_authors).to eq(['Watchful Eye, 1850-', 'Exciting Prints']) end it "meeting authors (for author_meeting_display)" do expect(@smods_rec.sw_meeting_authors).to eq(['conference']) end context "sort author" do it "should be a String" do expect(@smods_rec.sw_sort_author).to eq('qJerk') end it "should not begin or end with whitespace" do expect(@smods_rec.sw_sort_author).to eq(@smods_rec.sw_sort_author.strip) end it "should substitute the java Character.MAX_CODE_POINT for nil main_author so missing main authors sort last" do r = Stanford::Mods::Record.new r.from_str "Jerk" expect(r.sw_sort_author).to match(/ Jerk$/) expect(r.sw_sort_author).to match("\u{10FFFF}") expect(r.sw_sort_author).to match("\xF4\x8F\xBF\xBF") end it "should not have any punctuation marks" do r = Stanford::Mods::Record.new r.from_str "J,e.r;;;k" expect(r.sw_sort_author).to match(/ Jerk$/) end end end # context sw author methods end