Browse Source

Change number validation to allow 0 at the beginning

pull/1714/head
Kat 3 years ago
parent
commit
577dda9386
  1. 8
      app/controllers/users_controller.rb
  2. 7
      spec/features/user_spec.rb

8
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

7
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")

Loading…
Cancel
Save