diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 048c3d11..0d2877f0 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -66,6 +66,6 @@ def destroy def has_required_roles? = current_user.has_roles?(:admin) def user_params - params.expect(user: [:username, :password, :password_confirmation, { roles: [] }]) + params.expect(user: [:username, :name, :password, :password_confirmation, { roles: [] }]) end end diff --git a/db/migrate/20260323123000_add_name_to_users.rb b/db/migrate/20260323123000_add_name_to_users.rb new file mode 100644 index 00000000..5cc47a41 --- /dev/null +++ b/db/migrate/20260323123000_add_name_to_users.rb @@ -0,0 +1,5 @@ +class AddNameToUsers < ActiveRecord::Migration[8.0] + def change + add_column :users, :name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 51e0115e..ec410c5d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2026_02_22_231800) do +ActiveRecord::Schema[8.1].define(version: 2026_03_23_123000) do create_table "action_text_rich_texts", force: :cascade do |t| t.text "body" t.datetime "created_at", null: false @@ -133,6 +133,7 @@ end create_table "users", force: :cascade do |t| + t.string "name" t.string "password_digest" t.string "username" t.index ["username"], name: "index_users_on_username", unique: true diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 85bd6f60..29f2efc6 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -69,6 +69,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest test "#create successfully creates a user with valid parameters" do user_params = { username: "newuser", + name: "New User", password: "password", password_confirmation: "password", roles: %w[admin reporter] @@ -80,6 +81,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest created_user = User.find_by(username: "newuser") assert created_user.authenticate("password") + assert_equal "New User", created_user.name assert_equal %w[admin reporter], created_user.user_roles.pluck(:role) end @@ -107,11 +109,13 @@ class UsersControllerTest < ActionDispatch::IntegrationTest test "#update successfully updates a user's username" do updated_username = "Updated user" + updated_name = "Updated Name" - patch user_url(@user), params: { user: { username: updated_username } } + patch user_url(@user), params: { user: { username: updated_username, name: updated_name } } assert_redirected_to users_path assert_equal updated_username, @user.reload.username + assert_equal updated_name, @user.reload.name end test "#update does not update a user with invalid params" do