diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 5dc998bbb..88bc5a43e 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -62,7 +62,7 @@ class LettingsLog < Log .or(filter_by_tenant_code(param)) .or(filter_by_propcode(param)) .or(filter_by_postcode(param)) - .or(filter_by_id(param)) + .or(filter_by_id(param.gsub(/log/i, ""))) } scope :after_date, ->(date) { where("lettings_logs.startdate >= ?", date) } scope :before_date, ->(date) { where("lettings_logs.startdate < ?", date) } diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index b17956b3a..c22575aa5 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -47,7 +47,7 @@ class SalesLog < Log scope :search_by, lambda { |param| filter_by_purchaser_code(param) .or(filter_by_postcode(param)) - .or(filter_by_id(param)) + .or(filter_by_id(param.gsub(/log/i, ""))) } scope :age1_answered, -> { where.not(age1: nil).or(where(age1_known: [1, 2])) } scope :duplicate_logs, lambda { |log| diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index f27a7f7e5..225a25952 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -2828,6 +2828,18 @@ RSpec.describe LettingsLog do expect(result.first.id).to eq lettings_log_to_search.id end + it "allows searching by id including the word log" do + result = described_class.search_by("log#{lettings_log_to_search.id}") + expect(result.count).to eq(1) + expect(result.first.id).to eq lettings_log_to_search.id + end + + it "allows searching by id including the capitalised word Log" do + result = described_class.search_by("Log#{lettings_log_to_search.id}") + expect(result.count).to eq(1) + expect(result.first.id).to eq lettings_log_to_search.id + end + context "when lettings log is supported housing" do let(:location) { create(:location, postcode: "W6 0ST") } diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb index 1ad889e84..18b5dc5e8 100644 --- a/spec/models/sales_log_spec.rb +++ b/spec/models/sales_log_spec.rb @@ -162,6 +162,50 @@ RSpec.describe SalesLog, type: :model do end end + describe "#search_by" do + let!(:sales_log_to_search) { create(:sales_log, :completed) } + + it "allows searching using ID" do + result = described_class.search_by(sales_log_to_search.id.to_s) + expect(result.count).to eq(1) + expect(result.first.id).to eq sales_log_to_search.id + end + + it "allows searching using purchaser code" do + result = described_class.search_by(sales_log_to_search.purchaser_code) + expect(result.count).to eq(1) + expect(result.first.id).to eq sales_log_to_search.id + end + + it "allows searching by a Property Postcode" do + result = described_class.search_by(sales_log_to_search.postcode_full) + expect(result.count).to eq(1) + expect(result.first.id).to eq sales_log_to_search.id + end + + it "allows searching by id including the word log" do + result = described_class.search_by("log#{sales_log_to_search.id}") + expect(result.count).to eq(1) + expect(result.first.id).to eq sales_log_to_search.id + end + + it "allows searching by id including the capitalised word Log" do + result = described_class.search_by("Log#{sales_log_to_search.id}") + expect(result.count).to eq(1) + expect(result.first.id).to eq sales_log_to_search.id + end + + context "when postcode has spaces and lower case letters" do + let(:matching_postcode_lower_case_with_spaces) { sales_log_to_search.postcode_full.downcase.chars.insert(3, " ").join } + + it "allows searching by a Property Postcode" do + result = described_class.search_by(matching_postcode_lower_case_with_spaces) + expect(result.count).to eq(1) + expect(result.first.id).to eq sales_log_to_search.id + end + end + end + context "when filtering by year or nil" do before do Timecop.freeze(Time.utc(2021, 5, 3))