From 2c7f1d94b666eeb586850e2ce42e6aaa30ee629b Mon Sep 17 00:00:00 2001 From: Randall Floyd Date: Thu, 7 Dec 2023 12:13:37 -0500 Subject: [PATCH] Ensures the display of containers only changes the case of first character. (#1442) * Ensures containers display only changes case of first character. * Adjusting #containers in SolrDocument spec to test capitalization. --- app/models/concerns/arclight/solr_document.rb | 9 +++++++-- spec/models/concerns/arclight/solr_document_spec.rb | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/models/concerns/arclight/solr_document.rb b/app/models/concerns/arclight/solr_document.rb index 41f182b21..089b8d530 100644 --- a/app/models/concerns/arclight/solr_document.rb +++ b/app/models/concerns/arclight/solr_document.rb @@ -111,8 +111,13 @@ def digital_objects end def containers - # NOTE: that .titlecase strips punctuation, like hyphens, we want to keep - fetch('containers_ssim', []).map(&:capitalize) + # NOTE: Keep uppercase characters if present, but upcase the first if not already + containers_field = fetch('containers_ssim', []).reject(&:empty?) + return [] if containers_field.blank? + + containers_field.map do |container| + container.dup.sub!(/\A./, &:upcase) + end end # @return [Array] with embedded highlights using ... diff --git a/spec/models/concerns/arclight/solr_document_spec.rb b/spec/models/concerns/arclight/solr_document_spec.rb index e7123ea23..fb408b43d 100644 --- a/spec/models/concerns/arclight/solr_document_spec.rb +++ b/spec/models/concerns/arclight/solr_document_spec.rb @@ -88,10 +88,15 @@ end describe '#containers' do - let(:document) { SolrDocument.new(containers_ssim: ['box 1', 'folder 4-5']) } + let(:document) { SolrDocument.new(containers_ssim: ['box 1', 'folder 4-5', 'box ABC']) } + + it 'handles capitalization properly' do + expect(document.containers.first).to eq 'Box 1' + expect(document.containers.last).to eq 'Box ABC' + end it 'uses our rules for joining' do - expect(document.containers.join(', ')).to eq 'Box 1, Folder 4-5' + expect(document.containers.join(', ')).to eq 'Box 1, Folder 4-5, Box ABC' end end