Created
March 6, 2020 13:29
-
-
Save dkinzer/88f44606986a2cb787f78fc6f60d0035 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Failing test for issue traject/traject#241