Skip to content

Commit

Permalink
Merge pull request #2340 from projectblacklight/atom-feed-summary
Browse files Browse the repository at this point in the history
Allow the atom feed's summary to be customized
  • Loading branch information
jcoyne committed Sep 30, 2020
2 parents 49cec35 + 6c15f20 commit 9865d4d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
6 changes: 3 additions & 3 deletions app/views/catalog/_document.atom.builder
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ xml.entry do

with_format(:html) do
xml.summary "type" => "html" do
xml.text! render_document_partial(document,
:index,
document_counter: document_counter)
xml.text! render_document_partials(document,
blacklight_config.view_config(:atom).summary_partials,
document_counter: document_counter)
end
end

Expand Down
5 changes: 3 additions & 2 deletions lib/blacklight/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def default_values
# document presenter class used by helpers and views
document_presenter_class: nil,
# component class used to render a document; defaults to Blacklight::DocumentComponent,
# but can be set explicitly to avoid any legacy behavior
# but can be set explicitly to avoid any legacy behavior
document_component: nil,
# solr field to use to render a document title
title_field: nil,
Expand Down Expand Up @@ -100,7 +100,8 @@ def default_values
list: {},
atom: {
if: false, # by default, atom should not show up as an alternative view
partials: [:document]
partials: [:document],
summary_partials: [:index]
},
rss: {
if: false, # by default, rss should not show up as an alternative view
Expand Down
38 changes: 35 additions & 3 deletions spec/views/catalog/index.atom.builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@
end
end

let(:blacklight_config) { CatalogController.blacklight_config }

before do
@response = Blacklight::Solr::Response.new({ response: { numFound: 30 } }, start: 10, rows: 10)
allow(@response).to receive(:documents).and_return(document_list)
params['content_format'] = 'some_format'
allow(view).to receive(:action_name).and_return('index')
allow(view).to receive(:blacklight_config).and_return(CatalogController.blacklight_config)
allow(view).to receive(:blacklight_config).and_return(blacklight_config)
allow(view).to receive(:search_field_options_for_select).and_return([])
render template: 'catalog/index', formats: [:atom]
end

# We need to use rexml to test certain things that have_tag wont' test
let(:response_xml) { REXML::Document.new(rendered) }

it "has contextual information" do
render template: 'catalog/index', formats: [:atom]

expect(rendered).to have_selector("link[rel=self]")
expect(rendered).to have_selector("link[rel=next]")
expect(rendered).to have_selector("link[rel=previous]")
Expand All @@ -36,13 +39,17 @@
end

it "gets paging data correctly from response" do
render template: 'catalog/index', formats: [:atom]

# Can't use have_tag for namespaced elements, sorry.
expect(response_xml.elements["/feed/opensearch:totalResults"].text).to eq "30"
expect(response_xml.elements["/feed/opensearch:startIndex"].text).to eq "10"
expect(response_xml.elements["/feed/opensearch:itemsPerPage"].text).to eq "10"
end

it "includes an opensearch Query role=request" do
render template: 'catalog/index', formats: [:atom]

expect(response_xml.elements.to_a("/feed/opensearch:itemsPerPage")).to have(1).item
query_el = response_xml.elements["/feed/opensearch:Query"]
expect(query_el).not_to be_nil
Expand All @@ -52,34 +59,55 @@
end

it "has ten entries" do
render template: 'catalog/index', formats: [:atom]

expect(rendered).to have_selector("entry", count: 10)
end

describe "entries" do
it "has a title" do
render template: 'catalog/index', formats: [:atom]
expect(rendered).to have_selector("entry > title")
end

it "has an updated" do
render template: 'catalog/index', formats: [:atom]
expect(rendered).to have_selector("entry > updated")
end

it "has html link" do
render template: 'catalog/index', formats: [:atom]
expect(rendered).to have_selector("entry > link[rel=alternate][type='text/html']")
end

it "has an id" do
render template: 'catalog/index', formats: [:atom]
expect(rendered).to have_selector("entry > id")
end

it "has a summary" do
expect(rendered).to have_selector("entry > summary")
stub_template "catalog/_index.html.erb" => "partial content"
render template: 'catalog/index', formats: [:atom]
expect(rendered).to have_selector("entry > summary", text: 'partial content')
end

context 'with a custom HTML partial' do
before do
blacklight_config.view.atom.summary_partials = ['whatever']
stub_template 'catalog/_whatever_default.html.erb' => 'whatever content'
end

it "has the customized summary" do
render template: 'catalog/index', formats: [:atom]
expect(rendered).to have_selector("entry > summary", text: 'whatever content')
end
end

describe "with an author" do
let(:entry) { response_xml.elements.to_a("/feed/entry")[0] }

it "has author tag" do
render template: 'catalog/index', formats: [:atom]
expect(entry.elements["author/name"].text).to eq 'xyz'
end
end
Expand All @@ -88,6 +116,7 @@
let(:entry) { response_xml.elements.to_a("/feed/entry")[1] }

it "does not have an author tag" do
render template: 'catalog/index', formats: [:atom]
expect(entry.elements["author/name"]).to be_nil
end
end
Expand All @@ -98,10 +127,12 @@
let(:entry) { response_xml.elements.to_a("/feed/entry")[1].to_s }

it "includes a link rel tag" do
render template: 'catalog/index', formats: [:atom]
expect(entry).to have_selector("link[rel=alternate][type='application/some-format']")
end

it "has content embedded" do
render template: 'catalog/index', formats: [:atom]
expect(entry).to have_selector("content")
end
end
Expand All @@ -110,6 +141,7 @@
let(:entry) { response_xml.elements.to_a("/feed/entry")[5].to_s }

it "does not have content embedded" do
render template: 'catalog/index', formats: [:atom]
expect(entry).not_to have_selector("content[type='application/some-format']")
end
end
Expand Down

0 comments on commit 9865d4d

Please sign in to comment.