Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Limit number of subjects displayed on index page #907

Merged
merged 1 commit into from
Dec 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def self.search_config
# The ordering of the field names is the order of the display
config.add_index_field solr_name('description', :stored_searchable)
config.add_index_field solr_name('tag', :stored_searchable)
config.add_index_field solr_name('subject', :stored_searchable)
config.add_index_field solr_name('subject', :stored_searchable), helper_method: :index_subject
config.add_index_field solr_name('creator', :stored_searchable)
config.add_index_field solr_name('contributor', :stored_searchable)
config.add_index_field solr_name('publisher', :stored_searchable)
Expand Down
7 changes: 7 additions & 0 deletions app/helpers/index_view_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module IndexViewHelper
# Limit the number of subjects displayed on index page.
# Mainly because of geo works.
def index_subject(args)
args[:document].subject.take(7).join("<br/>")
end
end
16 changes: 16 additions & 0 deletions spec/helpers/index_view_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'rails_helper'

describe IndexViewHelper do
subject { helper }
let(:document) { instance_double(SolrDocument, subject: subject_list) }
let(:args) { { document: document } }

describe '#index_subject' do
context 'with a long list of subject terms' do
let(:subject_list) { ['1', '2', '3', '4', '5', '6', '7', '8', '9'] }
it 'returns a list with a maximum of 7 items' do
expect(subject.index_subject(args)).to eq '1<br/>2<br/>3<br/>4<br/>5<br/>6<br/>7'
end
end
end
end