From 32c3b5a9015992efed728eff97cdd9e79f003c03 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Tue, 21 May 2024 17:22:04 -0400 Subject: [PATCH] solr document handles non loc_id subject ids --- lib/authority_browse/solr_document/authority_graph.rb | 4 ++-- spec/authority_browse/names_spec.rb | 3 --- spec/authority_browse/solr_document/subjects_spec.rb | 6 +++++- spec/authority_browse/subjects_spec.rb | 3 --- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/authority_browse/solr_document/authority_graph.rb b/lib/authority_browse/solr_document/authority_graph.rb index 8481b7b9..f239ee5f 100644 --- a/lib/authority_browse/solr_document/authority_graph.rb +++ b/lib/authority_browse/solr_document/authority_graph.rb @@ -31,11 +31,11 @@ def term first[:label] end - # Library of Congress ID + # Library of Congress ID if the id is a valid one # # @return [String] def loc_id - first[:id] + first[:id] if first[:id].match?("loc.gov") end # @return [Integer] diff --git a/spec/authority_browse/names_spec.rb b/spec/authority_browse/names_spec.rb index f383057d..8f28e46b 100644 --- a/spec/authority_browse/names_spec.rb +++ b/spec/authority_browse/names_spec.rb @@ -62,7 +62,6 @@ expect(file_contents).to eq([ { id: "first\u001fname", - loc_id: "id1", browse_field: "name", term: "First", count: 1, @@ -71,7 +70,6 @@ }.to_json + "\n", { id: "second\u001fname", - loc_id: "id2", browse_field: "name", term: "Second", count: 2, @@ -79,7 +77,6 @@ }.to_json + "\n", { id: "third\u001fname", - loc_id: "id3", browse_field: "name", term: "Third", count: 3, diff --git a/spec/authority_browse/solr_document/subjects_spec.rb b/spec/authority_browse/solr_document/subjects_spec.rb index 71b6030a..e64673c3 100644 --- a/spec/authority_browse/solr_document/subjects_spec.rb +++ b/spec/authority_browse/solr_document/subjects_spec.rb @@ -72,9 +72,13 @@ end end context "#loc_id" do - it "returns the loc_id" do + it "returns the loc_id when the id is a loc id" do expect(subject.loc_id).to eq(counterpoint_id) end + it "returns nil when it's not" do + @subject[0][:id] = "9912351598" + expect(subject.loc_id).to be_nil + end end context "#term" do it "has the expected term" do diff --git a/spec/authority_browse/subjects_spec.rb b/spec/authority_browse/subjects_spec.rb index 7331dac9..306f3619 100644 --- a/spec/authority_browse/subjects_spec.rb +++ b/spec/authority_browse/subjects_spec.rb @@ -78,7 +78,6 @@ expect(file_contents).to eq([ { id: "first\u001fsubject", - loc_id: "id1", browse_field: "subject", term: "First", count: 1, @@ -88,7 +87,6 @@ }.to_json + "\n", { id: "second\u001fsubject", - loc_id: "id2", browse_field: "subject", term: "Second", count: 2, @@ -96,7 +94,6 @@ }.to_json + "\n", { id: "third\u001fsubject", - loc_id: "id3", browse_field: "subject", term: "Third", count: 3,