Browse Source

Move tests to request

pull/1714/head
Kat 3 years ago
parent
commit
5c6ef05a06
  1. 31
      spec/features/user_spec.rb
  2. 39
      spec/requests/users_controller_spec.rb

31
spec/features/user_spec.rb

@ -322,37 +322,6 @@ RSpec.describe "User Features" do
expect(page).to have_title("Error") expect(page).to have_title("Error")
end end
it "validates telephone number is numeric" do
visit("users/new")
fill_in("user[name]", with: "New User")
fill_in("user[email]", with: "newuser@example.com")
fill_in("user[phone]", with: "randomstring")
click_button("Continue")
expect(page).to have_selector("#error-summary-title")
expect(page).to have_selector("#user-phone-field-error")
expect(page).to have_content(/Enter a telephone number in the correct format/)
expect(page).to have_title("Error")
end
it "validates telephone number is longer than 11 digits" do
visit("users/new")
fill_in("user[name]", with: "New User")
fill_in("user[email]", with: "newuser@example.com")
fill_in("user[phone]", with: "123")
click_button("Continue")
expect(page).to have_selector("#error-summary-title")
expect(page).to have_selector("#user-phone-field-error")
expect(page).to have_content(/Enter a telephone number in the correct format/)
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 it "sets name, email, role, is_dpo and is_key_contact fields" do
visit("users/new") visit("users/new")
fill_in("user[name]", with: "New User") fill_in("user[name]", with: "New User")

39
spec/requests/users_controller_spec.rb

@ -938,6 +938,45 @@ RSpec.describe UsersController, type: :request do
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.email.blank"))
end end
end end
context "when validating telephone numbers" do
let(:params) do
{
"user": {
phone:,
},
}
end
context "when telephone number is not numeric" do
let(:phone) { "randomstring" }
it "validates telephone number" do
request
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.invalid"))
end
end
context "when telephone number is shorter than 11 digits" do
let(:phone) { "123" }
it "validates telephone number" do
request
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.invalid"))
end
end
context "when telephone number is in correct format" do
let(:phone) { "012345678919" }
it "validates telephone number" do
request
expect(page).not_to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.invalid"))
end
end
end
end end
describe "#new" do describe "#new" do

Loading…
Cancel
Save