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

Always report bibtex entries in DOI checker #101

Merged
merged 4 commits into from
Mar 6, 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
10 changes: 7 additions & 3 deletions app/lib/doi_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ def check_dois
# If there's no DOI present, check Crossref to see if we can find a candidate DOI for this entry.
elsif entry.has_field?('title')
candidate_doi = crossref_lookup(entry.title.value)
truncated_title = entry.title.to_s[0,50]
truncated_title += "..." if truncated_title.length < entry.title.to_s.length
if candidate_doi == "CROSSREF-ERROR"
truncated_title = entry.title.to_s[0,50]
truncated_title += "..." if truncated_title.length < entry.title.to_s.length
doi_summary[:missing].push("Errored finding suggestions for \"#{truncated_title}\", please try later")
elsif candidate_doi
doi_summary[:missing].push("#{candidate_doi} may be a valid DOI for title: #{entry.title}")
doi_summary[:missing].push("#{candidate_doi} may be a valid DOI for title: #{truncated_title}")
else
doi_summary[:missing].push("No DOI given, and none found for title: #{truncated_title}")
end
else
doi_summary[:missing].push("Entry without DOI or title found")
end
end
end
Expand Down
19 changes: 15 additions & 4 deletions spec/doi_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@
expect(doi_summary[:missing][0]).to eq("Errored finding suggestions for \"#{expected_title}\", please try later")
end

it "should ignore entries no DOI and no crossref alternative" do
missing_doi = BibTeX::Entry.new({title: "No DOI"})
it "should report entries with no DOI and no crossref alternative as missing DOIs" do
title = "No DOI"
missing_doi = BibTeX::Entry.new({title: title})
doi_checker = DOIChecker.new([missing_doi])

expect(doi_checker).to receive(:crossref_lookup).with("No DOI").and_return(nil)
Expand All @@ -92,7 +93,17 @@

expect(doi_summary[:ok]).to be_empty
expect(doi_summary[:invalid]).to be_empty
expect(doi_summary[:missing]).to be_empty
expect(doi_summary[:missing][0]).to eq("No DOI given, and none found for title: #{title}")
end

it "should report entries with no DOI or title as missing both" do
entry = BibTeX::Entry.new(journal: "A Well Respected Journal")
doi_checker = DOIChecker.new([entry])

doi_summary = doi_checker.check_dois
expect(doi_summary[:ok]).to be_empty
expect(doi_summary[:invalid]).to be_empty
expect(doi_summary[:missing][0]).to eq("Entry without DOI or title found")
end
end

Expand Down Expand Up @@ -203,4 +214,4 @@
end
end

end
end