diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index c509e4158..662477221 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -536,13 +536,13 @@ def set_include @include = params[:include].split(",").map { |i| i.downcase.underscore.to_sym } if params[:events].present? - @include = @include & [:client, :media, :views, :downloads] + @include = @include & [:client, :media, :references, :citations, :parts, :versions] else @include = @include & [:client, :media] end else if params[:events].present? - @include = [:client, :media, :views, :downloads] + @include = [:client, :media, :references, :citations, :parts, :versions] else @include = [:client, :media] end diff --git a/app/serializers/doi_serializer.rb b/app/serializers/doi_serializer.rb index aaaa8d19e..2063305ee 100644 --- a/app/serializers/doi_serializer.rb +++ b/app/serializers/doi_serializer.rb @@ -12,10 +12,10 @@ class DoiSerializer belongs_to :client, record_type: :clients has_many :media, record_type: :media, id_method_name: :uid, if: Proc.new { |object, params| params && params[:detail] && !params[:is_collection]} - has_many :references, record_type: :references, id_method_name: :uid, serializer: EventSerializer, if: Proc.new { |object, params| params && params[:detail] } - has_many :citations, record_type: :citations, id_method_name: :uid, serializer: EventSerializer, if: Proc.new { |object, params| params && params[:detail] } - has_many :parts, record_type: :parts, id_method_name: :uid, serializer: EventSerializer, if: Proc.new { |object, params| params && params[:detail] } - has_many :versions, record_type: :versions, id_method_name: :uid, serializer: EventSerializer, if: Proc.new { |object, params| params && params[:detail] } + has_many :references, record_type: :references, serializer: EventSerializer, if: Proc.new { |object, params| params && params[:detail] } + has_many :citations, record_type: :citations, serializer: EventSerializer, if: Proc.new { |object, params| params && params[:detail] } + has_many :parts, record_type: :parts, serializer: EventSerializer, if: Proc.new { |object, params| params && params[:detail] } + has_many :versions, record_type: :versions, serializer: EventSerializer, if: Proc.new { |object, params| params && params[:detail] } attribute :xml, if: Proc.new { |object, params| params && params[:detail] } do |object| begin diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index ddff8f73c..c59ceeb4c 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -231,14 +231,16 @@ end it "has references" do - get "/dois/#{doi.doi}", nil, headers + get "/dois/#{doi.doi}?events=true", nil, headers expect(last_response.status).to eq(200) expect(json.dig('data', 'attributes', 'url')).to eq(doi.url) expect(json.dig('data', 'attributes', 'doi')).to eq(doi.doi.downcase) expect(json.dig('data', 'attributes', 'titles')).to eq(doi.titles) expect(json.dig('data', 'attributes', 'referenceCount')).to eq(3) - expect(json.dig('data', 'relationships', 'references')).to eq("data"=>{"id"=>references.first.source_doi, "type"=>"references"}) + expect(json.dig('data', 'relationships', 'references', 'data').length).to eq(3) + expect(json.dig('included').length).to eq(4) + expect(json.dig('included', 1, 'attributes', 'relationTypeId')).to eq("references") end end @@ -253,14 +255,16 @@ end it "has citations" do - get "/dois/#{doi.doi}", nil, headers + get "/dois/#{doi.doi}?events=true", nil, headers expect(last_response.status).to eq(200) expect(json.dig('data', 'attributes', 'url')).to eq(doi.url) expect(json.dig('data', 'attributes', 'doi')).to eq(doi.doi.downcase) expect(json.dig('data', 'attributes', 'titles')).to eq(doi.titles) expect(json.dig('data', 'attributes', 'citationCount')).to eq(1) - expect(json.dig('data', 'relationships', 'citations')).to eq("data"=>{"id"=>citations.first.target_doi, "type"=>"citations"}) + expect(json.dig('data', 'relationships', 'citations', 'data').length).to eq(1) + expect(json.dig('included').length).to eq(2) + expect(json.dig('included', 0, 'attributes', 'relationTypeId')).to eq("is-referenced-by") end end @@ -275,14 +279,16 @@ end it "has parts" do - get "/dois/#{doi.doi}", nil, headers + get "/dois/#{doi.doi}?events=true", nil, headers expect(last_response.status).to eq(200) expect(json.dig('data', 'attributes', 'url')).to eq(doi.url) expect(json.dig('data', 'attributes', 'doi')).to eq(doi.doi.downcase) expect(json.dig('data', 'attributes', 'titles')).to eq(doi.titles) expect(json.dig('data', 'attributes', 'partCount')).to eq(3) - expect(json.dig('data', 'relationships', 'parts')).to eq("data"=>{"id"=>parts.first.source_doi, "type"=>"parts"}) + expect(json.dig('data', 'relationships', 'parts', 'data').length).to eq(3) + expect(json.dig('included').length).to eq(4) + expect(json.dig('included', 1, 'attributes', 'relationTypeId')).to eq("has-part") end end @@ -297,14 +303,17 @@ end it "has versions" do - get "/dois/#{doi.doi}", nil, headers + get "/dois/#{doi.doi}?events=true", nil, headers + puts last_response.body expect(last_response.status).to eq(200) expect(json.dig('data', 'attributes', 'url')).to eq(doi.url) expect(json.dig('data', 'attributes', 'doi')).to eq(doi.doi.downcase) expect(json.dig('data', 'attributes', 'titles')).to eq(doi.titles) expect(json.dig('data', 'attributes', 'versionCount')).to eq(3) - expect(json.dig('data', 'relationships', 'versions')).to eq("data"=>{"id"=>versions.first.source_doi, "type"=>"versions"}) + expect(json.dig('data', 'relationships', 'versions', 'data').length).to eq(3) + expect(json.dig('included').length).to eq(4) + expect(json.dig('included', 1, 'attributes', 'relationTypeId')).to eq("has-version") end end