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

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

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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