Skip to content

Commit

Permalink
fix fields_of_science graphql field for single record
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Aug 24, 2020
1 parent c6cdedc commit f673737
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/graphql/types/doi_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ def registration_agency

def fields_of_science
Array.wrap(object.subjects)
.select { |s| s.subjectScheme == "Fields of Science and Technology (FOS)" }
.select { |s| s["subjectScheme"] == "Fields of Science and Technology (FOS)" }
.map do |s|
name = s.subject.gsub("FOS: ", "")
name = s["subject"].gsub("FOS: ", "")
{
"id" => name.parameterize(separator: '_'),
"name" => name }
Expand Down
15 changes: 12 additions & 3 deletions spec/graphql/types/work_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@
id
doi
registered
subjects {
subject
subjectScheme
}
rights {
rights
rightsUri
Expand All @@ -256,7 +260,11 @@
})
end

let!(:works) { create_list(:doi, 10, aasm_state: "findable", agency: "datacite") }
let!(:works) { create_list(:doi, 10, aasm_state: "findable", agency: "datacite", subjects:
[{
"subject" => "Computer and information sciences"
}])
}
let!(:work) { create(:doi, aasm_state: "findable", agency: "crossref", rights_list: []) }

before do
Expand All @@ -275,9 +283,10 @@
expect(response.dig("data", "works", "nodes").length).to eq(4)
expect(response.dig("data", "works", "nodes", 0, "id")).to eq(@works[0].identifier)
expect(response.dig("data", "works", "nodes", 0, "registered")).to start_with(@works[0].registered[0..9])
expect(response.dig("data", "works", "nodes", 0, "subjects")).to eq([{"subject"=>"Computer and information sciences", "subjectScheme"=>nil}, {"subject"=>"FOS: Computer and information sciences", "subjectScheme"=>"Fields of Science and Technology (FOS)"}])
expect(response.dig("data", "works", "nodes", 0, "rights")).to eq([{"rights"=>"Creative Commons Zero v1.0 Universal",
+ "rightsIdentifier"=>"cc0-1.0",
+ "rightsUri"=>"https://creativecommons.org/publicdomain/zero/1.0/legalcode"}])
"rightsIdentifier"=>"cc0-1.0",
"rightsUri"=>"https://creativecommons.org/publicdomain/zero/1.0/legalcode"}])
end
end
end

0 comments on commit f673737

Please sign in to comment.