Browse Source

Make phone required for new users

pull/1714/head
Kat 3 years ago
parent
commit
2e8032751c
  1. 4
      app/controllers/users_controller.rb
  2. 1
      config/locales/en.yml
  3. 5
      spec/requests/users_controller_spec.rb

4
app/controllers/users_controller.rb

@ -121,7 +121,9 @@ private
@resource.errors.add :role, I18n.t("validations.role.invalid")
end
if user_params[:phone].present? && !valid_phone_number?(user_params[:phone])
if user_params[:phone].blank?
@resource.errors.add :phone, :blank
elsif !valid_phone_number?(user_params[:phone])
@resource.errors.add :phone
end
end

1
config/locales/en.yml

@ -156,6 +156,7 @@ en:
taken: "Enter an email address that hasn’t already been used to sign up"
phone:
invalid: "Enter a telephone number in the correct format"
blank: "Enter a telephone number"
role:
invalid: "Role must be data accessor, data provider or data coordinator"
blank: "Select role"

5
spec/requests/users_controller_spec.rb

@ -850,6 +850,7 @@ RSpec.describe UsersController, type: :request do
name: "new user ",
email: "new_user@example.com",
role: "data_coordinator",
phone: "12345678910",
},
}
end
@ -1312,6 +1313,7 @@ RSpec.describe UsersController, type: :request do
expect(page).to have_field("user[name]")
expect(page).to have_field("user[email]")
expect(page).to have_field("user[role]")
expect(page).to have_field("user[phone]")
end
it "allows setting the role to `support`" do
@ -1610,6 +1612,7 @@ RSpec.describe UsersController, type: :request do
name: "new user",
email:,
role: "data_coordinator",
phone: "12345612456",
organisation_id: organisation.id,
},
}
@ -1641,6 +1644,7 @@ RSpec.describe UsersController, type: :request do
name: "",
email: "",
role: "",
phone: "",
organisation_id: nil,
},
}
@ -1656,6 +1660,7 @@ RSpec.describe UsersController, type: :request do
expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.name.blank"))
expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.email.blank"))
expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.organisation_id.blank"))
expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.blank"))
end
end

Loading…
Cancel
Save