require 'spec_helper'
module Datacite
module Mapping
describe Description do
describe '#load_from_xml' do
it 'reads XML' do
xml_text = '
XML example of all DataCite Metadata Schema v3.1 properties.
'
desc = Description.parse_xml(xml_text)
expected_lang = 'en-us'
expected_type = DescriptionType::ABSTRACT
expected_value = 'XML example of all DataCite Metadata Schema v3.1 properties.'
expect(desc.language).to eq(expected_lang)
expect(desc.type).to eq(expected_type)
expect(desc.value.strip).to eq(expected_value)
end
it 'handles escaped HTML' do
xml_text = '
<p>This is HTML text</p><p><small>despite the advice in the standard</small></p>
'
desc = Description.parse_xml(xml_text)
expected_value = '
This is HTML text
despite the advice in the standard
'
expect(desc.value).to eq(expected_value)
end
it 'strips extra whitespace' do
xml_text = '
This is the value
'
desc = Description.parse_xml(xml_text)
expect(desc.value).to eq('This is the value')
end
it 'allows un-escaped
and
tags' do
xml_text = '
I am an
abstract
full
of <br/>s
'
desc = Description.parse_xml(xml_text)
expected_value = 'I am an
abstract
full
of
s'
expect(desc.value.strip).to eq(expected_value)
end
end
describe '#save_to_xml' do
it 'writes XML' do
desc = Description.new(language: 'en-us', type: DescriptionType::ABSTRACT, value: 'foo')
expected_xml = 'foo'
expect(desc.save_to_xml).to be_xml(expected_xml)
end
it 'escapes HTML' do
desc = Description.new(type: DescriptionType::ABSTRACT, value: 'This is HTML text
')
expected_xml = '<p>This is HTML text</p>'
expect(desc.save_to_xml).to be_xml(expected_xml)
end
it 'preserves
and
tags' do
desc = Description.new(type: DescriptionType::ABSTRACT, value: '
<br/> abstract
full
of
s')
expected_xml = '
<br/> abstract
full
of
s'
expect(desc.save_to_xml).to be_xml(expected_xml)
end
end
it 'round-trips to XML' do
xml_text = 'foo'
desc = Description.parse_xml(xml_text)
expect(desc.save_to_xml).to be_xml(xml_text)
end
it 'un-escapes
tags when round-tripping' do
xml_text = '
<br/> abstract
full
of
s'
desc = Description.parse_xml(xml_text)
expected_xml = '
abstract
full
of
s'
expect(desc.save_to_xml).to be_xml(expected_xml)
end
end
end
end