Skip to content

Commit

Permalink
fix: Archival Collection (#959)
Browse files Browse the repository at this point in the history
* add or instead or and

* update the archival_collection method

* fux trailing whitespace

* revert catalog controller

* revert californica_collection_presenter work_presenter

* update the mmethod to fix the punctuation

* add rubocop exception

* fix linting
  • Loading branch information
jendiamond authored Feb 8, 2024
1 parent 09732c9 commit 18c379f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Metrics/AbcSize:
- app/importers/collection_record_importer.rb
- spec/jobs/mss_csv_import_job_spec.rb
- app/jobs/csv_row_import_job.rb
- app/indexers/work_indexer.rb

Metrics/ClassLength:
Enabled: true
Expand Down Expand Up @@ -66,6 +67,7 @@ Metrics/CyclomaticComplexity:
- app/uploaders/csv_manifest_validator.rb
- app/indexers/year_parser.rb
- app/jobs/csv_row_import_job.rb
- app/indexers/work_indexer.rb

Metrics/LineLength:
Exclude:
Expand Down Expand Up @@ -116,6 +118,7 @@ Metrics/PerceivedComplexity:
- app/controllers/application_controller.rb
- app/indexers/year_parser.rb
- app/jobs/csv_row_import_job.rb
- app/indexers/work_indexer.rb

RSpec/AnyInstance:
Enabled: false
Expand Down Expand Up @@ -165,6 +168,10 @@ Style/IfUnlessModifier:
Exclude:
- 'app/importers/csv_validator.rb'

Style/UnneededInterpolation:
Exclude:
- 'app/indexers/work_indexer.rb'

Layout/MultilineBlockLayout:
Exclude:
- 'spec/system/search_catalog_spec.rb'
Expand All @@ -177,6 +184,10 @@ Layout/BlockEndNewline:
Exclude:
- 'spec/system/search_catalog_spec.rb'

Layout/IndentArray:
Exclude:
- 'spec/indexers/work_indexer_spec.rb'

Rails/SkipsModelValidations:
Exclude:
- 'app/importers/californica_importer.rb'
Expand Down
20 changes: 18 additions & 2 deletions app/indexers/work_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,24 @@ def solr_dates
end

def archival_collection
if object.archival_collection_title && object.archival_collection_number && object.archival_collection_box && object.archival_collection_folder
"#{object.archival_collection_title} (#{object.archival_collection_number}), #{object.archival_collection_box}, #{object.archival_collection_folder}"
# Return nil if none of the attributes exist.
return nil unless object.archival_collection_title.present? || object.archival_collection_number.present? || object.archival_collection_box.present? || object.archival_collection_folder.present?

parts = []
# Start with the title, if it exists.
parts << object.archival_collection_title if object.archival_collection_title.present?

# Add the number in parentheses directly following the title, if it exists.
if object.archival_collection_number.present?
title_with_number = parts.last ? "#{parts.pop} (#{object.archival_collection_number})" : "(#{object.archival_collection_number})"
parts << title_with_number
end

# Add the box and folder information, prefixed appropriately, if they exist.
parts << "#{object.archival_collection_box}" if object.archival_collection_box.present?
parts << "#{object.archival_collection_folder}" if object.archival_collection_folder.present?

# Join the parts with a comma a space, where appropriate.
parts.join(', ')
end
end
37 changes: 33 additions & 4 deletions spec/indexers/work_indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@

it 'indexes a human-readable related record title text' do
expect(solr_document['human_readable_related_record_title_ssm']).to match_array([
"<a href='http://localhost:3003/catalog/ark:/123/458'>title 3 for ark:/123/458</a>",
"<a href='http://localhost:3003/catalog/ark:/123/457'>title 2 for ark:/123/457</a>",
"<a href='http://localhost:3003/catalog/ark:/123/459'>title 1 for ark:/123/459</a>"
])
"<a href='http://localhost:3003/catalog/ark:/123/458'>title 3 for ark:/123/458</a>",
"<a href='http://localhost:3003/catalog/ark:/123/457'>title 2 for ark:/123/457</a>",
"<a href='http://localhost:3003/catalog/ark:/123/459'>title 1 for ark:/123/459</a>"
])
end
end
end
Expand Down Expand Up @@ -571,6 +571,35 @@
end
end

context 'when just archival collection title & number attributes are provided' do
let(:attributes) do
{
ark: 'ark:/123/456',
archival_collection_title: "Sample collection",
archival_collection_number: "Collection 123"
}
end

it 'combines them' do
expect(indexer.archival_collection).to eq "Sample collection (Collection 123)"
end
end

context 'when just archival collection title, box & folder attributes are provided' do
let(:attributes) do
{
ark: 'ark:/123/456',
archival_collection_title: "Sample collection",
archival_collection_box: "Box 9",
archival_collection_folder: "Folder 21"
}
end

it 'combines them' do
expect(indexer.archival_collection).to eq "Sample collection, Box 9, Folder 21"
end
end

context 'when archival collection attributes are absent' do
let(:attributes) do
{
Expand Down

0 comments on commit 18c379f

Please sign in to comment.