From 577dda9386e3339958742da3d30a674924a868d7 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 21 Jun 2023 08:49:45 +0100 Subject: [PATCH] Change number validation to allow 0 at the beginning --- app/controllers/users_controller.rb | 8 +++++++- spec/features/user_spec.rb | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3f91fa659..11a6c22da 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -127,7 +127,13 @@ private end def valid_phone_number?(number) - number.to_i.to_s == number && number.length >= 11 + numeric?(number) && number.length >= 11 + end + + def numeric?(str) + !Float(str).nil? + rescue StandardError + false end def format_error_messages diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index 222d2ff04..f5703640c 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -346,6 +346,13 @@ RSpec.describe "User Features" do expect(page).to have_title("Error") end + it "allows telephone number in correct format" do + visit("users/new") + fill_in("user[phone]", with: "02345678910") + click_button("Continue") + expect(page).not_to have_content(/Enter a telephone number in the correct format/) + end + it "sets name, email, role, is_dpo and is_key_contact fields" do visit("users/new") fill_in("user[name]", with: "New User")