From bba2e934b9cde3d92e032df9966c52fa1fb6e2e7 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Wed, 10 Apr 2019 22:03:10 +0200 Subject: [PATCH] affiliation should be array. datacite/bolognese#57 --- Gemfile.lock | 4 +- app/controllers/dois_controller.rb | 4 +- spec/requests/dois_spec.rb | 73 ++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a919b206f..ae7d0359d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -98,7 +98,7 @@ GEM latex-decode (~> 0.0) binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) - bolognese (1.1.8) + bolognese (1.1.11) activesupport (>= 4.2.5, < 6) benchmark_methods (~> 0.7) bibtex-ruby (~> 4.1) @@ -121,7 +121,7 @@ GEM rdf-rdfxml (~> 2.0) rdf-turtle (~> 2.2) thor (~> 0.19) - bootsnap (1.4.2) + bootsnap (1.4.3) msgpack (~> 1.0) builder (3.2.3) byebug (11.0.1) diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index b3cba16e3..5c518cbb2 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -513,9 +513,9 @@ def safe_params :should_validate, :client, :creators, - { creators: [:nameType, { nameIdentifiers: [:nameIdentifier, :nameIdentifierScheme, :schemeUri] }, :name, :givenName, :familyName, :affiliation, :lang] }, + { creators: [:nameType, { nameIdentifiers: [:nameIdentifier, :nameIdentifierScheme, :schemeUri] }, :name, :givenName, :familyName, :affiliation, { affiliation: [] }, :lang] }, :contributors, - { contributors: [:nameType, { nameIdentifiers: [:nameIdentifier, :nameIdentifierScheme, :schemeUri] }, :name, :givenName, :familyName, :affiliation, :contributorType, :lang] }, + { contributors: [:nameType, { nameIdentifiers: [:nameIdentifier, :nameIdentifierScheme, :schemeUri] }, :name, :givenName, :familyName, :affiliation, { affiliation: [] }, :contributorType, :lang] }, :identifiers, { identifiers: [:identifier, :identifierType] }, :relatedIdentifiers, diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index 38dd77f48..603c66ea3 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -1982,6 +1982,79 @@ end end + context 'update multiple affiliations' do + let(:creators) { [{ "name"=>"Ollomi, Benjamin", "affiliation" => ["Cambridge University", "EMBL-EBI"] }] } + let(:update_attributes) do + { + "data" => { + "type" => "dois", + "attributes" => { + "creators" => creators + } + } + } + end + + before { patch "/dois/#{doi.doi}", params: update_attributes.to_json, headers: headers } + + it 'updates the Doi' do + expect(json.dig('data', 'attributes', 'creators')).to eq(creators) + + doc = Nokogiri::XML(Base64.decode64(json.dig('data', 'attributes', 'xml')), nil, 'UTF-8', &:noblanks) + expect(doc.at_css("creators", "creator").to_s + "\n").to eq( + <<~HEREDOC + + + Ollomi, Benjamin + Cambridge University + EMBL-EBI + + + HEREDOC + ) + end + end + + context 'update geoLocationPoint' do + let(:geo_locations) { [ + { + "geoLocationPoint" => { + "pointLatitude" => "49.0850736", + "pointLongitude" => "-123.3300992" + } + }] } + let(:update_attributes) do + { + "data" => { + "type" => "dois", + "attributes" => { + "geoLocations" => geo_locations + } + } + } + end + + before { patch "/dois/#{doi.doi}", params: update_attributes.to_json, headers: headers } + + it 'updates the Doi' do + expect(json.dig('data', 'attributes', 'geoLocations')).to eq(geo_locations) + + doc = Nokogiri::XML(Base64.decode64(json.dig('data', 'attributes', 'xml')), nil, 'UTF-8', &:noblanks) + expect(doc.at_css("geoLocations", "geoLocation").to_s + "\n").to eq( + <<~HEREDOC + + + + 49.0850736 + -123.3300992 + + + + HEREDOC + ) + end + end + context 'remove series_information' do let(:xml) { File.read(file_fixture('datacite_series_information.xml')) } let(:descriptions) { [{ "description" => "Axel is a minimalistic cliff climbing rover that can explore