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 4b98f25 commit 0a84c70
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 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,11 +14,11 @@
url: users_path,
},
{
title: @user.name,
title: @user.name_was,
url: edit_user_path(@user),
},
{
title: "Change name for #{@user.name}",
title: "Change name for #{@user.name_was}",
}
]
})
Expand Down
11 changes: 11 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,17 @@ 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"
assert_select ".govuk-breadcrumbs li", text: "Change name for user-name"
end

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

Expand Down

0 comments on commit 0a84c70

Please sign in to comment.