Browse Source

CLDC-2575 Allow searches by Log Id to include "log" (#2297)

* feat: allow log id searches that include "log" before the id

* feat: make filtering case insensitive

* refactor: lint
pull/2302/head
natdeanlewissoftwire 10 months ago committed by GitHub
parent
commit
6493677d61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/models/lettings_log.rb
  2. 2
      app/models/sales_log.rb
  3. 12
      spec/models/lettings_log_spec.rb
  4. 44
      spec/models/sales_log_spec.rb

2
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) }

2
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|

12
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") }

44
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))

Loading…
Cancel
Save