Browse Source

Add specific field error messages if email or password omitted

pull/119/head
baarkerlounger 4 years ago
parent
commit
1c4c03af17
  1. 16
      app/controllers/users/sessions_controller.rb
  2. 2
      config/routes.rb
  3. 8
      spec/features/user_spec.rb

16
app/controllers/users/sessions_controller.rb

@ -0,0 +1,16 @@
class Users::SessionsController < Devise::SessionsController
def create
self.resource = resource_class.new
if params.dig("user", "email").empty?
resource.errors.add :email, "Please enter email address"
end
if params.dig("user", "password").empty?
resource.errors.add :password, "Please enter password"
end
if resource.errors.present?
render :new, status: :unprocessable_entity
else
super
end
end
end

2
config/routes.rb

@ -1,6 +1,6 @@
Rails.application.routes.draw do
devise_for :admin_users, ActiveAdmin::Devise.config
devise_for :users, controllers: { passwords: "users/passwords" }, skip: [:registrations]
devise_for :users, controllers: { passwords: "users/passwords", sessions: "users/sessions" }, skip: [:registrations]
devise_scope :user do
get "confirmations/reset", to: "users/passwords#reset_confirmation"
get "users/edit" => "devise/registrations#edit", :as => "edit_user_registration"

8
spec/features/user_spec.rb

@ -90,6 +90,14 @@ RSpec.describe "User Features" do
expect(page).to have_selector("#error-summary-title")
expect(page).to have_no_css(".govuk-notification-banner.govuk-notification-banner--success")
end
it "show specific field error messages if a field was omitted" do
visit("/case_logs")
click_button("Sign in")
expect(page).to have_selector("#error-summary-title")
expect(page).to have_selector("#user-email-field-error")
expect(page).to have_selector("#user-password-field-error")
end
end
context "Your Account " do

Loading…
Cancel
Save