From 750e34dd2d9141310fc0fdc14b23449d5561d8d9 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Thu, 16 Aug 2018 11:16:54 -0500 Subject: [PATCH] Display the type value in conformance with JSON-API --- app/views/catalog/index.json.jbuilder | 1 + app/views/catalog/show.json.jbuilder | 1 + spec/views/catalog/index.json.jbuilder_spec.rb | 8 +++++--- spec/views/catalog/show.json.jbuilder_spec.rb | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/views/catalog/index.json.jbuilder b/app/views/catalog/index.json.jbuilder index 4c5bd1ccf5..866433764d 100644 --- a/app/views/catalog/index.json.jbuilder +++ b/app/views/catalog/index.json.jbuilder @@ -14,6 +14,7 @@ json.data do json.array! @presenter.documents do |document| document_url = polymorphic_url(url_for_document(document)) json.id document.id + json.type document[blacklight_config.view_config(:index).display_type_field] json.attributes do doc_presenter = index_presenter(document) diff --git a/app/views/catalog/show.json.jbuilder b/app/views/catalog/show.json.jbuilder index 7a486b9407..a53c818879 100644 --- a/app/views/catalog/show.json.jbuilder +++ b/app/views/catalog/show.json.jbuilder @@ -6,6 +6,7 @@ end json.data do json.id @document.id + json.type @document[blacklight_config.view_config(:show).display_type_field] json.attributes do doc_presenter = show_presenter(@document) diff --git a/spec/views/catalog/index.json.jbuilder_spec.rb b/spec/views/catalog/index.json.jbuilder_spec.rb index 2d93fefaca..bad15f6d77 100644 --- a/spec/views/catalog/index.json.jbuilder_spec.rb +++ b/spec/views/catalog/index.json.jbuilder_spec.rb @@ -4,8 +4,8 @@ let(:response) { instance_double(Blacklight::Solr::Response, documents: docs, prev_page: nil, next_page: 2, total_pages: 3) } let(:docs) do [ - SolrDocument.new(id: '123', title_tsim: 'Book1', author_tsim: 'Julie'), - SolrDocument.new(id: '456', title_tsim: 'Book2', author_tsim: 'Rosie') + SolrDocument.new(id: '123', title_tsim: 'Book1', author_tsim: 'Julie', format: 'Book'), + SolrDocument.new(id: '456', title_tsim: 'Article1', author_tsim: 'Rosie', format: 'Article') ] end let(:config) do @@ -63,6 +63,7 @@ expect(hash).to include(data: [ { id: '123', + type: 'Book', attributes: { 'title': { id: 'http://test.host/catalog/123#title', @@ -77,12 +78,13 @@ }, { id: '456', + type: 'Article', attributes: { 'title': { id: 'http://test.host/catalog/456#title', type: 'document_value', attributes: { - value: 'Book2', + value: 'Article1', label: 'Title' } } diff --git a/spec/views/catalog/show.json.jbuilder_spec.rb b/spec/views/catalog/show.json.jbuilder_spec.rb index 6b7566f916..60f9b4e84d 100644 --- a/spec/views/catalog/show.json.jbuilder_spec.rb +++ b/spec/views/catalog/show.json.jbuilder_spec.rb @@ -2,7 +2,7 @@ RSpec.describe "catalog/show.json" do let(:document) do - SolrDocument.new(id: '123', title_tsim: 'Book1', author_tsim: 'Julie') + SolrDocument.new(id: '123', title_tsim: 'Book1', author_tsim: 'Julie', format: 'Book') end let(:config) do Blacklight::Configuration.new do |config| @@ -24,6 +24,7 @@ expect(hash).to include(data: { id: '123', + type: 'Book', attributes: { 'title_tsim' => 'Book1' } }) end