Browse Source

allow searching by a Property Postcode, when case log is supported housing (#818)

pull/819/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
981a81631b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      app/models/case_log.rb
  2. 28
      spec/models/case_log_spec.rb

10
app/models/case_log.rb

@ -57,11 +57,13 @@ class CaseLog < ApplicationRecord
scope :filter_by_tenant_code, ->(tenant_code) { where("tenancycode ILIKE ?", "%#{tenant_code}%") }
scope :filter_by_propcode, ->(propcode) { where("propcode ILIKE ?", "%#{propcode}%") }
scope :filter_by_postcode, ->(postcode_full) { where("REPLACE(postcode_full, ' ', '') ILIKE ?", "%#{postcode_full.delete(' ')}%") }
scope :filter_by_location_postcode, ->(postcode_full) { left_joins(:location).where("REPLACE(locations.postcode, ' ', '') ILIKE ?", "%#{postcode_full.delete(' ')}%") }
scope :search_by, lambda { |param|
filter_by_id(param)
.or(filter_by_tenant_code(param))
.or(filter_by_propcode(param))
.or(filter_by_postcode(param))
filter_by_location_postcode(param)
.or(filter_by_tenant_code(param))
.or(filter_by_propcode(param))
.or(filter_by_postcode(param))
.or(filter_by_id(param))
}
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze

28
spec/models/case_log_spec.rb

@ -2073,6 +2073,20 @@ RSpec.describe CaseLog do
expect(result.count).to eq(1)
expect(result.first.id).to eq case_log_to_search.id
end
context "when case log is supported housing" do
let(:location) { FactoryBot.create(:location, postcode: "W6 0ST") }
before do
case_log_to_search.update!(needstype: 2, location:)
end
it "allows searching by a Property Postcode" do
result = described_class.filter_by_location_postcode("W6 0ST")
expect(result.count).to eq(1)
expect(result.first.id).to eq case_log_to_search.id
end
end
end
describe "#search_by" do
@ -2100,6 +2114,20 @@ RSpec.describe CaseLog do
expect(result.first.id).to eq case_log_to_search.id
end
context "when case log is supported housing" do
let(:location) { FactoryBot.create(:location, postcode: "W6 0ST") }
before do
case_log_to_search.update!(needstype: 2, location:)
end
it "allows searching by a Property Postcode" do
result = described_class.search_by("W6 0ST")
expect(result.count).to eq(1)
expect(result.first.id).to eq case_log_to_search.id
end
end
context "when postcode has spaces and lower case letters" do
let(:matching_postcode_lower_case_with_spaces) { case_log_to_search.postcode_full.downcase.chars.insert(3, " ").join }

Loading…
Cancel
Save