Browse Source

Fix repeated use of Password in error summary (and use smart quotes)

pull/573/head
Paul Robert Lloyd 3 years ago
parent
commit
5a7809595c
  1. 11
      app/presenters/error_summary_full_messages_presenter.rb
  2. 2
      app/views/devise/passwords/edit.html.erb
  3. 2
      config/locales/devise.en.yml
  4. 2
      spec/models/organisation_spec.rb
  5. 12
      spec/presenters/error_summary_full_messages_presenter_spec.rb
  6. 4
      spec/requests/auth/passwords_controller_spec.rb
  7. 2
      spec/requests/users_controller_spec.rb

11
app/presenters/error_summary_full_messages_presenter.rb

@ -1,11 +0,0 @@
class ErrorSummaryFullMessagesPresenter
def initialize(error_messages)
@error_messages = error_messages
end
def formatted_error_messages
@error_messages.map do |attribute, messages|
[attribute, [attribute.to_s.humanize, messages.first].join(" ")]
end
end
end

2
app/views/devise/passwords/edit.html.erb

@ -10,7 +10,7 @@
<%= form_for(resource, as: resource_name, html: { method: :patch }) do |f| %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary(presenter: ErrorSummaryFullMessagesPresenter) %>
<%= f.govuk_error_summary %>
<h1 class="govuk-heading-l">
<%= content_for(:title) %>

2
config/locales/devise.en.yml

@ -57,6 +57,8 @@ en:
errors:
messages:
already_confirmed: "has already been confirmed. Sign in."
blank: "can’t be blank"
confirmation: "doesn’t match new password"
confirmation_period_expired: "needs to be confirmed within %{period}. Request a new account."
expired: "has expired. Request a new token."
not_found: "was not found"

2
spec/models/organisation_spec.rb

@ -15,7 +15,7 @@ RSpec.describe Organisation, type: :model do
it "validates provider_type presence" do
expect { FactoryBot.create(:organisation, provider_type: nil) }
.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Provider type can't be blank")
.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Provider type cant be blank")
end
context "with data protection confirmations" do

12
spec/presenters/error_summary_full_messages_presenter_spec.rb

@ -1,12 +0,0 @@
require "rails_helper"
RSpec.describe ErrorSummaryFullMessagesPresenter do
subject(:error_summary_presenter) { described_class.new(error_messages) }
let(:error_messages) { { reset_password_token: %w[expired] } }
let(:formatted_error_messages) { [[:reset_password_token, "Reset password token expired"]] }
it "formats messages to include the attribute name" do
expect(error_summary_presenter.formatted_error_messages).to eq(formatted_error_messages)
end
end

4
spec/requests/auth/passwords_controller_spec.rb

@ -106,7 +106,7 @@ RSpec.describe Auth::PasswordsController, type: :request do
it "shows an error" do
put "/admin/password", headers: headers, params: params
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content("doesn't match Password")
expect(page).to have_content("doesn’t match new password")
end
end
@ -178,7 +178,7 @@ RSpec.describe Auth::PasswordsController, type: :request do
it "shows an error" do
put "/account/password", headers: headers, params: params
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content("doesn't match Password")
expect(page).to have_content("doesn’t match new password")
end
end

2
spec/requests/users_controller_spec.rb

@ -69,7 +69,7 @@ RSpec.describe UsersController, type: :request do
it "shows an error if passwords don't match" do
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_selector("#error-summary-title")
expect(page).to have_content("Password confirmation doesn't match Password")
expect(page).to have_content("Password confirmation doesn’t match new password")
end
end

Loading…
Cancel
Save