diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1c1799be..2a31d5a3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -81,7 +81,7 @@ def user_params params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation) else if current_user.try(:admin?) - params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :admin) + params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :role) else params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation) end diff --git a/test/integration/users_test.rb b/test/integration/users_test.rb index d2879720..dc362a9a 100644 --- a/test/integration/users_test.rb +++ b/test/integration/users_test.rb @@ -18,4 +18,15 @@ class UsersTest < ActionDispatch::IntegrationTest assert_redirected_to login_path end + + test "admin can change a user's role" do + admin = FactoryBot.create(:user, :admin) + regular_user = FactoryBot.create(:user) + + sign_in_as admin + + patch user_path(regular_user), params: { user: { role: "admin" } } + + assert regular_user.reload.admin? + end end