Conversation
There was a problem hiding this comment.
Pull request overview
Adds persistence for a name attribute on User records to address UAT issues where the (required) Name input wasn’t being saved.
Changes:
- Add
users.namecolumn via migration and update schema snapshot. - Permit
:nameinUsersControllerstrong parameters. - Extend controller tests to verify
nameis persisted on create and update.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| test/controllers/users_controller_test.rb | Adds assertions that name is saved on create/update. |
| db/schema.rb | Updates schema version and reflects the new users.name column. |
| db/migrate/20260323123000_add_name_to_users.rb | Introduces migration adding the name column to users. |
| app/controllers/users_controller.rb | Permits :name via params.expect for create/update. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,5 @@ | |||
| class AddNameToUsers < ActiveRecord::Migration[8.0] | |||
There was a problem hiding this comment.
This new migration is defined as ActiveRecord::Migration[8.0], but the app is on Rails/ActiveRecord 8.1 (Gemfile + schema.rb). New migrations should generally target the current version ([8.1]) to ensure the migration DSL/defaults match the runtime framework behavior.
| class AddNameToUsers < ActiveRecord::Migration[8.0] | |
| class AddNameToUsers < ActiveRecord::Migration[8.1] |
| def change | ||
| add_column :users, :name, :string | ||
| end |
There was a problem hiding this comment.
name is marked required: true in the Users form, but this migration adds a nullable column with no default/backfill. Consider enforcing the requirement at the data layer (e.g., add a User model presence validation and/or a null: false constraint with a backfill for existing rows) so non-browser clients/console cannot persist users with a blank name.
| def change | |
| add_column :users, :name, :string | |
| end | |
| def up | |
| add_column :users, :name, :string, null: false, default: "" | |
| change_column_default :users, :name, from: "", to: nil | |
| end | |
| def down | |
| remove_column :users, :name | |
| end |
| @@ -80,6 +81,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest | |||
|
|
|||
| created_user = User.find_by(username: "newuser") | |||
There was a problem hiding this comment.
This test will raise a NoMethodError on authenticate if the user wasn't created (making failures harder to diagnose). Add an explicit assert_not_nil created_user (or assert User.exists?(username: ...)) before calling methods on it so the failure message points at the real problem.
| created_user = User.find_by(username: "newuser") | |
| created_user = User.find_by(username: "newuser") | |
| assert_not_nil created_user |
| assert_equal updated_username, @user.reload.username | ||
| assert_equal updated_name, @user.reload.name |
There was a problem hiding this comment.
Minor: @user.reload is called twice in a row here, which causes two DB queries. Reload once into a local variable (or call @user.reload once and assert on both attributes) to keep the test a bit leaner.
| assert_equal updated_username, @user.reload.username | |
| assert_equal updated_name, @user.reload.name | |
| reloaded_user = @user.reload | |
| assert_equal updated_username, reloaded_user.username | |
| assert_equal updated_name, reloaded_user.name |
TL;DR
What is this PR trying to achieve?
How did you achieve it?
Checklist