- <% flash.each do |type, msg| %> + <% if flash.notice %> <%= govuk_notification_banner( title_text: 'Success', success: true, title_heading_level: 3, title_id: "swanky-notifications") do |notification_banner| - notification_banner.heading(text: msg) + notification_banner.heading(text: flash.notice) end %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index f30e8868c..3ca1e142d 100644 --- a/config/routes.rb +++ b/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" diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index e41551845..5954fd6b8 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -7,12 +7,18 @@ RSpec.describe "User Features" do expect(page).to have_current_path("/users/sign_in") end + it "does not see the default devise error message" do + visit("/case_logs") + expect(page).to have_no_content("You need to sign in or sign up before continuing.") + end + it " is redirected to case logs after signing in" do visit("/case_logs") fill_in("user[email]", with: user.email) fill_in("user[password]", with: "pAssword1") click_button("Sign in") expect(page).to have_current_path("/case_logs") + expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") end end @@ -80,6 +86,34 @@ RSpec.describe "User Features" do end end + context "Trying to log in with incorrect credentials" do + it "shows a gov uk error summary and no flash message" do + visit("/case_logs") + fill_in("user[email]", with: user.email) + fill_in("user[password]", with: "nonsense") + click_button("Sign in") + 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 + + it "show specific field error messages if an invalid email address is entered" do + visit("/case_logs") + fill_in("user[email]", with: "thisisn'tanemail") + 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_content(/Enter an email address in the correct format, like name@example.com/) + end + end + context "Your Account " do before(:each) do visit("/case_logs")