diff --git a/app/helpers/record_helper.rb b/app/helpers/record_helper.rb index d4b70033..020777e3 100644 --- a/app/helpers/record_helper.rb +++ b/app/helpers/record_helper.rb @@ -14,7 +14,7 @@ def date_range(range) end def publication_date(metadata) - metadata['dates'].select { |date| date['kind'] == 'Publication date' }.first['value'] + metadata[:dates].select { |date| date['kind'] == 'Publication date' }.first['value'] end # Display the machine-format key in human-readable text. diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 742398df..d638c769 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -4,9 +4,9 @@ def displayed_fields end def trim_highlights(result) - return unless result['highlight']&.any? + return unless result[:highlight]&.any? - result['highlight'].reject { |h| displayed_fields.include? h['matchedField'] } + result[:highlight].reject { |h| displayed_fields.include? h['matchedField'] } end def format_highlight_label(field_name) @@ -15,17 +15,17 @@ def format_highlight_label(field_name) end def link_to_result(result) - if result['source_link'].present? - link_to(result['title'], result['source_link']) + if result[:source_link].present? + link_to(result[:title], result[:source_link]) else - result['title'] + result[:title] end end def view_online(result) - return unless result['source_link'].present? + return unless result[:source_link].present? - link_to 'View online', result['source_link'], class: 'button button-primary' + link_to 'View online', result[:source_link], class: 'button button-primary' end def view_record(record_id) diff --git a/app/models/normalize_primo_record.rb b/app/models/normalize_primo_record.rb index d967eb33..cac88518 100644 --- a/app/models/normalize_primo_record.rb +++ b/app/models/normalize_primo_record.rb @@ -8,25 +8,25 @@ def initialize(record, query) def normalize { # Core fields - 'title' => title, - 'creators' => creators, - 'source' => source, - 'year' => year, - 'format' => format, - 'links' => links, - 'citation' => citation, - 'identifier' => record_id, - 'summary' => summary, - 'publisher' => publisher, - 'location' => best_location, - 'subjects' => subjects, + title:, + creators:, + source:, + year:, + format:, + links:, + citation:, + identifier:, + summary:, + publisher:, + location:, + subjects:, # Primo-specific fields - 'container' => container_title, - 'numbering' => numbering, - 'chapter_numbering' => chapter_numbering, - 'thumbnail' => thumbnail, - 'availability' => best_availability, - 'other_availability' => other_availability? + container:, + numbering:, + chapter_numbering:, + thumbnail:, + availability:, + other_availability: } end @@ -115,7 +115,7 @@ def citation end end - def container_title + def container return unless @record['pnx']['addata'] if @record['pnx']['addata']['jtitle'].present? @@ -125,7 +125,7 @@ def container_title end end - def record_id + def identifier return unless @record['pnx']['control']['recordid'] @record['pnx']['control']['recordid'].join @@ -224,7 +224,7 @@ def openurl if openurl_server == record_openurl_server construct_primo_openurl else - Rails.logger.warn "Alma openurl server mismatch. Expected #{openurl_server}, but received #{record_openurl_server}. (record ID: #{record_id})" + Rails.logger.warn "Alma openurl server mismatch. Expected #{openurl_server}, but received #{record_openurl_server}. (record ID: #{identifier})" @record['delivery']['almaOpenurl'] end end @@ -265,7 +265,7 @@ def publisher @record['pnx']['addata']['pub'].first end - def best_location + def location return unless @record['delivery'] return unless @record['delivery']['bestlocation'] @@ -279,13 +279,13 @@ def subjects @record['pnx']['display']['subject'] end - def best_availability - return unless best_location + def availability + return unless location @record['delivery']['bestlocation']['availabilityStatus'] end - def other_availability? + def other_availability return unless @record['delivery']['bestlocation'] return unless @record['delivery']['holding'] @@ -302,9 +302,9 @@ def frbrized? end def alma_record? - return false unless record_id + return false unless identifier - record_id.start_with?('alma') + identifier.start_with?('alma') end def dedup_url diff --git a/app/models/normalize_timdex_record.rb b/app/models/normalize_timdex_record.rb index cf17efd5..9851e9e0 100644 --- a/app/models/normalize_timdex_record.rb +++ b/app/models/normalize_timdex_record.rb @@ -8,24 +8,24 @@ def initialize(record, query) def normalize { # Core fields - 'title' => title, - 'creators' => creators, - 'source' => source, - 'year' => year, - 'format' => format, - 'links' => links, - 'citation' => citation, - 'identifier' => identifier, - 'summary' => summary, - 'publisher' => publisher, - 'location' => location, - 'subjects' => subjects, + title:, + creators:, + source:, + year:, + format:, + links:, + citation:, + identifier:, + summary:, + publisher:, + location:, + subjects:, # TIMDEX-specific fields - 'content_type' => content_type, - 'dates' => dates, - 'contributors' => contributors, - 'highlight' => highlight, - 'source_link' => source_link + content_type:, + dates:, + contributors:, + highlight:, + source_link: } end diff --git a/app/views/search/_result.html.erb b/app/views/search/_result.html.erb index 42f20d0d..ec8a59fd 100644 --- a/app/views/search/_result.html.erb +++ b/app/views/search/_result.html.erb @@ -6,9 +6,9 @@

- <%= result['content_type']&.each { |type| type['value'] }&.join(' ; ') %> + <%= result[:content_type]&.each { |type| type['value'] }&.join(' ; ') %> - <% result['dates']&.each do |date| %> + <% result[:dates]&.each do |date| %> <%= date['value'] if date['kind'] == 'Publication date' %> <% end %> @@ -16,7 +16,7 @@ Contributors:

diff --git a/app/views/search/_result_geo.html.erb b/app/views/search/_result_geo.html.erb index 4f543366..558df01a 100644 --- a/app/views/search/_result_geo.html.erb +++ b/app/views/search/_result_geo.html.erb @@ -1,38 +1,38 @@
  • - Title: <%= link_to(result_geo['title'], record_path(result_geo['identifier'])) %> + Title: <%= link_to(result_geo[:title], record_path(result_geo[:identifier])) %>

    <%= render partial: 'shared/geo_data_info', locals: { metadata: result_geo } %>
    - <% if result_geo['creators'].present? || result_geo['contributors'].present? %> + <% if result_geo[:creators].present? || result_geo[:contributors].present? %> Contributors:
      - <% contributors = result_geo['creators'].present? ? result_geo['creators'] : result_geo['contributors'] %> + <% contributors = result_geo[:creators].present? ? result_geo[:creators] : result_geo[:contributors] %> <% if contributors %> <%= render partial: 'shared/contributors', locals: { contributors: contributors } %> <% end %>
    <% end %> - <% if result_geo['summary'].present? %> + <% if result_geo[:summary].present? %>

    - Summary: <%= result_geo['summary'] %> + Summary: <%= result_geo[:summary] %>

    <% end %> - <% if result_geo['highlight'] %> + <% if result_geo[:highlight] %>
    - <%= render partial: 'search/highlights', locals: { result: { 'highlight' => result_geo['highlight'] } } %> + <%= render partial: 'search/highlights', locals: { result: { highlight: result_geo[:highlight] } } %>
    <% end %>
    - <%= view_record(result_geo['identifier']) %> + <%= view_record(result_geo[:identifier]) %>
  • diff --git a/app/views/search/_result_primo.html.erb b/app/views/search/_result_primo.html.erb index bd4c5bba..89a9cbb7 100644 --- a/app/views/search/_result_primo.html.erb +++ b/app/views/search/_result_primo.html.erb @@ -2,22 +2,22 @@

    Title: - <% if result['links']&.find { |link| link['kind'] == 'full record' } %> - <%= link_to(result['title'], result['links'].find { |link| link['kind'] == 'full record' }['url']) %> + <% if result[:links]&.find { |link| link['kind'] == 'full record' } %> + <%= link_to(result[:title], result[:links].find { |link| link['kind'] == 'full record' }['url']) %> <% else %> - <%= result['title'] %> + <%= result[:title] %> <% end %>

    - <%= result['format'] %> - <%= result['year'] %> + <%= result[:format] %> + <%= result[:year] %>

    - <% if result['creators'].present? %> + <% if result[:creators].present? %> Contributors: diff --git a/test/controllers/search_controller_test.rb b/test/controllers/search_controller_test.rb index 4f5d0615..1f4d3bf3 100644 --- a/test/controllers/search_controller_test.rb +++ b/test/controllers/search_controller_test.rb @@ -4,14 +4,14 @@ class SearchControllerTest < ActionDispatch::IntegrationTest def mock_primo_search_success # Mock the Primo search components to avoid external API calls sample_doc = { - 'title' => 'Sample Primo Document Title', - 'format' => 'Article', - 'year' => '2025', - 'creators' => [ + title: 'Sample Primo Document Title', + format: 'Article', + year: '2025', + creators: [ { value: 'Foo Barston', link: nil }, { value: 'Baz Quxley', link: nil } ], - 'links' => [{ 'kind' => 'full record', 'url' => 'https://example.com/record' }] + links: [{ 'kind' => 'full record', 'url' => 'https://example.com/record' }] } mock_primo = mock('primo_search') diff --git a/test/helpers/search_helper_test.rb b/test/helpers/search_helper_test.rb index aac77742..ccb83f6a 100644 --- a/test/helpers/search_helper_test.rb +++ b/test/helpers/search_helper_test.rb @@ -4,36 +4,36 @@ class SearchHelperTest < ActionView::TestCase include SearchHelper test 'removes displayed fields from highlights' do - result = { 'highlight' => [{ 'matchedField' => 'title', 'matchedPhrases' => 'Very important data' }, - { 'matchedField' => 'title.exact_value', 'matchedPhrases' => 'Very important data' }, - { 'matchedField' => 'content_type', 'matchedPhrases' => 'Dataset' }, - { 'matchedField' => 'dates.value', 'matchedPhrases' => '2022' }, - { 'matchedField' => 'contributors.value', 'matchedPhrases' => 'Jane Datascientist' }] } + result = { highlight: [{ 'matchedField' => 'title', 'matchedPhrases' => 'Very important data' }, + { 'matchedField' => 'title.exact_value', 'matchedPhrases' => 'Very important data' }, + { 'matchedField' => 'content_type', 'matchedPhrases' => 'Dataset' }, + { 'matchedField' => 'dates.value', 'matchedPhrases' => '2022' }, + { 'matchedField' => 'contributors.value', 'matchedPhrases' => 'Jane Datascientist' }] } assert_empty trim_highlights(result) end test 'does not remove undisplayed fields from highlights' do - result = { 'highlight' => [{ 'matchedField' => 'summary', 'matchedPhrases' => 'Have some data' }] } + result = { highlight: [{ 'matchedField' => 'summary', 'matchedPhrases' => 'Have some data' }] } assert_equal [{ 'matchedField' => 'summary', 'matchedPhrases' => 'Have some data' }], trim_highlights(result) end test 'returns correct set of highlights when result includes displayed and undisplayed fields' do - result = { 'highlight' => [{ 'matchedField' => 'title', 'matchedPhrases' => 'Very important data' }, - { 'matchedField' => 'content_type', 'matchedPhrases' => 'Dataset' }, - { 'matchedField' => 'summary', 'matchedPhrases' => '2022' }, - { 'matchedField' => 'citation', 'matchedPhrases' => 'Datascientist, Jane' }] } + result = { highlight: [{ 'matchedField' => 'title', 'matchedPhrases' => 'Very important data' }, + { 'matchedField' => 'content_type', 'matchedPhrases' => 'Dataset' }, + { 'matchedField' => 'summary', 'matchedPhrases' => '2022' }, + { 'matchedField' => 'citation', 'matchedPhrases' => 'Datascientist, Jane' }] } assert_equal [{ 'matchedField' => 'summary', 'matchedPhrases' => '2022' }, { 'matchedField' => 'citation', 'matchedPhrases' => 'Datascientist, Jane' }], trim_highlights(result) end test 'renders view_online link if source_link is present' do - result = { 'title' => 'A record', 'source_link' => 'https://example.org' } + result = { title: 'A record', source_link: 'https://example.org' } assert_equal 'View online', view_online(result) end test 'does not render view_online link if source_link is absent' do - result = { 'title' => 'A record' } + result = { title: 'A record' } assert_nil view_online(result) end @@ -169,8 +169,8 @@ class SearchHelperTest < ActionView::TestCase test 'link_to_result returns link when source_link is present' do result = { - 'title' => 'Sample Document Title', - 'source_link' => 'https://example.com/document' + title: 'Sample Document Title', + source_link: 'https://example.com/document' } expected_link = 'Sample Document Title' assert_equal expected_link, link_to_result(result) @@ -178,23 +178,23 @@ class SearchHelperTest < ActionView::TestCase test 'link_to_result returns plain title when source_link is nil' do result = { - 'title' => 'Sample Document Title', - 'source_link' => nil + title: 'Sample Document Title', + source_link: nil } assert_equal 'Sample Document Title', link_to_result(result) end test 'link_to_result returns plain title when source_link is empty string' do result = { - 'title' => 'Sample Document Title', - 'source_link' => '' + title: 'Sample Document Title', + source_link: '' } assert_equal 'Sample Document Title', link_to_result(result) end test 'link_to_result returns plain title when source_link key is absent' do result = { - 'title' => 'Sample Document Title' + title: 'Sample Document Title' } assert_equal 'Sample Document Title', link_to_result(result) end diff --git a/test/models/normalize_primo_record_test.rb b/test/models/normalize_primo_record_test.rb index f7992551..b8e1740d 100644 --- a/test/models/normalize_primo_record_test.rb +++ b/test/models/normalize_primo_record_test.rb @@ -22,128 +22,128 @@ def cdi_record test 'normalizes title' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - assert_equal 'Testing the Limits of Knowledge', normalized['title'] + assert_equal 'Testing the Limits of Knowledge', normalized[:title] end test 'handles missing title' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_equal 'unknown title', normalized['title'] + assert_equal 'unknown title', normalized[:title] end test 'normalizes creators' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize expected_creators = ['Smith, John A.', 'Jones, Mary B.', 'Brown, Robert C.'] - assert_equal expected_creators.sort, normalized['creators'].map { |c| c[:value] }.sort + assert_equal expected_creators.sort, normalized[:creators].map { |c| c[:value] }.sort end test 'handles missing creators' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_empty normalized['creators'] + assert_empty normalized[:creators] end test 'normalizes source' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - assert_equal 'Primo', normalized['source'] + assert_equal 'Primo', normalized[:source] end test 'normalizes year' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - assert_equal '2023', normalized['year'] + assert_equal '2023', normalized[:year] end test 'handles missing year' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_nil normalized['year'] + assert_nil normalized[:year] end test 'normalizes format' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - assert_equal 'Book', normalized['format'] + assert_equal 'Book', normalized[:format] end test 'handles missing format' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_nil normalized['format'] + assert_nil normalized[:format] end test 'normalizes links' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize # First link should be the record link - assert_equal 'full record', normalized['links'].first['kind'] + assert_equal 'full record', normalized[:links].first['kind'] # Second link should be the Alma openurl - assert_equal 'openurl', normalized['links'].second['kind'] + assert_equal 'openurl', normalized[:links].second['kind'] end test 'handles missing links' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_empty normalized['links'] + assert_empty normalized[:links] end test 'normalizes citation' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - assert_equal 'volume 2 issue 3', normalized['citation'] + assert_equal 'volume 2 issue 3', normalized[:citation] end test 'handles missing citation' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_nil normalized['citation'] + assert_nil normalized[:citation] end test 'normalizes container title' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - assert_equal 'Journal of Testing', normalized['container'] + assert_equal 'Journal of Testing', normalized[:container] end test 'handles missing container title' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_nil normalized['container'] + assert_nil normalized[:container] end test 'normalizes identifier' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - assert_equal 'alma991000000001234567', normalized['identifier'] + assert_equal 'alma991000000001234567', normalized[:identifier] end test 'normalizes summary' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - assert_equal 'A comprehensive study of testing methodologies', normalized['summary'] + assert_equal 'A comprehensive study of testing methodologies', normalized[:summary] end test 'handles missing summary' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_nil normalized['summary'] + assert_nil normalized[:summary] end test 'handles missing identifier' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_nil normalized['identifier'] + assert_nil normalized[:identifier] end test 'normalizes numbering' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - assert_equal 'volume 2 issue 3', normalized['numbering'] + assert_equal 'volume 2 issue 3', normalized[:numbering] end test 'handles missing numbering' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_nil normalized['numbering'] + assert_nil normalized[:numbering] end test 'normalizes chapter numbering' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - assert_equal '2023, pp. 123-145', normalized['chapter_numbering'] + assert_equal '2023, pp. 123-145', normalized[:chapter_numbering] end test 'handles missing chapter numbering' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_nil normalized['chapter_numbering'] + assert_nil normalized[:chapter_numbering] end test 'includes FRBRized dedup record link in links when available' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - record_link = normalized['links'].find { |link| link['kind'] == 'full record' } + record_link = normalized[:links].find { |link| link['kind'] == 'full record' } assert_not_nil record_link # For FRBRized records, should use dedup URL format @@ -154,69 +154,69 @@ def cdi_record test 'generates thumbnail from ISBN' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize expected_url = 'https://syndetics.com/index.php?client=primo&isbn=9781234567890/sc.jpg' - assert_equal expected_url, normalized['thumbnail'] + assert_equal expected_url, normalized[:thumbnail] end test 'handles missing ISBN for thumbnail' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_nil normalized['thumbnail'] + assert_nil normalized[:thumbnail] end test 'extracts publisher information' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - assert_equal 'MIT Press', normalized['publisher'] + assert_equal 'MIT Press', normalized[:publisher] end test 'handles missing publisher' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_nil normalized['publisher'] + assert_nil normalized[:publisher] end test 'returns best location with call number' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize expected_location = ['Hayden Library Stacks', 'QA76.73.R83 2023'] - assert_equal expected_location, normalized['location'] + assert_equal expected_location, normalized[:location] end test 'handles missing location' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_nil normalized['location'] + assert_nil normalized[:location] end test 'extracts subjects' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize expected_subjects = ['Computer Science', 'Software Testing'] - assert_equal expected_subjects, normalized['subjects'] + assert_equal expected_subjects, normalized[:subjects] end test 'handles missing subjects' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_empty normalized['subjects'] + assert_empty normalized[:subjects] end test 'returns availability status' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - assert_equal 'available', normalized['availability'] + assert_equal 'available', normalized[:availability] end test 'handles missing availability' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_nil normalized['availability'] + assert_nil normalized[:availability] end test 'detects other availability when multiple holdings exist' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - assert normalized['other_availability'] + assert normalized[:other_availability] end test 'handles missing other availability' do normalized = NormalizePrimoRecord.new(minimal_record, 'test').normalize - assert_nil normalized['other_availability'] + assert_nil normalized[:other_availability] end test 'uses dedup URL as full record link for frbrized records' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - full_record_link = normalized['links'].find { |link| link['kind'] == 'full record' } + full_record_link = normalized[:links].find { |link| link['kind'] == 'full record' } assert_not_nil full_record_link expected_base = 'https://mit.primo.exlibrisgroup.com/discovery/search?' @@ -230,18 +230,18 @@ def cdi_record record_without_frbr['pnx']['facets']['frbrtype'] = ['3'] normalized = NormalizePrimoRecord.new(record_without_frbr, 'test').normalize - full_record_link = normalized['links'].find { |link| link['kind'] == 'full record' } + full_record_link = normalized[:links].find { |link| link['kind'] == 'full record' } assert_not_nil full_record_link assert_match %r{/discovery/fulldisplay\?}, full_record_link['url'] end test 'includes expected link types when available' do normalized = NormalizePrimoRecord.new(full_record, 'test query').normalize - link_kinds = normalized['links'].map { |link| link['kind'] } + link_kinds = normalized[:links].map { |link| link['kind'] } assert_includes link_kinds, 'full record' assert_includes link_kinds, 'openurl' - assert_equal 2, normalized['links'].length # Only full record and openurl + assert_equal 2, normalized[:links].length # Only full record and openurl end # Additional coverage tests for existing methods @@ -249,7 +249,7 @@ def cdi_record record = full_record.deep_dup record['pnx']['display']['creator'] = ['Smith, John A.; Doe, Jane B.'] normalized = NormalizePrimoRecord.new(record, 'test').normalize - creators = normalized['creators'].map { |c| c[:value] } + creators = normalized[:creators].map { |c| c[:value] } assert_includes creators, 'Smith, John A.' assert_includes creators, 'Doe, Jane B.' end @@ -258,12 +258,12 @@ def cdi_record record = full_record.deep_dup record['pnx']['display']['creator'] = ['Smith, John A.$$QAuthor'] normalized = NormalizePrimoRecord.new(record, 'test').normalize - assert_equal 'Smith, John A.', normalized['creators'].first[:value] + assert_equal 'Smith, John A.', normalized[:creators].first[:value] end test 'constructs author search links' do normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - creator_link = normalized['creators'].first[:link] + creator_link = normalized[:creators].first[:link] assert_match 'discovery/search?query=creator,exact,', creator_link assert_match 'Smith%2C%20John%20A.', creator_link end @@ -280,7 +280,7 @@ def cdi_record record = full_record.deep_dup record['pnx']['display']['type'] = [input] normalized = NormalizePrimoRecord.new(record, 'test').normalize - assert_equal expected, normalized['format'] + assert_equal expected, normalized[:format] end end @@ -289,7 +289,7 @@ def cdi_record record['pnx']['search'] = { 'creationdate' => ['2022'] } normalized = NormalizePrimoRecord.new(record, 'test').normalize - assert_equal '2022', normalized['year'] + assert_equal '2022', normalized[:year] end test 'handles different citation formats' do @@ -297,12 +297,12 @@ def cdi_record record = full_record.deep_dup record['pnx']['addata'] = { 'volume' => ['5'] } normalized = NormalizePrimoRecord.new(record, 'test').normalize - assert_equal 'volume 5', normalized['citation'] + assert_equal 'volume 5', normalized[:citation] # Test with date and pages record['pnx']['addata'] = { 'date' => ['2023'], 'pages' => ['10-20'] } normalized = NormalizePrimoRecord.new(record, 'test').normalize - assert_equal '2023, pp. 10-20', normalized['citation'] + assert_equal '2023, pp. 10-20', normalized[:citation] end test 'prefers jtitle over btitle for container' do @@ -311,7 +311,7 @@ def cdi_record record['pnx']['addata']['btitle'] = ['Book Title'] normalized = NormalizePrimoRecord.new(record, 'test').normalize - assert_equal 'Journal Title', normalized['container'] + assert_equal 'Journal Title', normalized[:container] end test 'uses btitle when jtitle is not present for container' do @@ -320,20 +320,20 @@ def cdi_record record['pnx']['addata']['btitle'] = ['Book Title Only'] normalized = NormalizePrimoRecord.new(record, 'test').normalize - assert_equal 'Book Title Only', normalized['container'] + assert_equal 'Book Title Only', normalized[:container] end test 'handles openurl server validation' do # Test with matching server normalized = NormalizePrimoRecord.new(full_record, 'test').normalize - openurl_link = normalized['links'].find { |link| link['kind'] == 'openurl' } + openurl_link = normalized[:links].find { |link| link['kind'] == 'openurl' } assert_not_nil openurl_link # Test with mismatched server. Should log warning but still return URL record = full_record.deep_dup record['delivery']['almaOpenurl'] = 'https://different.server.com/openurl?param=value' normalized = NormalizePrimoRecord.new(record, 'test').normalize - openurl_link = normalized['links'].find { |link| link['kind'] == 'openurl' } + openurl_link = normalized[:links].find { |link| link['kind'] == 'openurl' } assert_not_nil openurl_link end @@ -355,7 +355,7 @@ def cdi_record test 'generates FRBR dedup URL for Alma records when frbrized' do normalized = NormalizePrimoRecord.new(alma_record, 'test query').normalize - full_record_link = normalized['links'].find { |link| link['kind'] == 'full record' } + full_record_link = normalized[:links].find { |link| link['kind'] == 'full record' } assert_not_nil full_record_link # Should use dedup URL for Alma records @@ -365,7 +365,7 @@ def cdi_record test 'does not generate FRBR dedup URL for CDI records even when frbrized' do normalized = NormalizePrimoRecord.new(cdi_record, 'test query').normalize - full_record_link = normalized['links'].find { |link| link['kind'] == 'full record' } + full_record_link = normalized[:links].find { |link| link['kind'] == 'full record' } assert_not_nil full_record_link # Should use regular record link for CDI records, not dedup URL @@ -378,7 +378,7 @@ def cdi_record record['pnx']['facets']['frbrtype'] = ['3'] # Not frbrized normalized = NormalizePrimoRecord.new(record, 'test').normalize - full_record_link = normalized['links'].find { |link| link['kind'] == 'full record' } + full_record_link = normalized[:links].find { |link| link['kind'] == 'full record' } assert_not_nil full_record_link # Should use regular record link when not frbrized diff --git a/test/models/normalize_primo_results_test.rb b/test/models/normalize_primo_results_test.rb index 1fb9f649..f1d3ff16 100644 --- a/test/models/normalize_primo_results_test.rb +++ b/test/models/normalize_primo_results_test.rb @@ -27,8 +27,8 @@ def empty_results normalized = normalizer.normalize assert_equal 2, normalized.length - assert_equal 'Testing the Limits of Knowledge', normalized.first['title'] - assert_equal 'unknown title', normalized.second['title'] + assert_equal 'Testing the Limits of Knowledge', normalized.first[:title] + assert_equal 'unknown title', normalized.second[:title] end test 'handles empty results' do diff --git a/test/models/normalize_timdex_record_test.rb b/test/models/normalize_timdex_record_test.rb index 58addee7..d3540603 100644 --- a/test/models/normalize_timdex_record_test.rb +++ b/test/models/normalize_timdex_record_test.rb @@ -11,14 +11,14 @@ def minimal_record test 'normalizes title' do normalized = NormalizeTimdexRecord.new(full_record, 'test').normalize - assert_equal 'Sample TIMDEX Record for Testing', normalized['title'] + assert_equal 'Sample TIMDEX Record for Testing', normalized[:title] end test 'handles missing title' do record_without_title = minimal_record record_without_title.delete('title') normalized = NormalizeTimdexRecord.new(record_without_title, 'test').normalize - assert_equal 'Unknown title', normalized['title'] + assert_equal 'Unknown title', normalized[:title] end test 'normalizes creators from contributors' do @@ -27,34 +27,34 @@ def minimal_record { 'value' => 'Smith, Jane', 'link' => nil }, { 'value' => 'Doe, John', 'link' => nil } ] - assert_equal expected_creators, normalized['creators'] + assert_equal expected_creators, normalized[:creators] end test 'handles missing creators' do normalized = NormalizeTimdexRecord.new(minimal_record, 'test').normalize - assert_empty normalized['creators'] + assert_empty normalized[:creators] end test 'normalizes source' do normalized = NormalizeTimdexRecord.new(full_record, 'test').normalize - assert_equal 'Test Repository', normalized['source'] + assert_equal 'Test Repository', normalized[:source] end test 'handles missing source' do record_without_source = minimal_record.dup record_without_source.delete('source') normalized = NormalizeTimdexRecord.new(record_without_source, 'test').normalize - assert_equal 'Unknown source', normalized['source'] + assert_equal 'Unknown source', normalized[:source] end test 'extracts year from publication date' do normalized = NormalizeTimdexRecord.new(full_record, 'test').normalize - assert_equal '2023', normalized['year'] + assert_equal '2023', normalized[:year] end test 'handles missing year' do normalized = NormalizeTimdexRecord.new(minimal_record, 'test').normalize - assert_nil normalized['year'] + assert_nil normalized[:year] end test 'extracts year from fallback date when no publication date' do @@ -64,19 +64,19 @@ def minimal_record { 'kind' => 'Creation', 'value' => 'Created in 1998' } ] normalized = NormalizeTimdexRecord.new(record_with_coverage_date, 'test').normalize - assert_equal '1995', normalized['year'] + assert_equal '1995', normalized[:year] end test 'normalizes format from content type' do normalized = NormalizeTimdexRecord.new(full_record, 'test').normalize - assert_equal 'Dataset ; Geospatial data', normalized['format'] + assert_equal 'Dataset ; Geospatial data', normalized[:format] end test 'handles missing format' do record_without_format = minimal_record.dup record_without_format.delete('contentType') normalized = NormalizeTimdexRecord.new(record_without_format, 'test').normalize - assert_empty normalized['format'] + assert_empty normalized[:format] end test 'normalizes links from source link' do @@ -88,59 +88,59 @@ def minimal_record 'text' => 'View full record' } ] - assert_equal expected_links, normalized['links'] + assert_equal expected_links, normalized[:links] end test 'handles missing links' do normalized = NormalizeTimdexRecord.new(minimal_record, 'test').normalize - assert_empty normalized['links'] + assert_empty normalized[:links] end test 'normalizes citation' do normalized = NormalizeTimdexRecord.new(full_record, 'test').normalize assert_equal 'Smith, J. & Doe, J. (2023). Sample TIMDEX Record for Testing. Test Repository.', - normalized['citation'] + normalized[:citation] end test 'handles missing citation' do normalized = NormalizeTimdexRecord.new(minimal_record, 'test').normalize - assert_nil normalized['citation'] + assert_nil normalized[:citation] end test 'normalizes identifier' do normalized = NormalizeTimdexRecord.new(full_record, 'test').normalize - assert_equal 'test-record-123', normalized['identifier'] + assert_equal 'test-record-123', normalized[:identifier] end test 'normalizes summary' do normalized = NormalizeTimdexRecord.new(full_record, 'test').normalize assert_equal 'This is a comprehensive test record with all possible fields populated for testing normalization.', - normalized['summary'] + normalized[:summary] end test 'handles missing summary' do normalized = NormalizeTimdexRecord.new(minimal_record, 'test').normalize - assert_nil normalized['summary'] + assert_nil normalized[:summary] end test 'extracts publisher from contributors' do normalized = NormalizeTimdexRecord.new(full_record, 'test').normalize - assert_equal 'MIT Libraries', normalized['publisher'] + assert_equal 'MIT Libraries', normalized[:publisher] end test 'handles missing publisher' do normalized = NormalizeTimdexRecord.new(minimal_record, 'test').normalize - assert_nil normalized['publisher'] + assert_nil normalized[:publisher] end test 'normalizes location' do normalized = NormalizeTimdexRecord.new(full_record, 'test').normalize - assert_equal 'Cambridge, MA', normalized['location'] + assert_equal 'Cambridge, MA', normalized[:location] end test 'handles missing location' do normalized = NormalizeTimdexRecord.new(minimal_record, 'test').normalize - assert_nil normalized['location'] + assert_nil normalized[:location] end test 'joins multiple locations with semicolon' do @@ -151,17 +151,17 @@ def minimal_record { 'value' => 'New York, NY' } ] normalized = NormalizeTimdexRecord.new(record_with_multiple_locations, 'test').normalize - assert_equal 'Cambridge, MA; Boston, MA; New York, NY', normalized['location'] + assert_equal 'Cambridge, MA; Boston, MA; New York, NY', normalized[:location] end test 'normalizes subjects' do normalized = NormalizeTimdexRecord.new(full_record, 'test').normalize - assert_equal ['Geographic Information Systems', 'Remote Sensing'], normalized['subjects'] + assert_equal ['Geographic Information Systems', 'Remote Sensing'], normalized[:subjects] end test 'handles missing subjects' do normalized = NormalizeTimdexRecord.new(minimal_record, 'test').normalize - assert_empty normalized['subjects'] + assert_empty normalized[:subjects] end # Test TIMDEX-specific fields @@ -171,7 +171,7 @@ def minimal_record { 'value' => 'Dataset' }, { 'value' => 'Geospatial data' } ] - assert_equal expected_content_type, normalized['content_type'] + assert_equal expected_content_type, normalized[:content_type] end test 'includes TIMDEX-specific dates field' do @@ -180,7 +180,7 @@ def minimal_record { 'kind' => 'Publication date', 'value' => '2023-01-15' }, { 'kind' => 'Coverage', 'value' => '2020-2023' } ] - assert_equal expected_dates, normalized['dates'] + assert_equal expected_dates, normalized[:dates] end test 'includes TIMDEX-specific contributors field' do @@ -190,7 +190,7 @@ def minimal_record { 'kind' => 'Author', 'value' => 'Doe, John' }, { 'kind' => 'Publisher', 'value' => 'MIT Libraries' } ] - assert_equal expected_contributors, normalized['contributors'] + assert_equal expected_contributors, normalized[:contributors] end test 'includes TIMDEX-specific highlight field' do @@ -199,12 +199,12 @@ def minimal_record 'title' => ['Sample TIMDEX Record'], 'summary' => ['comprehensive test record'] } - assert_equal expected_highlight, normalized['highlight'] + assert_equal expected_highlight, normalized[:highlight] end test 'includes TIMDEX-specific source_link field' do normalized = NormalizeTimdexRecord.new(full_record, 'test').normalize - assert_equal 'https://example.com/source/record/123', normalized['source_link'] + assert_equal 'https://example.com/source/record/123', normalized[:source_link] end # Test that Primo-only fields are not included diff --git a/test/models/normalize_timdex_results_test.rb b/test/models/normalize_timdex_results_test.rb index 08c3fda9..c7e71267 100644 --- a/test/models/normalize_timdex_results_test.rb +++ b/test/models/normalize_timdex_results_test.rb @@ -20,24 +20,24 @@ def empty_timdex_response # Check first record (full record) first_result = results.first - assert_equal 'Sample TIMDEX Record for Testing', first_result['title'] - assert_equal 'test-record-123', first_result['identifier'] - assert_equal 'Test Repository', first_result['source'] - assert_equal 'Dataset ; Geospatial data', first_result['format'] - assert_equal '2023', first_result['year'] + assert_equal 'Sample TIMDEX Record for Testing', first_result[:title] + assert_equal 'test-record-123', first_result[:identifier] + assert_equal 'Test Repository', first_result[:source] + assert_equal 'Dataset ; Geospatial data', first_result[:format] + assert_equal '2023', first_result[:year] # Check TIMDEX-specific fields are preserved - assert_includes first_result.keys, 'content_type' - assert_includes first_result.keys, 'dates' - assert_includes first_result.keys, 'contributors' - assert_includes first_result.keys, 'highlight' - assert_includes first_result.keys, 'source_link' + assert_includes first_result.keys, :content_type + assert_includes first_result.keys, :dates + assert_includes first_result.keys, :contributors + assert_includes first_result.keys, :highlight + assert_includes first_result.keys, :source_link # Check second record (minimal record) second_result = results.second - assert_equal 'Minimal Test Record', second_result['title'] - assert_equal 'minimal-record-456', second_result['identifier'] - assert_equal 'Test Repository', second_result['source'] + assert_equal 'Minimal Test Record', second_result[:title] + assert_equal 'minimal-record-456', second_result[:identifier] + assert_equal 'Test Repository', second_result[:source] end test 'handles empty TIMDEX response' do