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 1 commit
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
2 changes: 2 additions & 0 deletions app/models/concerns/blacklight/marc/document_export.rb
Original file line number Diff line number Diff line change
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 @@ -572,6 +573,7 @@ def name_reverse(name)
name = clean_end_punctuation(name)
return name unless name =~ /,/
temp_name = name.split(", ")
return name if temp_name.empty?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this handle some case other than name = ", "? If so, can we just look for that on line 574? Otherwise, would you mind adding some comments to explain what we're looking for?

return temp_name.last + " " + temp_name.first
end
end
30 changes: 30 additions & 0 deletions spec/models/concerns/blacklight/marc/document_export_spec.rb
Original file line number Diff line number Diff line change
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