Skip to content

Commit

Permalink
no longer accept schema 2.1 or 2.2. #197
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Feb 5, 2019
1 parent 9b91260 commit 1bae585
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
5 changes: 5 additions & 0 deletions lib/xml_schema_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def get_valid_kernel(sv)
def validate_each(record, attribute, value)
kernel = get_valid_kernel(record.schema_version)
return false unless kernel.present?

if ["http://datacite.org/schema/kernel-2.2", "http://datacite.org/schema/kernel-2.2"].include?(record.schema_version)
record.errors[:xml] << "Schema #{record.schema_version} is no longer supported"
return false
end

filepath = Bundler.rubygems.find_name('bolognese').first.full_gem_path + "/resources/#{kernel}/metadata.xsd"
schema = Nokogiri::XML::Schema(open(filepath))
Expand Down
42 changes: 12 additions & 30 deletions spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -393,18 +393,12 @@
end
before { patch "/dois/10.14454/10703", params: valid_attributes.to_json, headers: headers }

it 'updates the record' do
expect(json.dig('data', 'attributes', 'doi')).to eq("10.14454/10703")
expect(json.dig('data', 'attributes', 'url')).to eq("http://www.bl.uk/pdf/patspec.pdf")
expect(json.dig('data', 'attributes', 'titles')).to eq([{"title"=>"Właściwości rzutowań podprzestrzeniowych"}, {"title"=>"Translation of Polish titles", "titleType"=>"TranslatedTitle"}])
expect(json.dig('data', 'attributes', 'schemaVersion')).to eq("http://datacite.org/schema/kernel-2.2")

xml = Maremma.from_xml(Base64.decode64(json.dig('data', 'attributes', 'xml'))).fetch("resource", {})
expect(xml.dig("titles", "title")).to eq(["Właściwości rzutowań podprzestrzeniowych", {"__content__"=>"Translation of Polish titles", "titleType"=>"TranslatedTitle"}])
it 'returns status code 422' do
expect(response).to have_http_status(422)
end

it 'returns status code 201' do
expect(response).to have_http_status(201)
it 'returns an error that schema is no longer supported' do
expect(json.fetch('errors', nil)).to eq([{"source"=>"xml", "title"=>"Schema http://datacite.org/schema/kernel-2.2 is no longer supported"}])
end
end

Expand Down Expand Up @@ -1016,18 +1010,12 @@

before { post '/dois', params: valid_attributes.to_json, headers: headers }

it 'creates a Doi' do
expect(json.dig('data', 'attributes', 'doi')).to eq("10.14454/10703")
expect(json.dig('data', 'attributes', 'titles')).to eq([{"title"=>"LAMMPS Data-File Generator"}])
expect(json.dig('data', 'attributes', 'schemaVersion')).to eq("http://datacite.org/schema/kernel-2.2")
end

it 'returns status code 201' do
expect(response).to have_http_status(201)
it 'returns status code 422' do
expect(response).to have_http_status(422)
end

it 'sets state to findable' do
expect(json.dig('data', 'attributes', 'state')).to eq("findable")
it 'returns an error that schema is no longer supported' do
expect(json.fetch('errors', nil)).to eq([{"source"=>"xml", "title"=>"Schema http://datacite.org/schema/kernel-2.2 is no longer supported"}])
end
end

Expand Down Expand Up @@ -1082,18 +1070,12 @@

before { post '/dois', params: valid_attributes.to_json, headers: headers }

it 'creates a Doi' do
expect(json.dig('data', 'attributes', 'doi')).to eq("10.14454/10703")
expect(json.dig('data', 'attributes', 'titles')).to eq([{"title"=>"LAMMPS Data-File Generator"}])
expect(json.dig('data', 'attributes', 'schemaVersion')).to eq("http://datacite.org/schema/kernel-2.2")
end

it 'returns status code 201' do
expect(response).to have_http_status(201)
it 'returns status code 422' do
expect(response).to have_http_status(422)
end

it 'sets state to findable' do
expect(json.dig('data', 'attributes', 'state')).to eq("findable")
it 'returns an error that schema is no longer supported' do
expect(json.fetch('errors', nil)).to eq([{"source"=>"xml", "title"=>"Schema http://datacite.org/schema/kernel-2.2 is no longer supported"}])
end
end

Expand Down

0 comments on commit 1bae585

Please sign in to comment.