diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 254953c19..9d760998d 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -6,7 +6,7 @@ class Scheme < ApplicationRecord has_paper_trail - scope :filter_by_id, ->(id) { where(id: (id.start_with?("S") ? id[1..] : id)) } + scope :filter_by_id, ->(id) { where(id: (id.start_with?("S", "s") ? id[1..] : id)) } scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") } scope :search_by_postcode, ->(postcode) { where("schemes.id IN (SELECT DISTINCT scheme_id FROM locations WHERE REPLACE(locations.postcode, ' ', '') ILIKE ?)", "%#{postcode.delete(' ')}%") } scope :search_by_location_name, ->(name) { where("schemes.id IN (SELECT DISTINCT scheme_id FROM locations WHERE locations.name ILIKE ?)", "%#{name}%") } diff --git a/spec/models/scheme_spec.rb b/spec/models/scheme_spec.rb index 70eccc5c2..cb9d74578 100644 --- a/spec/models/scheme_spec.rb +++ b/spec/models/scheme_spec.rb @@ -77,6 +77,8 @@ RSpec.describe Scheme, type: :model do it "returns case insensitive matching records" do expect(described_class.search_by(scheme_1.id.to_s).count).to eq(1) + expect(described_class.search_by("S#{scheme_1.id}").count).to eq(1) + expect(described_class.search_by("s#{scheme_1.id}").count).to eq(1) expect(described_class.search_by(scheme_1.id.to_s).first.id).to eq(scheme_1.id) expect(described_class.search_by(scheme_2.service_name.upcase).count).to eq(1) expect(described_class.search_by(scheme_2.service_name.downcase).count).to eq(1)