Skip to content

Commit

Permalink
Filter the attributes that display on the json index view
Browse files Browse the repository at this point in the history
This prevents data from displaying through the APIs even though it
wasn't clear that it would be displayed.
Fixes #1899
  • Loading branch information
jcoyne committed Jun 7, 2018
1 parent 2455f95 commit 2d33235
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
11 changes: 10 additions & 1 deletion app/views/catalog/index.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ end
json.data do
json.array! @presenter.documents do |document|
json.id document.id
json.attributes document
json.attributes do
doc_presenter = index_presenter(document)

index_fields(document).each do |field_name, field|
if should_render_index_field? document, field
json.set! field_name, doc_presenter.field_value(field_name)
end
end
end

json.links do
json.self polymorphic_url(url_for_document(document))
end
Expand Down
17 changes: 13 additions & 4 deletions spec/views/catalog/index.json.jbuilder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
# frozen_string_literal: true
RSpec.describe "catalog/index.json" do
let(:response) { instance_double(Blacklight::Solr::Response, documents: docs, prev_page: nil, next_page: 2, total_pages: 3) }
let(:docs) { [SolrDocument.new(id: '123', title_tsim: 'Book1'), SolrDocument.new(id: '456', title_tsim: 'Book2')] }
let(:docs) do
[
SolrDocument.new(id: '123', title_tsim: 'Book1', author_tsim: 'Julie'),
SolrDocument.new(id: '456', title_tsim: 'Book2', author_tsim: 'Rosie')
]
end
let(:facets) { double("facets") }
let(:config) { Blacklight::Configuration.new }
let(:config) do
Blacklight::Configuration.new do |config|
config.add_index_field 'title_tsim', label: 'Title:'
end
end
let(:presenter) { Blacklight::JsonPresenter.new(response, facets, config) }

let(:hash) do
Expand Down Expand Up @@ -44,12 +53,12 @@
expect(hash).to include(data: [
{
id: '123',
attributes: { 'id' => '123', 'title_tsim' => 'Book1' },
attributes: { 'title_tsim' => 'Book1' },
links: { self: 'http://test.host/catalog/123' }
},
{
id: '456',
attributes: { 'id' => '456', 'title_tsim' => 'Book2' },
attributes: { 'title_tsim' => 'Book2' },
links: { self: 'http://test.host/catalog/456' }
},
])
Expand Down

0 comments on commit 2d33235

Please sign in to comment.