Skip to content

Commit

Permalink
Merge 214f8fa into 2026f7f
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Oct 3, 2018
2 parents 2026f7f + 214f8fa commit 4aa7cb4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
10 changes: 10 additions & 0 deletions .rubocop_todo.yml
Expand Up @@ -193,6 +193,16 @@ RSpec/ExpectInHook:
Exclude:
- 'spec/dor/update_marc_record_service_spec.rb'

# Offense count: 4
# Configuration parameters: CustomTransform, IgnoreMethods.
RSpec/FilePath:
Exclude:
- 'spec/goobi_spec.rb'
- 'spec/goobi_tag_spec.rb'
- 'spec/registration_response_spec.rb'
- 'spec/service_item_spec.rb'
- 'spec/update_marc_spec.rb'

# Offense count: 141
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Expand Down
5 changes: 4 additions & 1 deletion app/models/dor/goobi_tag.rb
Expand Up @@ -13,7 +13,10 @@ def initialize(p_hash)
end

def to_xml
"<tag name=\"#{name}\" value=\"#{value}\"></tag>"
Nokogiri::XML::Node.new('tag', Nokogiri::XML::Document.new).tap do |node|
node['name'] = name
node['value'] = value
end.to_xml
end
end
end
16 changes: 8 additions & 8 deletions spec/dor/goobi_spec.rb
Expand Up @@ -22,8 +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', '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>')
allow(item).to receive(:tags).and_return(['DPG : Workflow : book_workflow & stuff', 'Process : Content Type : Book', 'LAB : MAPS'])
expect(@goobi.goobi_xml_tags).to eq('<tag name="DPG" value="Workflow : book_workflow &amp; stuff"/><tag name="Process" value="Content Type : Book"/><tag name="LAB" value="MAPS"/>')
expect(@goobi.xml_request).to be_equivalent_to <<-END
<stanfordCreationRequest>
<objectId>#{pid}</objectId>
Expand All @@ -40,17 +40,17 @@
<goobiWorkflow>goobi_workflow</goobiWorkflow>
<ocr>false</ocr>
<tags>
<tag name="DPG" value="Workflow : book_workflow"></tag>
<tag name="Process" value="Content Type : Book"></tag>
<tag name="LAB" value="MAPS"></tag>
<tag name="DPG" value="Workflow : book_workflow &amp; stuff"/>
<tag name="Process" value="Content Type : Book"/>
<tag name="LAB" value="MAPS"/>
</tags>
</stanfordCreationRequest>
END
end

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.goobi_xml_tags).to eq('<tag name="DPG" value="Workflow : book_workflow"/><tag name="DPG" value="OCR : TRUE"/>')
expect(@goobi.xml_request).to be_equivalent_to <<-END
<stanfordCreationRequest>
<objectId>#{pid}</objectId>
Expand All @@ -67,8 +67,8 @@
<goobiWorkflow>goobi_workflow</goobiWorkflow>
<ocr>true</ocr>
<tags>
<tag name="DPG" value="Workflow : book_workflow"></tag>
<tag name="DPG" value="OCR : TRUE"></tag>
<tag name="DPG" value="Workflow : book_workflow"/>
<tag name="DPG" value="OCR : TRUE"/>
</tags>
</stanfordCreationRequest>
END
Expand Down
13 changes: 13 additions & 0 deletions spec/goobi_tag_spec.rb
@@ -0,0 +1,13 @@
require 'rails_helper'

RSpec.describe Dor::GoobiTag do
it 'encodes a tag as XML' do
goobi_tag = described_class.new(name: 'tag_name', value: 'tag value')
expect(goobi_tag.to_xml).to eq('<tag name="tag_name" value="tag value"/>')
end

it 'encodes a tag as XML with special characters' do
goobi_tag = described_class.new(name: 'tag_name > and odd characters', value: 'tag value & other things')
expect(goobi_tag.to_xml).to eq('<tag name="tag_name &gt; and odd characters" value="tag value &amp; other things"/>')
end
end

0 comments on commit 4aa7cb4

Please sign in to comment.