Browse Source

CLDC-1381-Postcode-display-formatting (#781)

pull/807/head
Ted-U 2 years ago committed by GitHub
parent
commit
6d0d40fb22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      app/models/case_log.rb
  2. 10
      app/models/location.rb
  3. 4
      app/models/scheme.rb
  4. 2
      spec/features/schemes_helpers.rb
  5. 8
      spec/features/schemes_spec.rb

19
app/models/case_log.rb

@ -8,7 +8,6 @@ class CaseLogValidator < ActiveModel::Validator
include Validations::TenancyValidations
include Validations::DateValidations
include Validations::LocalAuthorityValidations
def validate(record)
validation_methods = public_methods.select { |method| method.starts_with?("validate_") }
validation_methods.each { |meth| public_send(meth, record) }
@ -57,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 ?", "%#{postcode_full.gsub(/\s+/, '')}%") }
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))
@ -118,6 +117,22 @@ class CaseLog < ApplicationRecord
end
end
def postcode_full=(postcode)
if postcode
super UKPostcode.parse(postcode).to_s
else
super nil
end
end
def ppostcode_full=(postcode)
if postcode
super UKPostcode.parse(postcode).to_s
else
super nil
end
end
def completed?
status == "completed"
end

10
app/models/location.rb

@ -9,7 +9,7 @@ class Location < ApplicationRecord
attr_accessor :add_another_location
scope :search_by_postcode, ->(postcode) { where("postcode ILIKE ?", "%#{postcode.gsub(/\s+/, '')}%") }
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)) }
@ -42,6 +42,14 @@ class Location < ApplicationRecord
]
end
def postcode=(postcode)
if postcode
super UKPostcode.parse(postcode).to_s
else
super nil
end
end
private
PIO = PostcodeService.new

4
app/models/scheme.rb

@ -8,8 +8,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 ?", "%#{postcode.delete(' ')}%") }
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/features/schemes_helpers.rb

@ -68,7 +68,7 @@ module SchemesHelpers
end
def fill_in_and_save_second_location
fill_in "Postcode", with: "XX1 1XX"
fill_in "Postcode", with: "AA12AA"
fill_in "Location name (optional)", with: "Other name"
fill_in "Total number of units at this location", with: 2
choose "Self-contained house"

8
spec/features/schemes_spec.rb

@ -493,7 +493,7 @@ RSpec.describe "Schemes scheme Features" do
it "displays information about newly created location" do
click_link "Add a location"
fill_in_and_save_second_location
expect(page).to have_content "XX11XX"
expect(page).to have_content "AA1 2AA"
expect(page).to have_content "Other name"
expect(page).to have_content "Self-contained house"
end
@ -507,13 +507,13 @@ RSpec.describe "Schemes scheme Features" do
end
it "displays changed location" do
click_link "XX11XX"
fill_in "Postcode", with: "ZZ1 1ZZ"
click_link "AA1 2AA"
fill_in "Postcode", with: "AA1 3AA"
choose "location-mobility-type-wheelchair-user-standard-field"
click_button "Save and continue"
expect(page).to have_content "Locations"
expect(page).to have_content "#{scheme.locations.count} location"
expect(page).to have_content "ZZ11ZZ"
expect(page).to have_content "AA1 3AA"
end
end

Loading…
Cancel
Save