Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rescue exception when collection is missing #6667

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/helpers/hyrax/hyrax_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ def collection_title_by_id(id)
solr_field = solr_docs.first["title_tesim"]
return nil if solr_field.nil?
solr_field.first
rescue Blacklight::Exceptions::RecordNotFound
nil
end

##
Expand Down
5 changes: 5 additions & 0 deletions spec/helpers/hyrax_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ def new_state
allow(repository).to receive(:find).with("abcd12345").and_return(solr_response)
allow(repository).to receive(:find).with("efgh67890").and_return(bad_solr_response)
allow(repository).to receive(:find).with("bad-id").and_return(empty_solr_response)
allow(repository).to receive(:find).with("error-id").and_raise(Blacklight::Exceptions::RecordNotFound)
end

it "returns the first title of the collection" do
Expand All @@ -388,6 +389,10 @@ def new_state
it "returns nil if collection not found" do
expect(helper.collection_title_by_id("bad-id")).to eq nil
end

it "returns nil if RecordNotFound is raised" do
expect(helper.collection_title_by_id("error-id")).to eq nil
end
end

describe "#thumbnail_label_for" do
Expand Down