From 3114e06006207d349241c76c0cc24e23e38a51ed Mon Sep 17 00:00:00 2001 From: Anna Headley <845363+hackartisan@users.noreply.github.com> Date: Mon, 9 Oct 2023 14:34:27 -0400 Subject: [PATCH] Do case-insensitive exact match searching closes #178 --- app/models/guide_card.rb | 2 +- spec/system/search_feature_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/guide_card.rb b/app/models/guide_card.rb index 05a3eed..7115e62 100644 --- a/app/models/guide_card.rb +++ b/app/models/guide_card.rb @@ -7,7 +7,7 @@ class GuideCard < ApplicationRecord # First, try to find an exact match. Otherwise, find the closest match. def self.search_result(term) - match = GuideCard.find_by(heading: term) + match = GuideCard.find_by('heading ilike ?', term) return match if match.present? GuideCard.where('heading < ?', term).order(heading: :desc).limit(1).first diff --git a/spec/system/search_feature_spec.rb b/spec/system/search_feature_spec.rb index 1b80ae1..02a8035 100644 --- a/spec/system/search_feature_spec.rb +++ b/spec/system/search_feature_spec.rb @@ -31,5 +31,11 @@ click_on '1' expect(page).to have_link('AALAS') end + it 'ignores capitalization' do + visit '/' + fill_in 'search_term', with: 'aaron' + click_on 'Go' + expect(page).to have_link('* Aaron') + end end end