Skip to content

Commit

Permalink
Include uncataloged id in item record search
Browse files Browse the repository at this point in the history
  • Loading branch information
crowesn committed Mar 5, 2024
1 parent e6a10a4 commit a426191
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions spec/controllers/search_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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')

0 comments on commit a426191

Please # to comment.