Skip to content

Commit

Permalink
Merge branch 'main' into joss
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanxu committed Mar 6, 2024
2 parents 8b4c3f2 + 946effa commit 5716aa9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
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

0 comments on commit 5716aa9

Please sign in to comment.