-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter the attributes that display on the json views
This prevents data from displaying through the APIs even though it wasn't clear that it would be displayed. Fixes #1899
- Loading branch information
Showing
6 changed files
with
73 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
json.links do | ||
json.self polymorphic_url(@document) | ||
end | ||
|
||
json.data do | ||
json.id @document.id | ||
json.attributes do | ||
doc_presenter = show_presenter(@document) | ||
|
||
document_show_fields(@document).each do |field_name, field| | ||
if should_render_show_field? @document, field | ||
json.set! field_name, doc_presenter.field_value(field_name) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe "catalog/show.json" do | ||
let(:document) do | ||
SolrDocument.new(id: '123', title_tsim: 'Book1', author_tsim: 'Julie') | ||
end | ||
let(:config) do | ||
Blacklight::Configuration.new do |config| | ||
config.add_show_field 'title_tsim', label: 'Title:' | ||
end | ||
end | ||
|
||
let(:hash) do | ||
render template: "catalog/show.json", format: :json | ||
JSON.parse(rendered).with_indifferent_access | ||
end | ||
|
||
before do | ||
allow(view).to receive(:blacklight_config).and_return(config) | ||
assign :document, document | ||
end | ||
|
||
it "includes document attributes" do | ||
expect(hash).to include(data: | ||
{ | ||
id: '123', | ||
attributes: { 'title_tsim' => 'Book1' } | ||
} | ||
) | ||
end | ||
end |