diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index d202b3c80..1c3f759b7 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -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) diff --git a/app/helpers/index_view_helper.rb b/app/helpers/index_view_helper.rb new file mode 100644 index 000000000..598fe7a1b --- /dev/null +++ b/app/helpers/index_view_helper.rb @@ -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("
") + end +end diff --git a/spec/helpers/index_view_helper_spec.rb b/spec/helpers/index_view_helper_spec.rb new file mode 100644 index 000000000..95e5d5270 --- /dev/null +++ b/spec/helpers/index_view_helper_spec.rb @@ -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
2
3
4
5
6
7' + end + end + end +end