Skip to content

Commit

Permalink
Merge pull request #706 from datacite/doi-nameIdentifiers
Browse files Browse the repository at this point in the history
Array.wrap doi nameIdentifiers element.
  • Loading branch information
svogt0511 authored Jan 16, 2021
2 parents 5347b6a + b38f276 commit 736e8f0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/serializers/datacite_doi_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class DataciteDoiSerializer
Array.wrap(c["affiliation"]).map do |a|
params[:affiliation] ? a : a["name"]
end.compact
c["nameIdentifiers"] = Array.wrap(c["nameIdentifiers"])
c
end.compact
end
Expand Down
29 changes: 26 additions & 3 deletions spec/requests/datacite_dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@
"nameType" => "Personal",
"name" => "John Doe",
"affiliation" => [],
"nameIdentifiers" => [],
})
end

Expand All @@ -360,6 +361,28 @@
expect(json.dig("data", "attributes", "creators")).to eq([doi.creators])
end
end

context "nameIdentifiers started as an object not array" do
let(:doi) do
create(:doi, client: client, creators:
[{
"nameType" => "Personal",
"name" => "John Doe",
"affiliation" => [],
"nameIdentifiers": {
"nameIdentifier": "http://viaf.org/viaf/4934600",
"nameIdentifierScheme": "VIAF"
},
}])
end

it "returns the nameIdentifiers as list" do
get "/dois/#{doi.doi}", nil, headers

expect(last_response.status).to eq(200)
expect(json.dig("data", "attributes", "creators", 0, "nameIdentifiers")).to eq([{ "nameIdentifier" => "http://viaf.org/viaf/4934600", "nameIdentifierScheme" => "VIAF"}])
end
end
end

describe "GET /dois for dissertations", elasticsearch: true, vcr: true do
Expand Down Expand Up @@ -1357,7 +1380,7 @@

context "when the creators change" do
let(:xml) { Base64.strict_encode64(file_fixture("datacite.xml").read) }
let(:creators) { [{ "affiliation" => [], "name" => "Ollomi, Benjamin" }, { "affiliation" => [], "name" => "Duran, Patrick" }] }
let(:creators) { [{ "affiliation" => [], "nameIdentifiers" => [], "name" => "Ollomi, Benjamin" }, { "affiliation" => [], "nameIdentifiers" => [], "name" => "Duran, Patrick" }] }
let(:valid_attributes) do
{
"data" => {
Expand Down Expand Up @@ -2472,7 +2495,7 @@
end

context "when the creators change" do
let(:creators) { [{ "affiliation" => [], "name" => "Ollomi, Benjamin" }, { "affiliation" => [], "name" => "Duran, Patrick" }] }
let(:creators) { [{ "affiliation" => [], "nameIdentifiers" => [], "name" => "Ollomi, Benjamin" }, { "affiliation" => [], "nameIdentifiers" => [], "name" => "Duran, Patrick" }] }
let(:xml) { Base64.strict_encode64(file_fixture("datacite.xml").read) }
let(:valid_attributes) do
{
Expand Down Expand Up @@ -3188,7 +3211,7 @@
end

context "update multiple affiliations" do
let(:creators) { [{ "name" => "Ollomi, Benjamin", "affiliation" => [{ "name" => "Cambridge University" }, { "name" => "EMBL-EBI" }] }] }
let(:creators) { [{ "name" => "Ollomi, Benjamin", "affiliation" => [{ "name" => "Cambridge University" }, { "name" => "EMBL-EBI" }], "nameIdentifiers" => [] }] }
let(:update_attributes) do
{
"data" => {
Expand Down

0 comments on commit 736e8f0

Please sign in to comment.