From c5f8719294c32857846a9f899d9f59719593a985 Mon Sep 17 00:00:00 2001 From: Beck Davis Date: Thu, 14 Mar 2024 16:34:52 -0400 Subject: [PATCH 1/9] Test methods for 040 field and subfields --- spec/variable_fields/040_spec.rb | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 spec/variable_fields/040_spec.rb diff --git a/spec/variable_fields/040_spec.rb b/spec/variable_fields/040_spec.rb new file mode 100644 index 0000000..3fa488f --- /dev/null +++ b/spec/variable_fields/040_spec.rb @@ -0,0 +1,71 @@ +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' => 'eng' }, + { 'b' => 'fre' }]} } + ] + end + it 'checks if a record has multiple or no 040 fields' do + expect(MarcCleanup.multiple_no_040b?(record)).to eq true + end + end + + describe 'fix_040b' do + let(:fields) do + [ + { '001' => '9970534203506421' }, + { '040' => { 'indicator1' => ' ', + 'indicator2' => ' ', + 'subfields' => [{ 'b' => 'eng' }, + { 'b' => 'fre' }]} } + ] + end + it 'corrects the 040b' do + expect(MarcCleanup.fix_040b(record)['040']['b']).to eq 'eng' + end + end + + describe 'missing_040c?' 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 +end From f898a9e57144671990010c66e12e894ef75da861 Mon Sep 17 00:00:00 2001 From: Beck Davis Date: Thu, 14 Mar 2024 16:46:13 -0400 Subject: [PATCH 2/9] Test 040 methods further --- spec/variable_fields/040_spec.rb | 74 +++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 20 deletions(-) diff --git a/spec/variable_fields/040_spec.rb b/spec/variable_fields/040_spec.rb index 3fa488f..6c4c793 100644 --- a/spec/variable_fields/040_spec.rb +++ b/spec/variable_fields/040_spec.rb @@ -25,32 +25,66 @@ end describe 'multiple_no_040b?' do - let(:fields) do - [ - { '001' => '9970534203506421' }, - { '040' => { 'indicator1' => ' ', - 'indicator2' => ' ', - 'subfields' => [{ 'b' => 'eng' }, - { 'b' => 'fre' }]} } - ] + + context "when there is more than one 040 subfield b" do + let(:fields) do + [ + { '001' => '9970534203506421' }, + { '040' => { 'indicator1' => ' ', + 'indicator2' => ' ', + 'subfields' => [{ 'b' => 'eng' }, + { 'b' => 'fre' }]} } + ] + end + it 'checks if a record has multiple or no 040 fields' do + expect(MarcCleanup.multiple_no_040b?(record)).to eq true + end end - it 'checks if a record has multiple or no 040 fields' do - expect(MarcCleanup.multiple_no_040b?(record)).to eq true + + context "when there is one 040 subfield b" do + let(:fields) do + [ + { '001' => '9970534203506421' }, + { '040' => { 'indicator1' => ' ', + 'indicator2' => ' ', + 'subfields' => [{ 'b' => 'eng' }]} } + ] + end + it 'checks if a record has multiple or no 040 fields' do + expect(MarcCleanup.multiple_no_040b?(record)).to eq false + end end end describe 'fix_040b' do - let(:fields) do - [ - { '001' => '9970534203506421' }, - { '040' => { 'indicator1' => ' ', - 'indicator2' => ' ', - 'subfields' => [{ 'b' => 'eng' }, - { 'b' => 'fre' }]} } - ] + + context 'when there is more than one 040 subfield b' do + let(:fields) do + [ + { '001' => '9970534203506421' }, + { '040' => { 'indicator1' => ' ', + 'indicator2' => ' ', + 'subfields' => [{ 'b' => 'eng' }, + { 'b' => 'fre' }]} } + ] + end + it 'corrects the 040b' do + expect(MarcCleanup.fix_040b(record)['040']['b']).to eq 'eng' + end end - it 'corrects the 040b' do - expect(MarcCleanup.fix_040b(record)['040']['b']).to eq 'eng' + + context 'when there is no 040 subfield b' 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 From 736ac2ea3454968c12fb7ef4841ec61a48a1d039 Mon Sep 17 00:00:00 2001 From: Beck Davis Date: Mon, 18 Mar 2024 09:43:32 -0400 Subject: [PATCH 3/9] Update multiple_no_040b? --- spec/variable_fields/040_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/variable_fields/040_spec.rb b/spec/variable_fields/040_spec.rb index 6c4c793..152647b 100644 --- a/spec/variable_fields/040_spec.rb +++ b/spec/variable_fields/040_spec.rb @@ -47,7 +47,7 @@ { '001' => '9970534203506421' }, { '040' => { 'indicator1' => ' ', 'indicator2' => ' ', - 'subfields' => [{ 'b' => 'eng' }]} } + 'subfields' => [{ 'b' => 'e n g' }]} } ] end it 'checks if a record has multiple or no 040 fields' do From 6f25d6fc0cf2f97f9ceb0fa1c7b6404e66e4046c Mon Sep 17 00:00:00 2001 From: Beck Davis Date: Mon, 18 Mar 2024 09:48:17 -0400 Subject: [PATCH 4/9] Update multiple_no_040b? --- spec/variable_fields/040_spec.rb | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/spec/variable_fields/040_spec.rb b/spec/variable_fields/040_spec.rb index 152647b..d63ca12 100644 --- a/spec/variable_fields/040_spec.rb +++ b/spec/variable_fields/040_spec.rb @@ -26,20 +26,20 @@ describe 'multiple_no_040b?' do - context "when there is more than one 040 subfield b" do - let(:fields) do - [ - { '001' => '9970534203506421' }, - { '040' => { 'indicator1' => ' ', - 'indicator2' => ' ', - 'subfields' => [{ 'b' => 'eng' }, - { 'b' => 'fre' }]} } - ] - end - it 'checks if a record has multiple or no 040 fields' do - expect(MarcCleanup.multiple_no_040b?(record)).to eq true - end - end + # context "when there is more than one 040 subfield b" do + # let(:fields) do + # [ + # { '001' => '9970534203506421' }, + # { '040' => { 'indicator1' => ' ', + # 'indicator2' => ' ', + # 'subfields' => [{ 'b' => 'eng' }, + # { 'b' => 'fre' }]} } + # ] + # end + # it 'checks if a record has multiple or no 040 fields' do + # expect(MarcCleanup.multiple_no_040b?(record)).to eq true + # end + # end context "when there is one 040 subfield b" do let(:fields) do From 0751b5fe8ceb2c9e53e9c44c1cf37a9693c3fe58 Mon Sep 17 00:00:00 2001 From: Beck Davis Date: Mon, 18 Mar 2024 10:05:47 -0400 Subject: [PATCH 5/9] Update fix_040b --- spec/variable_fields/040_spec.rb | 66 ++++++++++++-------------------- 1 file changed, 24 insertions(+), 42 deletions(-) diff --git a/spec/variable_fields/040_spec.rb b/spec/variable_fields/040_spec.rb index d63ca12..ee8ebca 100644 --- a/spec/variable_fields/040_spec.rb +++ b/spec/variable_fields/040_spec.rb @@ -25,53 +25,35 @@ end describe 'multiple_no_040b?' do - - # context "when there is more than one 040 subfield b" do - # let(:fields) do - # [ - # { '001' => '9970534203506421' }, - # { '040' => { 'indicator1' => ' ', - # 'indicator2' => ' ', - # 'subfields' => [{ 'b' => 'eng' }, - # { 'b' => 'fre' }]} } - # ] - # end - # it 'checks if a record has multiple or no 040 fields' do - # expect(MarcCleanup.multiple_no_040b?(record)).to eq true - # end - # end - - context "when there is one 040 subfield b" 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 + 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 more than one 040 subfield b' do - let(:fields) do - [ - { '001' => '9970534203506421' }, - { '040' => { 'indicator1' => ' ', - 'indicator2' => ' ', - 'subfields' => [{ 'b' => 'eng' }, - { 'b' => 'fre' }]} } - ] - end - it 'corrects the 040b' do - expect(MarcCleanup.fix_040b(record)['040']['b']).to eq 'eng' - end - end + # context 'when there is more than one 040 subfield b' do + # let(:fields) do + # [ + # { '001' => '9970534203506421' }, + # { '040' => { 'indicator1' => ' ', + # 'indicator2' => ' ', + # 'subfields' => [{ 'b' => 'eng' }, + # { 'b' => 'fre' }]} } + # ] + # end + # it 'corrects the 040b' do + # expect(MarcCleanup.fix_040b(record)['040']['b']).to eq 'eng' + # end + # end context 'when there is no 040 subfield b' do let(:fields) do From 89a7fb7da7c6beda557eac257555d029a4af8841 Mon Sep 17 00:00:00 2001 From: Beck Davis Date: Mon, 18 Mar 2024 10:11:58 -0400 Subject: [PATCH 6/9] Update fix_040b --- spec/variable_fields/040_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/variable_fields/040_spec.rb b/spec/variable_fields/040_spec.rb index ee8ebca..fa09e14 100644 --- a/spec/variable_fields/040_spec.rb +++ b/spec/variable_fields/040_spec.rb @@ -61,7 +61,7 @@ { '001' => '9970534203506421' }, { '040' => { 'indicator1' => ' ', 'indicator2' => ' ', - 'subfields' => [{ 'a' => 'DLC' }]} } + 'subfields' => [{ 'c' => 'DLC' }]} } ] end it 'corrects the 040b' do From e0683bfd90a9ec5fe6f6b896c84c2c26ffedbc73 Mon Sep 17 00:00:00 2001 From: Beck Davis Date: Mon, 18 Mar 2024 10:12:33 -0400 Subject: [PATCH 7/9] Update fix_040b --- spec/variable_fields/040_spec.rb | 38 +++++++++----------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/spec/variable_fields/040_spec.rb b/spec/variable_fields/040_spec.rb index fa09e14..842125b 100644 --- a/spec/variable_fields/040_spec.rb +++ b/spec/variable_fields/040_spec.rb @@ -39,34 +39,16 @@ end describe 'fix_040b' do - - # context 'when there is more than one 040 subfield b' do - # let(:fields) do - # [ - # { '001' => '9970534203506421' }, - # { '040' => { 'indicator1' => ' ', - # 'indicator2' => ' ', - # 'subfields' => [{ 'b' => 'eng' }, - # { 'b' => 'fre' }]} } - # ] - # end - # it 'corrects the 040b' do - # expect(MarcCleanup.fix_040b(record)['040']['b']).to eq 'eng' - # end - # end - - context 'when there is no 040 subfield b' 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 + 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 From f41a564de3a10e44002182084e1277a7d45aa873 Mon Sep 17 00:00:00 2001 From: Beck Davis Date: Mon, 18 Mar 2024 10:17:45 -0400 Subject: [PATCH 8/9] Update fix_040b --- spec/variable_fields/040_spec.rb | 34 +++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/spec/variable_fields/040_spec.rb b/spec/variable_fields/040_spec.rb index 842125b..c74d782 100644 --- a/spec/variable_fields/040_spec.rb +++ b/spec/variable_fields/040_spec.rb @@ -39,16 +39,32 @@ end describe 'fix_040b' do - let(:fields) do - [ - { '001' => '9970534203506421' }, - { '040' => { 'indicator1' => ' ', - 'indicator2' => ' ', - 'subfields' => [{ 'c' => 'DLC' }]} } - ] + 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 - it 'corrects the 040b' do - expect(MarcCleanup.fix_040b(record)['040']['b']).to eq 'eng' + + 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 From be833e260438ca709a0f46bc34f82b96b3e58297 Mon Sep 17 00:00:00 2001 From: Beck Davis Date: Mon, 18 Mar 2024 10:24:27 -0400 Subject: [PATCH 9/9] Update missing_040c? test --- spec/variable_fields/040_spec.rb | 42 +++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/spec/variable_fields/040_spec.rb b/spec/variable_fields/040_spec.rb index c74d782..3b17e1b 100644 --- a/spec/variable_fields/040_spec.rb +++ b/spec/variable_fields/040_spec.rb @@ -16,7 +16,7 @@ 'subfields' => [{ 'a' => 'DLC' }] } }, { '040' => { 'indicator1' => ' ', 'indicator2' => ' ', - 'subfields' => [{ 'a' => 'DLC' }] } }, + 'subfields' => [{ 'a' => 'DLC' }] } } ] end it 'checks if a record has multiple or no 040 fields' do @@ -39,6 +39,7 @@ end describe 'fix_040b' do + context "when there is no subfield a" do let(:fields) do [ @@ -69,17 +70,36 @@ end describe 'missing_040c?' do - let(:fields) do - [ - { '001' => '9970534203506421' }, - { '040' => { 'indicator1' => ' ', - 'indicator2' => ' ', - 'subfields' => [{ 'a' => 'DLC' }, - { 'b' => 'eng' }]} }, - ] + + 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 - it 'checks for subfield c in field 040' do - expect(MarcCleanup.missing_040c?(record)).to eq true + + 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