Skip to content

Commit

Permalink
Merge pull request #438 from uclibs/418/item-record-search
Browse files Browse the repository at this point in the history
Include uncataloged id's in item record search
  • Loading branch information
Janell-Huyck authored Mar 6, 2024
2 parents e47b781 + a426191 commit 668b568
Show file tree
Hide file tree
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
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions spec/controllers/search_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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')
Expand Down

0 comments on commit 668b568

Please # to comment.