Browse Source

Remove spaces in postcode searches

Co-Authored-By: Katrina <katrina@madetech.com>
pull/781/head
Stéphane Meny 3 years ago
parent
commit
066e58fdd1
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 2
      app/models/case_log.rb
  2. 2
      app/models/location.rb
  3. 4
      app/models/scheme.rb
  4. 2
      spec/requests/case_logs_controller_spec.rb

2
app/models/case_log.rb

@ -56,7 +56,7 @@ class CaseLog < ApplicationRecord
scope :filter_by_id, ->(id) { where(id:) }
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("postcode_full ILIKE ?", "%#{UKPostcode.parse(postcode_full)}%") }
scope :filter_by_postcode, ->(postcode_full) { where("REPLACE(postcode_full, ' ', '') ILIKE ?", "%#{postcode_full.delete(' ')}%") }
scope :search_by, lambda { |param|
filter_by_id(param)
.or(filter_by_tenant_code(param))

2
app/models/location.rb

@ -7,7 +7,7 @@ class Location < ApplicationRecord
attr_accessor :add_another_location
scope :search_by_postcode, ->(postcode) { where("postcode ILIKE ?", "%#{UKPostcode.parse(postcode)}%") }
scope :search_by_postcode, ->(postcode) { where("REPLACE(postcode, ' ', '') ILIKE ?", "%#{postcode.delete(' ')}%") }
scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") }
scope :search_by, ->(param) { search_by_name(param).or(search_by_postcode(param)) }

4
app/models/scheme.rb

@ -6,8 +6,8 @@ class Scheme < ApplicationRecord
scope :filter_by_id, ->(id) { where(id: (id.start_with?("S") ? id[1..] : id)) }
scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") }
scope :search_by_postcode, ->(postcode) { joins("LEFT JOIN locations ON locations.scheme_id = schemes.id").where("locations.postcode ILIKE ?", "%#{UKPostcode.parse(postcode)}%") }
scope :search_by_location_name, ->(name) { joins("LEFT JOIN locations ON locations.scheme_id = schemes.id").where("locations.name ILIKE ?", "%#{name}%") }
scope :search_by_postcode, ->(postcode) { left_joins(:locations).where("REPLACE(locations.postcode, ' ', '') ILIKE ?", "%#{postcode.delete(' ')}%") }
scope :search_by_location_name, ->(name) { left_joins(:locations).where("locations.name ILIKE ?", "%#{name}%") }
scope :search_by, lambda { |param|
search_by_postcode(param)
.or(search_by_service_name(param))

2
spec/requests/case_logs_controller_spec.rb

@ -792,7 +792,7 @@ RSpec.describe CaseLogsController, type: :request do
it "downloads logs matching both csv and filter logs" do
get "/logs?status[]=completed&search=#{postcode}", headers:, params: {}
csv = CSV.parse(response.body)
expect(csv.count).to eq(1)
expect(csv.count).to eq(2)
end
end
end

Loading…
Cancel
Save