Skip to content

Commit

Permalink
Merge 275569a into 94cfa83
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Oct 3, 2018
2 parents 94cfa83 + 275569a commit 4312767
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions .rubocop_todo.yml
Expand Up @@ -199,6 +199,7 @@ RSpec/ExpectInHook:
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'
Expand Down
2 changes: 1 addition & 1 deletion app/models/dor/goobi_tag.rb
Expand Up @@ -13,7 +13,7 @@ def initialize(p_hash)
end

def to_xml
"<tag name=\"#{name}\" value=\"#{value}\"></tag>"
"<tag name=\"#{name.encode(xml: :text)}\" value=\"#{value.encode(xml: :text)}\"></tag>"
end
end
end
6 changes: 3 additions & 3 deletions spec/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><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 +40,7 @@
<goobiWorkflow>goobi_workflow</goobiWorkflow>
<ocr>false</ocr>
<tags>
<tag name="DPG" value="Workflow : book_workflow"></tag>
<tag name="DPG" value="Workflow : book_workflow &amp; stuff"></tag>
<tag name="Process" value="Content Type : Book"></tag>
<tag name="LAB" value="MAPS"></tag>
</tags>
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"></tag>')
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"></tag>')
end
end

0 comments on commit 4312767

Please sign in to comment.