Skip to content

fix: analyze and fix users bugs/issues#258

Open
AliK070 wants to merge 1 commit intomainfrom
users-fixes
Open

fix: analyze and fix users bugs/issues#258
AliK070 wants to merge 1 commit intomainfrom
users-fixes

Conversation

@AliK070
Copy link
Contributor

@AliK070 AliK070 commented Mar 24, 2026

TL;DR

  • Persist Name on users so required Name input is actually saved.
  • Allow name in Users controller params and add test coverage to verify Name is saved on create and update.

What is this PR trying to achieve?

  • To fix issues found during UAT

How did you achieve it?

  • Added a migration to add name to users and updated strong params to permit name.
  • Updated controller tests to assert for name persistence.

Checklist

  • Changes have been top-hatted locally
  • Tests have been added or updated
  • Documentation has been updated (if applicable)
  • Linked related issues

Copilot AI review requested due to automatic review settings March 24, 2026 01:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.name column via migration and update schema snapshot.
  • Permit :name in UsersController strong parameters.
  • Extend controller tests to verify name is 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]
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
class AddNameToUsers < ActiveRecord::Migration[8.0]
class AddNameToUsers < ActiveRecord::Migration[8.1]

Copilot uses AI. Check for mistakes.
Comment on lines +2 to +4
def change
add_column :users, :name, :string
end
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
@@ -80,6 +81,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest

created_user = User.find_by(username: "newuser")
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
created_user = User.find_by(username: "newuser")
created_user = User.find_by(username: "newuser")
assert_not_nil created_user

Copilot uses AI. Check for mistakes.
Comment on lines 117 to +118
assert_equal updated_username, @user.reload.username
assert_equal updated_name, @user.reload.name
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants