Skip to content

Commit

Permalink
Ensures the display of containers only changes the case of first char…
Browse files Browse the repository at this point in the history
…acter. (#1442)

* Ensures containers display only changes case of first character.
* Adjusting #containers in SolrDocument spec to test capitalization.
  • Loading branch information
randalldfloyd authored Dec 7, 2023
1 parent 78183a6 commit 2c7f1d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions app/models/concerns/arclight/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>] with embedded highlights using <em>...</em>
Expand Down
9 changes: 7 additions & 2 deletions spec/models/concerns/arclight/solr_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2c7f1d9

Please sign in to comment.