Browse Source

Add email validation

pull/134/head
baarkerlounger 4 years ago committed by Paul Robert Lloyd
parent
commit
5ec5e8fc98
  1. 17
      app/controllers/users_controller.rb
  2. 19
      spec/features/user_spec.rb

17
app/controllers/users_controller.rb

@ -1,5 +1,6 @@
class UsersController < ApplicationController
include Devise::Controllers::SignInOut
include Helpers::Email
before_action :authenticate_user!
def update
@ -14,9 +15,19 @@ class UsersController < ApplicationController
end
def create
@user = User.create!(user_params.merge(org_params).merge(password_params))
@user.send_reset_password_instructions
redirect_to users_organisation_path(current_user.organisation)
@resource = User.new
if user_params["email"].empty?
@resource.errors.add :email, "Enter an email address"
elsif !email_valid?(user_params["email"])
@resource.errors.add :email, "Enter an email address in the correct format, like name@example.com"
end
if @resource.errors.present?
render :new, status: :unprocessable_entity
else
@user = User.create!(user_params.merge(org_params).merge(password_params))
@user.send_reset_password_instructions
redirect_to users_organisation_path(current_user.organisation)
end
end
def edit_password

19
spec/features/user_spec.rb

@ -164,4 +164,23 @@ RSpec.describe "User Features" do
expect(page).to have_content("Test New")
end
end
context "Adding a new user" do
before(:each) do
visit("/case-logs")
fill_in("user[email]", with: user.email)
fill_in("user[password]", with: "pAssword1")
click_button("Sign in")
end
it "validates email" do
visit("users/new")
fill_in("user[name]", with: "New User")
fill_in("user[email]", with: "thisis'tanemail")
click_button("Continue")
expect(page).to have_selector("#error-summary-title")
expect(page).to have_selector("#user-email-field-error")
expect(page).to have_content(/Enter an email address in the correct format, like name@example.com/)
end
end
end

Loading…
Cancel
Save