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:
taitus
2024-10-08 16:47:04 +02:00
parent 3d4f78a424
commit c50452aec6
6 changed files with 8 additions and 5 deletions

View File

@@ -388,6 +388,9 @@ Rails/DynamicFindBy:
- find_by_slug_or_id! - find_by_slug_or_id!
- find_by_manager_login - find_by_manager_login
Rails/EnumHash:
Enabled: true
Rails/EnumSyntax: Rails/EnumSyntax:
Enabled: true Enabled: true

View File

@@ -9,7 +9,7 @@ class Dashboard::Action < ApplicationRecord
class_name: "Dashboard::ExecutedAction" class_name: "Dashboard::ExecutedAction"
has_many :proposals, through: :executed_actions 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 } validates :title, presence: true, allow_blank: false, length: { in: 4..80 }

View File

@@ -2,7 +2,7 @@ class ProgressBar < ApplicationRecord
self.inheritance_column = nil self.inheritance_column = nil
RANGE = (0..100) RANGE = (0..100)
enum :kind, %i[primary secondary] enum :kind, { primary: 0, secondary: 1 }
belongs_to :progressable, polymorphic: true belongs_to :progressable, polymorphic: true

View File

@@ -1,6 +1,6 @@
class SDG::Phase < ApplicationRecord class SDG::Phase < ApplicationRecord
include Cardable include Cardable
enum :kind, %w[sensitization planning monitoring] enum :kind, { sensitization: 0, planning: 1, monitoring: 2 }
validates :kind, presence: true, uniqueness: true validates :kind, presence: true, uniqueness: true
def self.[](kind) def self.[](kind)

View File

@@ -1,5 +1,5 @@
class Tenant < ApplicationRecord class Tenant < ApplicationRecord
enum :schema_type, %w[subdomain domain] enum :schema_type, { subdomain: 0, domain: 1 }
validates :schema, validates :schema,
presence: true, presence: true,

View File

@@ -3,7 +3,7 @@ class VotationType < ApplicationRecord
QUESTIONABLE_TYPES = %w[Poll::Question].freeze 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, presence: true
validates :questionable_type, inclusion: { in: ->(*) { QUESTIONABLE_TYPES }} validates :questionable_type, inclusion: { in: ->(*) { QUESTIONABLE_TYPES }}