Skip to content

Commit

Permalink
Merge pull request #2910 from alphagov/1191-fix-current-role
Browse files Browse the repository at this point in the history
Fix current role on edit role pages
  • Loading branch information
yndajas authored May 29, 2024
2 parents bbe04d0 + 1c739df commit 57dc842
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/views/account/roles/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
id: "user_role",
name: "user[role]",
label: "Role",
options: current_user.manageable_roles.map { |role| { text: role.display_name, value: role.name, selected: current_user.role == role.name } }
options: current_user.manageable_roles.map { |role| { text: role.display_name, value: role.name, selected: current_user.role_name == role.name } }
} %>
<%= render "govuk_publishing_components/components/button", {
text: "Change role"
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/roles/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
name: "user[role]",
label: "Role",
hint: user_role_select_hint,
options: current_user.manageable_roles.map { |role| { text: role.display_name, value: role.name, selected: @user.role == role.name } },
options: current_user.manageable_roles.map { |role| { text: role.display_name, value: role.name, selected: @user.role_name == role.name } },
error_message: @user.errors[:role].any? ? @user.errors.full_messages_for(:role).to_sentence : nil
} %>
<div class="govuk-button-group">
Expand Down
1 change: 1 addition & 0 deletions test/integration/account_roles_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class AccountRolesTest < ActionDispatch::IntegrationTest

visit edit_account_role_path

assert has_select? "Role", selected: "Superadmin"
select "Normal", from: "Role"
click_button "Change role"

Expand Down
3 changes: 2 additions & 1 deletion test/integration/change_user_role_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ def sign_in_as_and_edit_user(sign_in_as, user_to_edit)

context "when logged in as a super admin" do
should "be able to change the role of a user who is not exempt from 2SV" do
user = create(:user)
user = create(:two_step_enabled_organisation_admin)
sign_in_as_and_edit_user(@super_admin, user)
click_link "Change Role"

assert has_select? "Role", selected: "Organisation admin"
select "Admin", from: "Role"
click_button "Change role"

Expand Down

0 comments on commit 57dc842

Please sign in to comment.