diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 3c274e1a7..40bbdd146 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -63,7 +63,7 @@ <%= summary_list.row do |row| row.key { "Role" } - row.value { @user.role.humanize } + row.value { @user.role&.humanize } if can_edit_roles?(@user, current_user) row.action( visually_hidden_text: "role", diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index c0c667906..9b951b742 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -164,6 +164,19 @@ RSpec.describe UsersController, type: :request do end end + context "when the user does not have a role because they are a data protection officer only" do + let(:user) { FactoryBot.create(:user, role: nil) } + + before do + sign_in user + get "/users/#{user.id}", headers:, params: {} + end + + it "shows their details" do + expect(response).to have_http_status(:ok) + end + end + context "when the current user does not match the user ID" do before do sign_in user