Skip to content

Commit

Permalink
affiliation should be array. datacite/bolognese#57
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 10, 2019
1 parent 6f9a297 commit bba2e93
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
73 changes: 73 additions & 0 deletions spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
<creators>
<creator>
<creatorName>Ollomi, Benjamin</creatorName>
<affiliation>Cambridge University</affiliation>
<affiliation>EMBL-EBI</affiliation>
</creator>
</creators>
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
<geoLocations>
<geoLocation>
<geoLocationPoint>
<pointLatitude>49.0850736</pointLatitude>
<pointLongitude>-123.3300992</pointLongitude>
</geoLocationPoint>
</geoLocation>
</geoLocations>
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
Expand Down

0 comments on commit bba2e93

Please sign in to comment.