From a4261916b1e961c57740f06a85145e05f37509cb Mon Sep 17 00:00:00 2001 From: crowesn Date: Tue, 5 Mar 2024 14:31:53 -0500 Subject: [PATCH] Include uncataloged id in item record search --- app/controllers/search_controller.rb | 2 +- spec/controllers/search_controller_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index f486748e..3957e421 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -6,7 +6,7 @@ class SearchController < ApplicationController def results @search_string = params[:search] @records = case @search_string - when /^i\d{1,}/ + when /^[a-zA-Z]+\d{1,}/ ConservationRecord.where(item_record_number: @search_string) when /^\d+$/ ConservationRecord.where(id: @search_string) diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index 2b51b777..5cc088ee 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -11,6 +11,7 @@ sign_in_user(user) create(:conservation_record) create(:conservation_record, item_record_number: 'i1001') + create(:conservation_record, item_record_number: 'notcat2817') create(:conservation_record, title: 'Third Title') end @@ -29,6 +30,12 @@ def sign_in_user(user) expect(response).to redirect_to(conservation_record_path(expected_id)) end + it 'can search for documents by *un-cataloged* record number' do + get :results, params: { search: 'notcat2817' } + expected_id = ConservationRecord.find_by(item_record_number: 'notcat2817').id + expect(response).to redirect_to(conservation_record_path(expected_id)) + end + it 'can search for documents by title' do get :results, params: { search: 'Third' } expected_id = ConservationRecord.find_by(title: 'Third Title')