Skip to content

Commit

Permalink
Update solr_document_features_block to correctly fallback to the defa…
Browse files Browse the repository at this point in the history
…ult title field if a primary caption isn't provided. (#2115)
  • Loading branch information
cbeer authored and mejackreed committed Dec 18, 2018
1 parent 7359a41 commit a203cb8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<% indicators << capture do %>
<li data-target="#<%= html_id %>" data-slide-to="<%= index %>" class="list-group-item <%= 'active' if index == 0 %>">
<a href="#" title="<%= (caption_text = doc_presenter.field_value(solr_documents_features_block.primary_caption? ? solr_documents_features_block.primary_caption_field : document_show_link_field)) %>">
<a href="#" title="<%= (caption_text = doc_presenter.field_value(solr_documents_features_block.primary_caption? ? solr_documents_features_block.primary_caption_field : document_show_link_field(document))) %>">
<%= truncate(caption_text, length: 95) %>
</a>
<% if solr_documents_features_block.secondary_caption? %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
SirTrevorRails::Blocks::SolrDocumentsFeaturesBlock.new({ type: 'block', data: { 'show-primary-caption' => true, 'primary-caption-field' => 'x' } }, page)
end

let(:blacklight_config) do
Blacklight::Configuration.new do |config|
config.index.title_field = 'full_title_tesim'
end
end

before do
doc1 = [{}, SolrDocument.new(id: 1, x: 'a' * 100)]
doc2 = [{}, SolrDocument.new(id: 2)]
doc2 = [{}, SolrDocument.new(id: 2, full_title_tesim: 'full_title')]
doc3 = [{}, SolrDocument.new(id: 3)]
allow(block).to receive(:each_document).and_return([doc1, doc2, doc3])
allow(block).to receive_messages(documents?: true)
allow(view).to receive_messages(solr_documents_features_block: block)
allow(view).to receive_messages(has_thumbnail?: true, render_thumbnail_tag: 'thumb', blacklight_config: Blacklight::Configuration.new)
allow(view).to receive_messages(has_thumbnail?: true, render_thumbnail_tag: 'thumb', blacklight_config: blacklight_config)
end

it 'has a slideshow block' do
Expand All @@ -30,4 +36,16 @@
expect(rendered).to have_selector '.carousel-indicators li', count: 3
expect(rendered).to have_selector '.carousel-indicators li', text: 'a' * 92 + '...'
end

describe 'without a primary caption' do
let(:block) do
SirTrevorRails::Blocks::SolrDocumentsFeaturesBlock.new({ type: 'block', data: { 'show-primary-caption' => false } }, page)
end

it 'falls back to the regular document title for the caption' do
render partial: p, locals: { item_carousel_block: block }
expect(rendered).to have_selector '.item-features'
expect(rendered).to have_selector '.carousel-indicators li', text: 'full_title'
end
end
end

0 comments on commit a203cb8

Please sign in to comment.