Browse Source

validating postcode case logs style

pull/704/head
JG 3 years ago
parent
commit
4afeb461ca
  1. 5
      app/controllers/locations_controller.rb
  2. 12
      app/models/location.rb
  3. 2
      app/views/schemes/check_answers.html.erb
  4. 1
      spec/features/schemes_spec.rb

5
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

12
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

2
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| %>
<strong><%= @scheme.locations.count %></strong> <%= @scheme.locations.count.eql?(1) ? "location" : "locations" %>.
<strong><%= @scheme.locations.count %></strong> <%= @scheme.locations.count.eql?(1) ? "location" : "locations" %>
<% end %>
<%= table.head do |head| %>
<%= head.row do |row| %>

1
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

Loading…
Cancel
Save