-
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.
Test methods for 040 field and subfields (#120)
* Test methods for 040 field and subfields * Test 040 methods further * Update multiple_no_040b? * Update multiple_no_040b? * Update fix_040b * Update fix_040b * Update fix_040b * Update fix_040b * Update missing_040c? test
- Loading branch information
1 parent
98d24b8
commit ff415de
Showing
1 changed file
with
105 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
require 'nokogiri' | ||
require 'marc' | ||
require 'byebug' | ||
require 'marc_cleanup' | ||
|
||
RSpec.describe 'field_040' do | ||
let(:record) { MARC::Record.new_from_hash('fields' => fields, 'leader' => leader) } | ||
let(:leader) { '01104naa a2200289 i 4500' } | ||
|
||
describe 'multiple_no_040?' do | ||
let(:fields) do | ||
[ | ||
{ '001' => '9970534203506421' }, | ||
{ '040' => { 'indicator1' => ' ', | ||
'indicator2' => ' ', | ||
'subfields' => [{ 'a' => 'DLC' }] } }, | ||
{ '040' => { 'indicator1' => ' ', | ||
'indicator2' => ' ', | ||
'subfields' => [{ 'a' => 'DLC' }] } } | ||
] | ||
end | ||
it 'checks if a record has multiple or no 040 fields' do | ||
expect(MarcCleanup.multiple_no_040?(record)).to eq true | ||
end | ||
end | ||
|
||
describe 'multiple_no_040b?' do | ||
let(:fields) do | ||
[ | ||
{ '001' => '9970534203506421' }, | ||
{ '040' => { 'indicator1' => ' ', | ||
'indicator2' => ' ', | ||
'subfields' => [{ 'b' => 'e n g' }]} } | ||
] | ||
end | ||
it 'checks if a record has multiple or no 040 fields' do | ||
expect(MarcCleanup.multiple_no_040b?(record)).to eq false | ||
end | ||
end | ||
|
||
describe 'fix_040b' do | ||
|
||
context "when there is no subfield a" do | ||
let(:fields) do | ||
[ | ||
{ '001' => '9970534203506421' }, | ||
{ '040' => { 'indicator1' => ' ', | ||
'indicator2' => ' ', | ||
'subfields' => [{ 'c' => 'DLC' }]} } | ||
] | ||
end | ||
it 'corrects the 040b' do | ||
expect(MarcCleanup.fix_040b(record)['040']['b']).to eq 'eng' | ||
end | ||
end | ||
|
||
context "when there is one subfield a" do | ||
let(:fields) do | ||
[ | ||
{ '001' => '9970534203506421' }, | ||
{ '040' => { 'indicator1' => ' ', | ||
'indicator2' => ' ', | ||
'subfields' => [{ 'a' => 'DLC' }]} } | ||
] | ||
end | ||
it 'corrects the 040b' do | ||
expect(MarcCleanup.fix_040b(record)['040']['b']).to eq 'eng' | ||
end | ||
end | ||
end | ||
|
||
describe 'missing_040c?' do | ||
|
||
context 'when no there is no subfield c' do | ||
let(:fields) do | ||
[ | ||
{ '001' => '9970534203506421' }, | ||
{ '040' => { 'indicator1' => ' ', | ||
'indicator2' => ' ', | ||
'subfields' => [{ 'a' => 'DLC' }, | ||
{ 'b' => 'eng' }]} } | ||
] | ||
end | ||
it 'checks for subfield c in field 040' do | ||
expect(MarcCleanup.missing_040c?(record)).to eq true | ||
end | ||
end | ||
|
||
context 'when no there is no subfield c' do | ||
let(:fields) do | ||
[ | ||
{ '001' => '9970534203506421' }, | ||
{ '040' => { 'indicator1' => ' ', | ||
'indicator2' => ' ', | ||
'subfields' => [{ 'a' => 'DLC' }, | ||
{ 'b' => 'eng' }, | ||
{ 'c' => 'DLC' }]} } | ||
] | ||
end | ||
it 'checks for subfield c in field 040' do | ||
expect(MarcCleanup.missing_040c?(record)).to eq false | ||
end | ||
end | ||
end | ||
end |