5
11
Fork
You've already forked tomato
1

Update enums to prepare for rails 8 #31

Merged
edwardloveall merged 1 commit from el-enum-upgrade into main 2025年10月16日 14:28:14 +02:00

Enums in rails 8 can no longer be defined by a hash. That is, you can't
pass a hash to enum but you can still use a hash to define the values:

class User < ApplicationRecord
 # removed in rails 8
 enum roles: { volunteer: 0, admin: 1 }
 # allowed in rails 8
 enum :roles, { volunteer: 0, admin: 1 }
end

We're not on rails 8, but we'd like to upgrade to 7.2. v7.2 prints a
deprecation warning, so this takes care of that warning.

This fixes our enums to use the new format. I also took the opportunity
to clean up some of the enum logic in the User model. We were (maybe
unintentionally) overriding the generated enum methods like
volunteer?. This allowed us to pass an optional organization argument
to check if a user was a part of an org. I replaced these with better
named methods that require an org.

Enums in rails 8 can no longer be defined by a hash. That is, you can't pass a hash to `enum` but you can still use a hash to define the values: ```rb class User < ApplicationRecord # removed in rails 8 enum roles: { volunteer: 0, admin: 1 } # allowed in rails 8 enum :roles, { volunteer: 0, admin: 1 } end ``` We're not on rails 8, but we'd like to upgrade to 7.2. v7.2 prints a deprecation warning, so this takes care of that warning. This fixes our enums to use the new format. I also took the opportunity to clean up some of the enum logic in the User model. We were (maybe unintentionally) overriding the generated enum methods like `volunteer?`. This allowed us to pass an optional organization argument to check if a user was a part of an org. I replaced these with better named methods that require an org.
Update enums to prepare for rails 8
All checks were successful
Setup Successful
Jest Successful
Static Analysis Successful
RSpec Successful
56a7d2bb70
Enums in rails 8 can no longer be defined by a hash. That is, you can't
pass a hash to `enum` but you can still use a hash to define the values:
```rb
class User < ApplicationRecord
 # removed in rails 8
 enum roles: { volunteer: 0, admin: 1 }
 # allowed in rails 8
 enum :roles, { volunteer: 0, admin: 1 }
end
```
We're not on rails 8, but we'd like to upgrade to 7.2. v7.2 prints a
deprecation warning, so this takes care of that warning.
This fixes our enums to use the new format. I also took the opportunity
to clean up some of the enum logic in the User model. We were (maybe
unintentionally) overriding the generated enum methods like
`volunteer?`. This allowed us to pass an optional organization argument
to check if a user was a part of an org. I replaced these with better
named methods that require an org.
thetizzo left a comment
Copy link

Looks good. Good job taking the opportunity to clean up the User model.

Looks good. Good job taking the opportunity to clean up the User model.
edwardloveall deleted branch el-enum-upgrade 2025年10月16日 14:28:15 +02:00
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rootable/tomato!31
Reference in a new issue
rootable/tomato
No description provided.
Delete branch "el-enum-upgrade"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?