-
Notifications
You must be signed in to change notification settings - Fork 0
fix: analyze and fix users bugs/issues #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,5 @@ | ||||||||||||||||||||||||
| class AddNameToUsers < ActiveRecord::Migration[8.0] | ||||||||||||||||||||||||
| def change | ||||||||||||||||||||||||
| add_column :users, :name, :string | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
|
Comment on lines
+2
to
+4
|
||||||||||||||||||||||||
| 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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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") | ||||||||||||
|
||||||||||||
| created_user = User.find_by(username: "newuser") | |
| created_user = User.find_by(username: "newuser") | |
| assert_not_nil created_user |
Copilot
AI
Mar 24, 2026
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.