Skip to content

Commit

Permalink
Merge 569cd94 into 94cfa83
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Oct 3, 2018
2 parents 94cfa83 + 569cd94 commit 56696cf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
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
15 changes: 15 additions & 0 deletions spec/goobi_tag_spec.rb
@@ -0,0 +1,15 @@
require 'rails_helper'

RSpec.describe Dor::GoobiTag do

it 'encodes a tag as XML' do
goobi_tag = Dor::GoobiTag.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 = Dor::GoobiTag.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 56696cf

Please sign in to comment.