-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor empty_subfield_fix for memory usage (#119)
- Loading branch information
1 parent
c50dec2
commit 98d24b8
Showing
2 changed files
with
47 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'nokogiri' | ||
require 'marc' | ||
require 'marc_cleanup' | ||
require 'byebug' | ||
|
||
RSpec.describe 'empty_subfield_fix method' do | ||
describe 'when there are empty subfields' do | ||
it 'removes them' do | ||
original_hash = { 'fields' => [{ | ||
'020' => { 'indicator1' => ' ', | ||
'indicator2' => ' ', | ||
'subfields' => [{ 'a' => '9780316458759', | ||
'b' => nil, | ||
'c' => '', | ||
'd' => nil, | ||
'e' => '', | ||
'z' => '' }] } | ||
}, { | ||
'035' => { 'indicator1' => ' ', | ||
'indicator2' => ' ', | ||
'subfields' => [{ 'a' => 'ocn123', | ||
'b' => nil, | ||
'c' => '4567' }] } | ||
}] } | ||
original = MARC::Record.new_from_hash(original_hash) | ||
|
||
expected_hash = { 'fields' => [{ | ||
'020' => { 'indicator1' => ' ', | ||
'indicator2' => ' ', | ||
'subfields' => [{ 'a' => '9780316458759' }] } | ||
}, { | ||
'035' => { 'indicator1' => ' ', | ||
'indicator2' => ' ', | ||
'subfields' => [{ 'a' => 'ocn123', | ||
'c' => '4567' }] } | ||
}] } | ||
expected = MARC::Record.new_from_hash(expected_hash) | ||
|
||
fixed = MarcCleanup.empty_subfield_fix(original) | ||
expect(fixed).to eq(expected) | ||
end | ||
end | ||
end |