From 1bae585acc39d07a700e3842abe8d7e9cc2f178a Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Wed, 6 Feb 2019 00:42:53 +0100 Subject: [PATCH] no longer accept schema 2.1 or 2.2. #197 --- lib/xml_schema_validator.rb | 5 +++++ spec/requests/dois_spec.rb | 42 +++++++++++-------------------------- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/lib/xml_schema_validator.rb b/lib/xml_schema_validator.rb index 37272c68f..199050630 100644 --- a/lib/xml_schema_validator.rb +++ b/lib/xml_schema_validator.rb @@ -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)) diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index fad5edd90..0ff79cc2b 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -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 @@ -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 @@ -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