Skip to content

Commit 560d5d8

Browse files
authored
Adding fixes for #1439 (#1441)
1 parent 8a721b3 commit 560d5d8

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

app/models/paper.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,14 @@ def scholar_authors
216216

217217
def bibtex_authors
218218
return nil unless published?
219-
metadata['paper']['authors'].collect {|a| "#{a['given_name']} #{a['middle_name']} #{a['last_name']}".squish}.join(' and ')
219+
metadata['paper']['authors'].collect do |a|
220+
given_parts = [a['given_name'], a['middle_name']].compact.join(' ')
221+
if given_parts.present?
222+
"#{a['last_name']}, #{given_parts}"
223+
else
224+
a['last_name']
225+
end
226+
end.join(' and ')
220227
end
221228

222229
def bibtex_key

spec/models/paper_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,4 +508,42 @@
508508
expect(@paper.reload.track).to eq(@track_2)
509509
end
510510
end
511+
512+
describe "#bibtex_authors" do
513+
it "should format author names correctly for BibTeX" do
514+
paper = create(:accepted_paper)
515+
paper.metadata['paper']['authors'] = [
516+
{'given_name' => 'Rhoslyn', 'last_name' => 'Roebuck Williams'},
517+
{'given_name' => 'Harry', 'middle_name' => 'J.', 'last_name' => 'Stroud'},
518+
{'given_name' => 'Ludwig', 'last_name' => 'van Beethoven'}
519+
]
520+
paper.save!
521+
522+
expected_bibtex = "Roebuck Williams, Rhoslyn and Stroud, Harry J. and van Beethoven, Ludwig"
523+
expect(paper.bibtex_authors).to eq(expected_bibtex)
524+
end
525+
526+
it "should handle authors with no given name" do
527+
paper = create(:accepted_paper)
528+
paper.metadata['paper']['authors'] = [
529+
{'given_name' => 'John', 'last_name' => 'Smith'},
530+
{'last_name' => 'Collective'}
531+
]
532+
paper.save!
533+
534+
expected_bibtex = "Smith, John and Collective"
535+
expect(paper.bibtex_authors).to eq(expected_bibtex)
536+
end
537+
538+
it "should handle authors with only middle name" do
539+
paper = create(:accepted_paper)
540+
paper.metadata['paper']['authors'] = [
541+
{'middle_name' => 'J.', 'last_name' => 'Smith'}
542+
]
543+
paper.save!
544+
545+
expected_bibtex = "Smith, J."
546+
expect(paper.bibtex_authors).to eq(expected_bibtex)
547+
end
548+
end
511549
end

0 commit comments

Comments
 (0)