Skip to content

Instantly share code, notes, and snippets.

@dkinzer
Created March 6, 2020 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkinzer/88f44606986a2cb787f78fc6f60d0035 to your computer and use it in GitHub Desktop.
Save dkinzer/88f44606986a2cb787f78fc6f60d0035 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
RSpec.describe Traject::Indexer::NokogiriIndexer do
let(:settings) { {
"nokogiri.each_record_xpath" => "/oai:OAI-PMH/oai:ListRecords/oai:record",
"nokogiri.namespaces" => { "oai" => "http://www.openarchives.org/OAI/2.0/" },
"solr_writer.commit_on_close" => "false",
} }
let(:records) { Traject::NokogiriReader.new(StringIO.new(
<<-XML
<?xml version="1.0" encoding="UTF-8"?>
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
<responseDate>2020-03-03T04:16:09Z</responseDate>
<request verb="ListRecords" metadataPrefix="marc21" set="blacklight" from="2020-03-02T20:47:11Z">https://na02.alma.exlibrisgroup.com/view/oai/01TULI_INST/request</request>
<ListRecords>
<record>
<header status="deleted">
<identifier>oai:alma.01TULI_INST:991025803889703811</identifier>
<datestamp>2020-03-03T03:54:35Z</datestamp>
<setSpec>blacklight</setSpec>
<setSpec>rapid_print_journals</setSpec>
<setSpec>blacklight_qa</setSpec>
</header>
</record>
</ListRecords>
</OAI-PMH>
XML
), []).to_a }
describe "extract_xpath attribute bug" do
let(:indexer) { Traject::Indexer::NokogiriIndexer.new(settings) do
to_field "status", extract_xpath("//oai:record/oai:header/@status")
end
}
it "extracts the correct attribute" do
record = records.first
status = indexer.map_record(record)["status"].join
expect(status).to eq("deleted")
end
end
describe "vanilla nokogiri xpath" do
it "extracts the correct attribute" do
record = records.first
status = record.at_xpath("//oai:record/oai:header/@status", settings["nokogiri.namespaces"]).text()
expect(status).to eq("deleted")
end
end
end
@dkinzer
Copy link
Author

dkinzer commented Mar 6, 2020

Failing test for issue traject/traject#241

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment