Skip to content

Commit

Permalink
Use original user name in page title, etc on edit user name page
Browse files Browse the repository at this point in the history
Trello: https://trello.com/c/uwgUF9hF

This fixes a bug that was originally present on the edit user page, but
made its way into the recently added edit user name page. The bug is no
longer a problem on the user edit page, because you can no longer change
the user's name on that page.

The problem is best described by the steps to reproduce it when it was
on the user edit page:

* As an admin of some sort edit a user by clicking on a link from the
  table on the users index page
* See that the page title & heading is something like: "Edit “James
  Mead”"
* Change the name field to be blank
* Click the "Update user" button at the bottom of the page
* See that the page title and heading changes to "Edit “”", i.e. it uses
  the new name value and not the old one.
  • Loading branch information
floehopper committed Nov 8, 2023
1 parent 93fdf82 commit c1a211b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/views/users/names/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% content_for :title_caption, "Manage other users" %>
<% content_for :title, "Change name for #{@user.name}" %>
<% content_for :title, "Change name for #{@user.name_was}" %>

<% content_for :breadcrumbs,
render("govuk_publishing_components/components/breadcrumbs", {
Expand All @@ -14,7 +14,7 @@
url: users_path,
},
{
title: @user.name,
title: @user.name_was,
url: edit_user_path(@user),
},
{
Expand Down
10 changes: 10 additions & 0 deletions test/controllers/users/names_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ class Users::NamesControllerTest < ActionController::TestCase
end
end

should "use original name in page title, heading & breadcrumbs if new name was not valid" do
user = create(:user, name: "user-name")

put :update, params: { user_id: user, user: { name: "" } }

assert_select "head title", text: /^Change name for user-name/
assert_select "h1", text: "Change name for user-name"
assert_select ".govuk-breadcrumbs li", text: "user-name"
end

should "display errors if name is not valid" do
user = create(:user)

Expand Down

0 comments on commit c1a211b

Please sign in to comment.