Skip to content

Commit

Permalink
show all contributors when not filtering by contributor-type. #632
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Sep 16, 2020
1 parent 124a497 commit 00d06de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/graphql/types/doi_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ def creators(**args)
end

def contributors(**args)
Array.wrap(object.contributors[0...args[:first]]).select { |c| c["contributorType"] == args[:contributor_type] }.map do |c|
contrib = Array.wrap(object.contributors[0...args[:first]])
contrib = contrib.select { |c| c["contributorType"] == args[:contributor_type] } if args[:contributor_type].present?
contrib.map do |c|
Hashie::Mash.new(
"id" => c.fetch("nameIdentifiers", []).find { |n| %w(ORCID ROR).include?(n.fetch("nameIdentifierScheme", nil)) }.to_h.fetch("nameIdentifier", nil),
"contributor_type" => c.fetch("contributorType", nil),
Expand Down
20 changes: 20 additions & 0 deletions spec/graphql/types/dissertation_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@
name
contributorType
}
hostingInstitution: contributors(contributorType: "HostingInstitution") {
id
type
name
contributorType
}
contributors {
id
type
name
contributorType
}
}
}
})
Expand All @@ -213,6 +225,14 @@
expect(response.dig("data", "dissertations", "published")).to eq([{"count"=>3, "id"=>"2011", "title"=>"2011"}])
expect(response.dig("data", "dissertations", "nodes").length).to eq(3)
expect(response.dig("data", "dissertations", "nodes", 0, "dataManagers")).to eq([])
expect(response.dig("data", "dissertations", "nodes", 0, "hostingInstitution")).to eq([{"contributorType"=>"HostingInstitution",
"id"=>"https://ror.org/046ak2485",
"name"=>"Freie Universität Berlin",
"type"=>"Organization"}])
expect(response.dig("data", "dissertations", "nodes", 0, "contributors")).to eq([{"contributorType"=>"HostingInstitution",
"id"=>"https://ror.org/046ak2485",
"name"=>"Freie Universität Berlin",
"type"=>"Organization"}])
end
end
end

0 comments on commit 00d06de

Please sign in to comment.