Skip to content

Commit

Permalink
Don't fail on citations when the 700 only has punctuation and spaces (#…
Browse files Browse the repository at this point in the history
…117)

* Don't fail on citations when the 700 only has punctuation and spaces

Co-authored-by: Christina Chortaria <christinach@users.noreply.github.com>
Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>

* Incorporate feedback from review

Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>
Co-authored-by: Christina Chortaria <christinach@users.noreply.github.com>

---------

Co-authored-by: Christina Chortaria <christinach@users.noreply.github.com>
Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>
  • Loading branch information
3 people committed Mar 8, 2024
1 parent 7c27d41 commit f5562ce
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/concerns/blacklight/marc/document_export.rb
Expand Up @@ -561,6 +561,7 @@ def get_publication_data(record)

def abbreviate_name(name)
name_parts = name.split(", ")
return "" if name_parts.empty?
first_name_parts = name_parts.last.split(" ")
temp_name = name_parts.first + ", " + first_name_parts.first[0,1] + "."
first_name_parts.shift
Expand All @@ -570,7 +571,7 @@ def abbreviate_name(name)

def name_reverse(name)
name = clean_end_punctuation(name)
return name unless name =~ /,/
return name if name == ", " || !(name =~ /,/)
temp_name = name.split(", ")
return temp_name.last + " " + temp_name.first
end
Expand Down
30 changes: 30 additions & 0 deletions spec/models/concerns/blacklight/marc/document_export_spec.rb
Expand Up @@ -26,6 +26,19 @@ def to_marc
end
end

class MockClassInvalid700
include Blacklight::Marc::DocumentExport

def to_marc
fields = [
{ "100" => { "subfields" => [{ "a" => "Borja, Ronaldo I." }]}},
{ "245" => { "ind1" => " ", "ind2" => " ", "subfields" => [{ "a" => "Plasticity : ", "b" => "modeling & computation /", "c" => "Ronaldo I. Borja." }] } },
{ "700" => { "ind1" => " ", "ind2" => " ", "subfields" => [{ "a" => ", ." }] } }
]
MARC::Record.new_from_hash('fields' => fields)
end
end

RSpec.describe Blacklight::Marc::DocumentExport do
describe 'export citiations from 260 field' do
it 'exports citations in apa format' do
Expand Down Expand Up @@ -60,4 +73,21 @@ def to_marc
expect(MockClass264.new.export_as_chicago_citation_txt).to include('Berlin: Springer,')
end
end

describe 'when the 700 only has punctuation and spaces' do
it 'exports citations in apa format' do
expect(MockClassInvalid700.new.export_as_apa_citation_txt).to include('Borja, R. I')
expect(MockClassInvalid700.new.export_as_apa_citation_txt).to include('Plasticity')
end

it 'exports citations in mla format' do
expect(MockClassInvalid700.new.export_as_mla_citation_txt).to include('Borja, Ronaldo I')
expect(MockClassInvalid700.new.export_as_mla_citation_txt).to include('Plasticity')
end

it 'exports citations in Chicago format' do
expect(MockClassInvalid700.new.export_as_chicago_citation_txt).to include('Borja, Ronaldo I')
expect(MockClassInvalid700.new.export_as_chicago_citation_txt).to include('Plasticity')
end
end
end

0 comments on commit f5562ce

Please sign in to comment.