From f673737a95934fcc2ef23e7a43f08e8d3e798805 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Mon, 24 Aug 2020 07:22:52 +0200 Subject: [PATCH] fix fields_of_science graphql field for single record --- app/graphql/types/doi_item.rb | 4 ++-- spec/graphql/types/work_type_spec.rb | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/graphql/types/doi_item.rb b/app/graphql/types/doi_item.rb index 5919669bb..7529eac41 100644 --- a/app/graphql/types/doi_item.rb +++ b/app/graphql/types/doi_item.rb @@ -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 } diff --git a/spec/graphql/types/work_type_spec.rb b/spec/graphql/types/work_type_spec.rb index bb2c423e2..8e536fdb8 100644 --- a/spec/graphql/types/work_type_spec.rb +++ b/spec/graphql/types/work_type_spec.rb @@ -246,6 +246,10 @@ id doi registered + subjects { + subject + subjectScheme + } rights { rights rightsUri @@ -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 @@ -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