Skip to content

Commit

Permalink
pull out tags into new method; refactoring of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Aug 24, 2018
1 parent d0010d3 commit 88f3122
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
10 changes: 7 additions & 3 deletions app/models/dor/goobi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ def register
# rubocop:enable Metrics/LineLength
end

def goobi_xml_tags
goobi_tag_list.map do |tag_name, tag_value|
"<tag name=\"#{tag_name}\" value=\"#{tag_value}\"></tag>"
end.join
end

def xml_request
<<-END
<stanfordCreationRequest>
Expand All @@ -31,9 +37,7 @@ def xml_request
<sdrWorkflow>#{Dor::Config.goobi.dpg_workflow_name}</sdrWorkflow>
<goobiWorkflow>#{goobi_workflow_name}</goobiWorkflow>
<ocr>#{goobi_ocr_tag_present?}</ocr>
<tags>
#{goobi_tag_list.map { |tag_name, tag_value| "<tag name=\"#{tag_name}\" value=\"#{tag_value}\"></tag>" }.join("\n")}
</tags>
<tags>#{goobi_xml_tags}</tags>
</stanfordCreationRequest>
END
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/dor/service_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def goobi_ocr_tag_present?

# returns an array of arrays, each element contains an array of [name, value] of DOR object tags in the format expected to pass to Goobi
# the name of the tag is the first namespace part of the tag (before first colon), value of the tag is everything after this
# @return [Array]
# @return [Array] of arrays, each element is a [name, value] pair of tags derived from the DOR object, e.g. [['Tag1', 'Value1'], ['Tag2', 'Value2']]
def goobi_tag_list
@druid_obj.tags.map do |tag|
tag_split = tag.split(':', 2).map(&:strip) # only split on the first colon
Expand Down
26 changes: 6 additions & 20 deletions spec/goobi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
end

it 'creates the correct xml request without ocr tag present' do
allow(item).to receive(:tags).and_return(['DPG : Workflow : book_workflow', 'Process : Content Type : Book (flipbook, ltr)', 'LAB : MAPS'])
allow(item).to receive(:tags).and_return(['DPG : Workflow : book_workflow', 'Process : Content Type : Book', 'LAB : MAPS'])
expect(@goobi.goobi_xml_tags).to eq('<tag name="DPG" value="Workflow : book_workflow"></tag><tag name="Process" value="Content Type : Book"></tag><tag name="LAB" value="MAPS"></tag>')
expect(@goobi.xml_request).to be_equivalent_to <<-END
<stanfordCreationRequest>
<objectId>#{pid}</objectId>
Expand All @@ -40,7 +41,7 @@
<ocr>false</ocr>
<tags>
<tag name="DPG" value="Workflow : book_workflow"></tag>
<tag name="Process" value="Content Type : Book (flipbook, ltr)"></tag>
<tag name="Process" value="Content Type : Book"></tag>
<tag name="LAB" value="MAPS"></tag>
</tags>
</stanfordCreationRequest>
Expand All @@ -49,6 +50,7 @@

it 'creates the correct xml request with ocr tag present' do
allow(item).to receive(:tags).and_return(['DPG : Workflow : book_workflow', 'DPG : OCR : TRUE'])
expect(@goobi.goobi_xml_tags).to eq('<tag name="DPG" value="Workflow : book_workflow"></tag><tag name="DPG" value="OCR : TRUE"></tag>')
expect(@goobi.xml_request).to be_equivalent_to <<-END
<stanfordCreationRequest>
<objectId>#{pid}</objectId>
Expand All @@ -74,24 +76,8 @@

it 'creates the correct xml request with no tags present' do
allow(item).to receive(:tags).and_return([])
expect(@goobi.xml_request).to be_equivalent_to <<-END
<stanfordCreationRequest>
<objectId>#{pid}</objectId>
<objectType>item</objectType>
<sourceID>some_source_id</sourceID>
<title>Object Title</title>
<contentType>book</contentType>
<project>Project Name</project>
<catkey>ckey_12345</catkey>
<barcode>barcode_12345</barcode>
<collectionId>druid:oo000oo0001</collectionId>
<collectionName>collection name</collectionName>
<sdrWorkflow>#{Dor::Config.goobi.dpg_workflow_name}</sdrWorkflow>
<goobiWorkflow>goobi_workflow</goobiWorkflow>
<ocr>false</ocr>
<tags></tags>
</stanfordCreationRequest>
END
expect(@goobi.goobi_xml_tags).to eq('')
expect(@goobi.xml_request).to include('<tags></tags>')
end

it 'makes a call to the goobi server with the appropriate xml params' do
Expand Down
20 changes: 10 additions & 10 deletions spec/service_item_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rails_helper'

RSpec.describe Dor::ServiceItem do
describe '.catkey' do
describe '#catkey' do
it 'returns catkey from a valid identityMetadata' do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_1)
expect(@si.ckey).to eq('8832162')
Expand All @@ -21,7 +21,7 @@
end
end

describe '.goobi_workflow_name' do
describe '#goobi_workflow_name' do
before do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_1)
end
Expand All @@ -42,7 +42,7 @@
end
end

describe '.goobi_tag_list' do
describe '#goobi_tag_list' do
before do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_1)
end
Expand All @@ -63,7 +63,7 @@
end
end

describe '.goobi_ocr_tag_present?' do
describe '#goobi_ocr_tag_present?' do
before do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_1)
end
Expand All @@ -84,7 +84,7 @@
end
end

describe '.object_type' do
describe '#object_type' do
it 'returns object_type from a valid identityMetadata' do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_1)
expect(@si.object_type).to eq('item')
Expand All @@ -96,7 +96,7 @@
end
end

describe '.project_name' do
describe '#project_name' do
before do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_1)
end
Expand All @@ -112,7 +112,7 @@
end
end

describe '.collection_name and id' do
describe '#collection_name and id' do
before do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_1)
end
Expand All @@ -132,7 +132,7 @@
end
end

describe '.barcode' do
describe '#barcode' do
it 'returns barcode from a valid identityMetadata' do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_1)
expect(@si.barcode).to eq('36105216275185')
Expand All @@ -144,7 +144,7 @@
end
end

describe '.content_type' do
describe '#content_type' do
before do
druid = 'bb111bb2222'
@d = Dor::Item.new(:pid => druid)
Expand Down Expand Up @@ -174,7 +174,7 @@
end
end

describe '.thumb' do
describe '#thumb' do
it 'returns thumb from a valid contentMetadata' do
druid = 'bb111bb2222'
d = Dor::Item.new(:pid => druid)
Expand Down

0 comments on commit 88f3122

Please sign in to comment.