From 913ad2ad003e7f40144089280559d15ca656ae7f Mon Sep 17 00:00:00 2001 From: J G <7750475+moarpheus@users.noreply.github.com> Date: Thu, 21 Jul 2022 11:59:39 +0100 Subject: [PATCH] fixed (#766) --- app/controllers/locations_controller.rb | 2 +- spec/requests/locations_controller_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 483c183fe..6ac482fef 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -62,7 +62,7 @@ private end def is_integer?(string) - string.to_i.to_s == string + string.sub(/^0+/, "").to_i.to_s == string.sub(/^0+/, "") end def find_scheme diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 381727455..3e099e32d 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -123,6 +123,26 @@ RSpec.describe LocationsController, type: :request do end end + context "when startdate is submitted with leading zeroes" do + let(:params) do + { location: { + name: "Test", + units: "5", + type_of_unit: "Bungalow", + add_another_location: "No", + postcode: "zz1 1zz", + mobility_type: "N", + "startdate(3i)" => "01", + "startdate(2i)" => "01", + "startdate(1i)" => "2022", + } } + end + + it "creates a new location for scheme with postcode " do + expect(Location.last.startdate).to eq(Time.utc(2022, 1, 1)) + end + end + context "when trying to add location to a scheme that belongs to another organisation" do let(:another_scheme) { FactoryBot.create(:scheme) } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "ZZ1 1ZZ", mobility_type: "N" } } }