Browse Source

fix devise error message

pull/1610/head
Phil Lee 3 years ago
parent
commit
99605a71ec
  1. 7
      config/locales/en.yml
  2. 15
      spec/features/auth/sign_in_spec.rb
  3. 2
      spec/features/auth/user_lockout_spec.rb
  4. 6
      spec/models/user_spec.rb

7
config/locales/en.yml

@ -75,6 +75,9 @@ en:
inclusion: You must select one of the following options for how would like to fix errors inclusion: You must select one of the following options for how would like to fix errors
activerecord: activerecord:
attributes:
user:
email: email
errors: errors:
models: models:
scheme: scheme:
@ -123,6 +126,9 @@ en:
role: role:
invalid: "Role must be data accessor, data provider or data coordinator" invalid: "Role must be data accessor, data provider or data coordinator"
blank: "Select role" blank: "Select role"
password:
blank: Enter a password
too_short: Password is too short (minimum is %{count} characters)
merge_request: merge_request:
attributes: attributes:
absorbing_organisation_id: absorbing_organisation_id:
@ -138,7 +144,6 @@ en:
new_organisation_telephone_number: new_organisation_telephone_number:
blank: "Enter a valid telephone number" blank: "Enter a valid telephone number"
validations: validations:
organisation: organisation:
name_missing: "Enter the name of the organisation" name_missing: "Enter the name of the organisation"

15
spec/features/auth/sign_in_spec.rb

@ -0,0 +1,15 @@
require "rails_helper"
RSpec.describe "User sign in" do
let(:user) { FactoryBot.create(:user) }
context "when wrong credentials" do
it "shows correct error message" do
visit("/account/sign-in")
fill_in("user[email]", with: user.email)
fill_in("user[password]", with: "wrong_password")
click_button("Sign in")
expect(page).to have_content("Incorrect email or password")
end
end
end

2
spec/features/auth/user_lockout_spec.rb

@ -21,7 +21,7 @@ RSpec.describe "User Lockout" do
fill_in("user[email]", with: user.email) fill_in("user[email]", with: user.email)
fill_in("user[password]", with: user.password) fill_in("user[password]", with: user.password)
click_button("Sign in") click_button("Sign in")
expect(page).to have_http_status(:unprocessable_entity) expect(page).to have_http_status(:ok)
expect(page).to have_content(I18n.t("devise.failure.locked")) expect(page).to have_content(I18n.t("devise.failure.locked"))
end end
end end

6
spec/models/user_spec.rb

@ -268,7 +268,7 @@ RSpec.describe User, type: :model do
context "when a too short password is entered" do context "when a too short password is entered" do
let(:password) { "123" } let(:password) { "123" }
let(:error_message) { "Validation failed: Password #{I18n.t('errors.messages.too_short', count: 8)}" } let(:error_message) { "Validation failed: Password #{I18n.t('activerecord.errors.models.user.attributes.password.too_short', count: 8)}" }
it "validates password length" do it "validates password length" do
expect { FactoryBot.create(:user, password:) } expect { FactoryBot.create(:user, password:) }
@ -278,7 +278,7 @@ RSpec.describe User, type: :model do
context "when an invalid email is entered" do context "when an invalid email is entered" do
let(:invalid_email) { "not_an_email" } let(:invalid_email) { "not_an_email" }
let(:error_message) { "Validation failed: Email #{I18n.t('activerecord.errors.models.user.attributes.email.invalid')}" } let(:error_message) { "Validation failed: email #{I18n.t('activerecord.errors.models.user.attributes.email.invalid')}" }
it "validates email format" do it "validates email format" do
expect { FactoryBot.create(:user, email: invalid_email) } expect { FactoryBot.create(:user, email: invalid_email) }
@ -288,7 +288,7 @@ RSpec.describe User, type: :model do
context "when the email entered has already been used" do context "when the email entered has already been used" do
let(:user) { FactoryBot.create(:user) } let(:user) { FactoryBot.create(:user) }
let(:error_message) { "Validation failed: Email #{I18n.t('activerecord.errors.models.user.attributes.email.taken')}" } let(:error_message) { "Validation failed: email #{I18n.t('activerecord.errors.models.user.attributes.email.taken')}" }
it "validates email uniqueness" do it "validates email uniqueness" do
expect { FactoryBot.create(:user, email: user.email) } expect { FactoryBot.create(:user, email: user.email) }

Loading…
Cancel
Save