Add and apply Rails/EnumHash rubocop rule
In rubocop-rails 2.26.0, support was added for Rails 7 syntax in the Rails/EnumHash rule. We took this opportunity to ensure consistency by converting all enums to hash with integer values. This format minimizes the risk of data consistency issues in the database when adding new values.
This commit is contained in:
@@ -388,6 +388,9 @@ Rails/DynamicFindBy:
|
||||
- find_by_slug_or_id!
|
||||
- find_by_manager_login
|
||||
|
||||
Rails/EnumHash:
|
||||
Enabled: true
|
||||
|
||||
Rails/EnumSyntax:
|
||||
Enabled: true
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class Dashboard::Action < ApplicationRecord
|
||||
class_name: "Dashboard::ExecutedAction"
|
||||
has_many :proposals, through: :executed_actions
|
||||
|
||||
enum :action_type, [:proposed_action, :resource]
|
||||
enum :action_type, { proposed_action: 0, resource: 1 }
|
||||
|
||||
validates :title, presence: true, allow_blank: false, length: { in: 4..80 }
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ class ProgressBar < ApplicationRecord
|
||||
self.inheritance_column = nil
|
||||
RANGE = (0..100)
|
||||
|
||||
enum :kind, %i[primary secondary]
|
||||
enum :kind, { primary: 0, secondary: 1 }
|
||||
|
||||
belongs_to :progressable, polymorphic: true
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class SDG::Phase < ApplicationRecord
|
||||
include Cardable
|
||||
enum :kind, %w[sensitization planning monitoring]
|
||||
enum :kind, { sensitization: 0, planning: 1, monitoring: 2 }
|
||||
validates :kind, presence: true, uniqueness: true
|
||||
|
||||
def self.[](kind)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Tenant < ApplicationRecord
|
||||
enum :schema_type, %w[subdomain domain]
|
||||
enum :schema_type, { subdomain: 0, domain: 1 }
|
||||
|
||||
validates :schema,
|
||||
presence: true,
|
||||
|
||||
@@ -3,7 +3,7 @@ class VotationType < ApplicationRecord
|
||||
|
||||
QUESTIONABLE_TYPES = %w[Poll::Question].freeze
|
||||
|
||||
enum :vote_type, %w[unique multiple]
|
||||
enum :vote_type, { unique: 0, multiple: 1 }
|
||||
|
||||
validates :questionable, presence: true
|
||||
validates :questionable_type, inclusion: { in: ->(*) { QUESTIONABLE_TYPES }}
|
||||
|
||||
Reference in New Issue
Block a user