Browse Source

testing postcode missing

pull/704/head
JG 3 years ago
parent
commit
ae9c392e35
  1. 2
      app/controllers/locations_controller.rb
  2. 2
      app/models/location.rb
  3. 10
      spec/requests/locations_controller_spec.rb

2
app/controllers/locations_controller.rb

@ -44,7 +44,7 @@ private
def location_params def location_params
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 = 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[:postcode] = required_params[:postcode].gsub(" ", "").encode("ASCII", "UTF-8", invalid: :replace, undef: :replace, replace: "") if required_params[:postcode]
required_params required_params
end end
end end

2
app/models/location.rb

@ -36,7 +36,7 @@ class Location < ApplicationRecord
private private
def validate_postcode def validate_postcode
unless postcode.match(Validations::PropertyValidations::POSTCODE_REGEXP) if postcode.nil? || !postcode&.match(Validations::PropertyValidations::POSTCODE_REGEXP)
error_message = I18n.t("validations.postcode") error_message = I18n.t("validations.postcode")
errors.add :postcode, error_message errors.add :postcode, error_message
end end

10
spec/requests/locations_controller_spec.rb

@ -103,6 +103,16 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
context "when required organisation id param is missing" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No" } } }
it "displays the new page with an error message" do
post "/schemes/#{scheme.id}/location/create", params: params
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("validations.postcode"))
end
end
context "when do you want to add another location is selected as yes" do context "when do you want to add another location is selected as yes" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ" } } } let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ" } } }

Loading…
Cancel
Save