From 9283b8b4221c95665799ebd7b7d53ba10a3f78dc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 5 Oct 2024 17:50:13 +0000 Subject: [PATCH 1/4] Bump rubocop-rails from 2.25.1 to 2.26.2 Bumps [rubocop-rails](https://github.com/rubocop/rubocop-rails) from 2.25.1 to 2.26.2. - [Release notes](https://github.com/rubocop/rubocop-rails/releases) - [Changelog](https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop/rubocop-rails/compare/v2.25.1...v2.26.2) --- updated-dependencies: - dependency-name: rubocop-rails dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Gemfile | 2 +- Gemfile.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 7f363c976..c8f3c3198 100644 --- a/Gemfile +++ b/Gemfile @@ -102,7 +102,7 @@ group :development do gem "rubocop-capybara", "~> 2.21.0", require: false gem "rubocop-factory_bot", "~> 2.26.1", require: false gem "rubocop-performance", "~> 1.22.1", require: false - gem "rubocop-rails", "~> 2.25.1", require: false + gem "rubocop-rails", "~> 2.26.2", require: false gem "rubocop-rspec", "~> 3.1.0", require: false gem "rubocop-rspec_rails", "~> 2.30.0", require: false gem "rvm1-capistrano3", "~> 1.4.0", require: false diff --git a/Gemfile.lock b/Gemfile.lock index cd02cca6f..932b8bb1a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -558,10 +558,10 @@ GEM rubocop-performance (1.22.1) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rails (2.25.1) + rubocop-rails (2.26.2) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 1.33.0, < 2.0) + rubocop (>= 1.52.0, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) rubocop-rspec (3.1.0) rubocop (~> 1.61) @@ -773,7 +773,7 @@ DEPENDENCIES rubocop-capybara (~> 2.21.0) rubocop-factory_bot (~> 2.26.1) rubocop-performance (~> 1.22.1) - rubocop-rails (~> 2.25.1) + rubocop-rails (~> 2.26.2) rubocop-rspec (~> 3.1.0) rubocop-rspec_rails (~> 2.30.0) rvm1-capistrano3 (~> 1.4.0) From 3d4f78a424ae1739ac7b28e479f3f1f57c03d6b1 Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 8 Oct 2024 15:45:14 +0200 Subject: [PATCH 2/4] Add an apply Rails/EnumSyntax rubocop rule This rule was added in rubocop-rails 2.26.0. Applying it allows us to anticipate the deprecation of the current enum syntax using keyword arguments, which is set to be removed in Rails 8.0, as mentioned in the rule's own documentation: https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsenumsyntax --- .rubocop.yml | 3 +++ app/models/dashboard/action.rb | 2 +- app/models/poll/shift.rb | 2 +- app/models/progress_bar.rb | 2 +- app/models/sdg/phase.rb | 2 +- app/models/tenant.rb | 2 +- app/models/votation_type.rb | 2 +- 7 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 47498329c..088cfb508 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -388,6 +388,9 @@ Rails/DynamicFindBy: - find_by_slug_or_id! - find_by_manager_login +Rails/EnumSyntax: + Enabled: true + Rails/EnumUniqueness: Enabled: true diff --git a/app/models/dashboard/action.rb b/app/models/dashboard/action.rb index cfac18315..bd8391ecb 100644 --- a/app/models/dashboard/action.rb +++ b/app/models/dashboard/action.rb @@ -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, :resource] validates :title, presence: true, allow_blank: false, length: { in: 4..80 } diff --git a/app/models/poll/shift.rb b/app/models/poll/shift.rb index 452eb8b45..8bae96426 100644 --- a/app/models/poll/shift.rb +++ b/app/models/poll/shift.rb @@ -8,7 +8,7 @@ class Poll validates :date, presence: true, uniqueness: { scope: [:officer_id, :booth_id, :task] } validates :task, presence: true - enum task: { vote_collection: 0, recount_scrutiny: 1 } + enum :task, { vote_collection: 0, recount_scrutiny: 1 } scope :current, -> { where(date: Date.current) } diff --git a/app/models/progress_bar.rb b/app/models/progress_bar.rb index c966f6c9f..8852b6549 100644 --- a/app/models/progress_bar.rb +++ b/app/models/progress_bar.rb @@ -2,7 +2,7 @@ class ProgressBar < ApplicationRecord self.inheritance_column = nil RANGE = (0..100) - enum kind: %i[primary secondary] + enum :kind, %i[primary secondary] belongs_to :progressable, polymorphic: true diff --git a/app/models/sdg/phase.rb b/app/models/sdg/phase.rb index 3796dcf21..3108c06a8 100644 --- a/app/models/sdg/phase.rb +++ b/app/models/sdg/phase.rb @@ -1,6 +1,6 @@ class SDG::Phase < ApplicationRecord include Cardable - enum kind: %w[sensitization planning monitoring] + enum :kind, %w[sensitization planning monitoring] validates :kind, presence: true, uniqueness: true def self.[](kind) diff --git a/app/models/tenant.rb b/app/models/tenant.rb index e39d3cd9c..f03136b98 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -1,5 +1,5 @@ class Tenant < ApplicationRecord - enum schema_type: %w[subdomain domain] + enum :schema_type, %w[subdomain domain] validates :schema, presence: true, diff --git a/app/models/votation_type.rb b/app/models/votation_type.rb index 00fca0ecf..de1fac364 100644 --- a/app/models/votation_type.rb +++ b/app/models/votation_type.rb @@ -3,7 +3,7 @@ class VotationType < ApplicationRecord QUESTIONABLE_TYPES = %w[Poll::Question].freeze - enum vote_type: %w[unique multiple] + enum :vote_type, %w[unique multiple] validates :questionable, presence: true validates :questionable_type, inclusion: { in: ->(*) { QUESTIONABLE_TYPES }} From c50452aec6b373441793bccf0babbd5452f99daf Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 8 Oct 2024 16:47:04 +0200 Subject: [PATCH 3/4] 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. --- .rubocop.yml | 3 +++ app/models/dashboard/action.rb | 2 +- app/models/progress_bar.rb | 2 +- app/models/sdg/phase.rb | 2 +- app/models/tenant.rb | 2 +- app/models/votation_type.rb | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 088cfb508..50a37133e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -388,6 +388,9 @@ Rails/DynamicFindBy: - find_by_slug_or_id! - find_by_manager_login +Rails/EnumHash: + Enabled: true + Rails/EnumSyntax: Enabled: true diff --git a/app/models/dashboard/action.rb b/app/models/dashboard/action.rb index bd8391ecb..ca625a900 100644 --- a/app/models/dashboard/action.rb +++ b/app/models/dashboard/action.rb @@ -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 } diff --git a/app/models/progress_bar.rb b/app/models/progress_bar.rb index 8852b6549..d79f61b8f 100644 --- a/app/models/progress_bar.rb +++ b/app/models/progress_bar.rb @@ -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 diff --git a/app/models/sdg/phase.rb b/app/models/sdg/phase.rb index 3108c06a8..4a57fb531 100644 --- a/app/models/sdg/phase.rb +++ b/app/models/sdg/phase.rb @@ -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) diff --git a/app/models/tenant.rb b/app/models/tenant.rb index f03136b98..6c1bcac80 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -1,5 +1,5 @@ class Tenant < ApplicationRecord - enum :schema_type, %w[subdomain domain] + enum :schema_type, { subdomain: 0, domain: 1 } validates :schema, presence: true, diff --git a/app/models/votation_type.rb b/app/models/votation_type.rb index de1fac364..71d61c62d 100644 --- a/app/models/votation_type.rb +++ b/app/models/votation_type.rb @@ -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 }} From 29df39b2fa95ff32a86f9a9427fe27fa4b9b5c06 Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 8 Oct 2024 17:12:19 +0200 Subject: [PATCH 4/4] Add an apply Rails/CompactBlank rubocop rule In rubocop-rails 2.26.0, the Rails/CompactBlank rule was modified to handle cases where select(&:present?) is used. After identifying three occurrences in our code, we've decided to apply this rule as it encourages the use of the more efficient and clearer method, compact_blank. By using compact_blank, we improve code clarity and performance, as this method performs the same operation but in a more optimized way. --- .rubocop.yml | 3 +++ app/components/concerns/header.rb | 2 +- app/components/sdg/goals/plain_tag_list_component.rb | 2 +- app/components/sdg/targets/plain_tag_list_component.rb | 2 +- app/components/shared/link_list_component.rb | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 50a37133e..65336f2f3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -367,6 +367,9 @@ Rails/ActiveRecordCallbacksOrder: Rails/AddColumnIndex: Enabled: true +Rails/CompactBlank: + Enabled: true + Rails/CreateTableWithTimestamps: Enabled: true Exclude: diff --git a/app/components/concerns/header.rb b/app/components/concerns/header.rb index 25ca5b3ae..24b8a9216 100644 --- a/app/components/concerns/header.rb +++ b/app/components/concerns/header.rb @@ -7,7 +7,7 @@ module Header (t("#{namespace}.header.title", default: "") unless skip_section_title), strip_tags(title), setting["org_name"] - ].reject(&:blank?).join(" - ") + ].compact_blank.join(" - ") end heading_tag = if %w[admin management moderation sdg_management valuation].include?(namespace) diff --git a/app/components/sdg/goals/plain_tag_list_component.rb b/app/components/sdg/goals/plain_tag_list_component.rb index 5e8b4ff53..3cfa29868 100644 --- a/app/components/sdg/goals/plain_tag_list_component.rb +++ b/app/components/sdg/goals/plain_tag_list_component.rb @@ -4,7 +4,7 @@ class SDG::Goals::PlainTagListComponent < ApplicationComponent private def tags - [*goal_tags, see_more_link].select(&:present?) + [*goal_tags, see_more_link].compact_blank end def goal_tags diff --git a/app/components/sdg/targets/plain_tag_list_component.rb b/app/components/sdg/targets/plain_tag_list_component.rb index 78ccc4b42..46acd8e94 100644 --- a/app/components/sdg/targets/plain_tag_list_component.rb +++ b/app/components/sdg/targets/plain_tag_list_component.rb @@ -4,7 +4,7 @@ class SDG::Targets::PlainTagListComponent < ApplicationComponent private def tags - [*target_tags, see_more_link].select(&:present?) + [*target_tags, see_more_link].compact_blank end def target_tags diff --git a/app/components/shared/link_list_component.rb b/app/components/shared/link_list_component.rb index ccfc97b69..8009b5c4f 100644 --- a/app/components/shared/link_list_component.rb +++ b/app/components/shared/link_list_component.rb @@ -13,7 +13,7 @@ class Shared::LinkListComponent < ApplicationComponent private def present_links - links.select(&:present?) + links.compact_blank end def list_items