diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb
index 07508a51d..d1a953565 100644
--- a/app/controllers/locations_controller.rb
+++ b/app/controllers/locations_controller.rb
@@ -19,7 +19,6 @@ class LocationsController < ApplicationController
end
def details
- debugger
render :new
end
@@ -30,6 +29,8 @@ private
end
def location_params
- params.require(:location).permit(:postcode, :name, :total_units, :type_of_unit, :wheelchair_adaptation, :add_another_location).merge(scheme_id: @scheme.id)
+ required_params = params.require(:location).permit(:postcode, :name, :total_units, :type_of_unit, :wheelchair_adaptation, :add_another_location).merge(scheme_id: @scheme.id)
+ required_params[:postcode] = required_params[:postcode].gsub(" ", "").encode("ASCII", "UTF-8", invalid: :replace, undef: :replace, replace: "")
+ required_params
end
end
diff --git a/app/models/location.rb b/app/models/location.rb
index 92b8457e6..6361bcbef 100644
--- a/app/models/location.rb
+++ b/app/models/location.rb
@@ -1,4 +1,6 @@
class Location < ApplicationRecord
+ include Validations::PropertyValidations
+ validate :validate_postcode
belongs_to :scheme
attr_accessor :add_another_location
@@ -29,5 +31,15 @@ class Location < ApplicationRecord
{ name: "Type of building", value: type_of_building, suffix: false },
{ name: "Wheelchair adaptation", value: wheelchair_adaptation, suffix: false },
]
+ end
+
+private
+
+ def validate_postcode
+ unless postcode.match(Validations::PropertyValidations::POSTCODE_REGEXP)
+ debugger
+ error_message = I18n.t("validations.postcode")
+ errors.add :postcode, error_message
+ end
end
end
diff --git a/app/views/schemes/check_answers.html.erb b/app/views/schemes/check_answers.html.erb
index 7a5e98282..5265f3a99 100644
--- a/app/views/schemes/check_answers.html.erb
+++ b/app/views/schemes/check_answers.html.erb
@@ -67,7 +67,7 @@
<% component.tab(label: "Locations") do %>
<%= govuk_table do |table| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
- <%= @scheme.locations.count %> <%= @scheme.locations.count.eql?(1) ? "location" : "locations" %>.
+ <%= @scheme.locations.count %> <%= @scheme.locations.count.eql?(1) ? "location" : "locations" %>
<% end %>
<%= table.head do |head| %>
<%= head.row do |row| %>
diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb
index 554759bef..7d30ec2e9 100644
--- a/spec/features/schemes_spec.rb
+++ b/spec/features/schemes_spec.rb
@@ -439,7 +439,6 @@ RSpec.describe "Schemes scheme Features" do
end
context "when changing answers" do
-
it "displays change links" do
assert_selector "a", text: "Change", count: 12
end