From f89cfa71bef939e648bd5b79226710ca39868263 Mon Sep 17 00:00:00 2001 From: AyakorK Date: Thu, 18 Jan 2024 15:12:47 +0100 Subject: [PATCH] fix: change rubocop rules and fix migrations modified by rubocop --- .rubocop_rails.yml | 5 ++- .rubocop_ruby.yml | 18 +++++------ Gemfile | 2 +- ...el_data_to_sortition.decidim_sortitions.rb | 3 +- ...ign_keys_in_decidim_action_logs.decidim.rb | 2 +- ...idim_comments_comments.decidim_comments.rb | 2 +- ...tability_results.decidim_accountability.rb | 2 +- ...notifications_sending_frequency.decidim.rb | 2 +- ...roposals.decidim_custom_proposal_states.rb | 3 +- db/schema.rb | 31 +++++++++++++++++++ spec/spec_helper.rb | 2 +- 11 files changed, 52 insertions(+), 20 deletions(-) diff --git a/.rubocop_rails.yml b/.rubocop_rails.yml index 0ec984f4..6e191ba6 100644 --- a/.rubocop_rails.yml +++ b/.rubocop_rails.yml @@ -94,10 +94,13 @@ Rails/Validation: Include: - app/models/**/*.rb +Rails/CompactBlank: + Enabled: false + Rails/BulkChangeTable: Exclude: - db/**/* RSpec/MultipleMemoizedHelpers: Exclude: - - spec/**/** + - spec/**/** \ No newline at end of file diff --git a/.rubocop_ruby.yml b/.rubocop_ruby.yml index e00f4fb8..8abd755b 100644 --- a/.rubocop_ruby.yml +++ b/.rubocop_ruby.yml @@ -16,6 +16,7 @@ AllCops: - "vendor/**/*" - "node_modules/**/*" - "db/schema.rb" + - "db/migrate/*.rb" - "bin/*" # Default formatter will be used if no -f/--format option is given. DefaultFormatter: progress @@ -67,12 +68,7 @@ AllCops: # If a value is specified for TargetRubyVersion then it is used. # Else if .ruby-version exists and it contains an MRI version it is used. # Otherwise we fallback to the oldest officially supported Ruby version (2.0). - TargetRubyVersion: 2.7 - - RSpec: - Patterns: - - "(?:^|/)spec/" - - "(?:^|/)test/" + TargetRubyVersion: 3.0 Lint/SafeNavigationChain: Exclude: @@ -287,6 +283,9 @@ Style/HashEachMethods: Style/HashLikeCase: MinBranchesCount: 5 +Style/OpenStructUse: + Enabled: false + # Indentation of `when`. Layout/CaseIndentation: EnforcedStyle: case @@ -1272,10 +1271,11 @@ RSpec/NamedSubject: Enabled: false RSpec/RepeatedExampleGroupDescription: - Enabled: false + Enabled: true RSpec/RepeatedExampleGroupBody: - Enabled: false + Enabled: true + RSpec/VerifiedDoubles: Enabled: false @@ -1764,4 +1764,4 @@ Faker/DeprecatedArguments: - random_words_to_add questions: - number - - supplemental + - supplemental \ No newline at end of file diff --git a/Gemfile b/Gemfile index 8e6bf0e5..01a53a9f 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source "https://rubygems.org" DECIDIM_VERSION = "0.27" -DECIDIM_BRANCH = "release/#{DECIDIM_VERSION}-stable" +DECIDIM_BRANCH = "release/#{DECIDIM_VERSION}-stable".freeze ruby RUBY_VERSION diff --git a/db/migrate/20180611125005_add_cancel_data_to_sortition.decidim_sortitions.rb b/db/migrate/20180611125005_add_cancel_data_to_sortition.decidim_sortitions.rb index 68d029ca..3c1b0dc8 100644 --- a/db/migrate/20180611125005_add_cancel_data_to_sortition.decidim_sortitions.rb +++ b/db/migrate/20180611125005_add_cancel_data_to_sortition.decidim_sortitions.rb @@ -6,7 +6,6 @@ class AddCancelDataToSortition < ActiveRecord::Migration[5.1] def change add_column :decidim_module_sortitions_sortitions, :cancel_reason, :jsonb add_column :decidim_module_sortitions_sortitions, :cancelled_on, :datetime - add_column :decidim_module_sortitions_sortitions, :cancelled_by_user_id, :integer - add_index :decidim_module_sortitions_sortitions, :cancelled_by_user_id + add_column :decidim_module_sortitions_sortitions, :cancelled_by_user_id, :integer, index: true end end diff --git a/db/migrate/20200923121726_index_foreign_keys_in_decidim_action_logs.decidim.rb b/db/migrate/20200923121726_index_foreign_keys_in_decidim_action_logs.decidim.rb index bfe62b23..c8354596 100644 --- a/db/migrate/20200923121726_index_foreign_keys_in_decidim_action_logs.decidim.rb +++ b/db/migrate/20200923121726_index_foreign_keys_in_decidim_action_logs.decidim.rb @@ -6,6 +6,6 @@ class IndexForeignKeysInDecidimActionLogs < ActiveRecord::Migration[5.2] def change add_index :decidim_action_logs, :decidim_area_id add_index :decidim_action_logs, :decidim_scope_id - add_index :decidim_action_logs, :version_id + add_index :decidim_action_logs, :version_id unless index_exists?(:decidim_action_logs, :version_id) end end diff --git a/db/migrate/20200923121747_index_foreign_keys_in_decidim_comments_comments.decidim_comments.rb b/db/migrate/20200923121747_index_foreign_keys_in_decidim_comments_comments.decidim_comments.rb index eab48bb7..fc0ad5d9 100644 --- a/db/migrate/20200923121747_index_foreign_keys_in_decidim_comments_comments.decidim_comments.rb +++ b/db/migrate/20200923121747_index_foreign_keys_in_decidim_comments_comments.decidim_comments.rb @@ -4,6 +4,6 @@ class IndexForeignKeysInDecidimCommentsComments < ActiveRecord::Migration[5.2] def change - add_index :decidim_comments_comments, :decidim_user_group_id + add_index :decidim_comments_comments, :decidim_user_group_id unless index_exists?(:decidim_comments_comments, :decidim_user_group_id) end end diff --git a/db/migrate/20200923121758_index_foreign_keys_in_decidim_accountability_results.decidim_accountability.rb b/db/migrate/20200923121758_index_foreign_keys_in_decidim_accountability_results.decidim_accountability.rb index 6bfbc0d2..42dec3ba 100644 --- a/db/migrate/20200923121758_index_foreign_keys_in_decidim_accountability_results.decidim_accountability.rb +++ b/db/migrate/20200923121758_index_foreign_keys_in_decidim_accountability_results.decidim_accountability.rb @@ -4,6 +4,6 @@ class IndexForeignKeysInDecidimAccountabilityResults < ActiveRecord::Migration[5.2] def change - add_index :decidim_accountability_results, :external_id + add_index :decidim_accountability_results, :external_id unless index_exists?(:decidim_accountability_results, :external_id) end end diff --git a/db/migrate/20240115111961_add_index_to_decidim_users_notifications_sending_frequency.decidim.rb b/db/migrate/20240115111961_add_index_to_decidim_users_notifications_sending_frequency.decidim.rb index 7417dc65..2d7f0b09 100644 --- a/db/migrate/20240115111961_add_index_to_decidim_users_notifications_sending_frequency.decidim.rb +++ b/db/migrate/20240115111961_add_index_to_decidim_users_notifications_sending_frequency.decidim.rb @@ -4,6 +4,6 @@ class AddIndexToDecidimUsersNotificationsSendingFrequency < ActiveRecord::Migration[6.0] def change - add_index :decidim_users, :notifications_sending_frequency + add_index :decidim_users, :notifications_sending_frequency unless index_exists?(:decidim_users, :notifications_sending_frequency) end end diff --git a/db/migrate/20240115111973_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb b/db/migrate/20240115111973_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb index ab5c6f41..13bcc335 100644 --- a/db/migrate/20240115111973_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb +++ b/db/migrate/20240115111973_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb @@ -4,8 +4,7 @@ class AddStateIdToDecidimProposalsProposals < ActiveRecord::Migration[6.0] def up - add_column :decidim_proposals_proposals, :decidim_proposals_proposal_state_id, :integer - add_index :decidim_proposals_proposals, :decidim_proposals_proposal_state_id + add_column :decidim_proposals_proposals, :decidim_proposals_proposal_state_id, :integer, index: true add_foreign_key :decidim_proposals_proposals, :decidim_proposals_proposal_states, column: :decidim_proposals_proposal_state_id end diff --git a/db/schema.rb b/db/schema.rb index d8d2db2d..71c9f705 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -62,6 +62,7 @@ t.float "weight", default: 1.0 t.string "external_id" t.integer "comments_count", default: 0, null: false + t.index ["comments_count"], name: "index_decidim_accountability_results_on_comments_count" t.index ["decidim_accountability_status_id"], name: "decidim_accountability_results_on_status_id" t.index ["decidim_component_id"], name: "index_decidim_accountability_results_on_decidim_component_id" t.index ["decidim_scope_id"], name: "index_decidim_accountability_results_on_decidim_scope_id" @@ -207,6 +208,7 @@ t.index ["decidim_organization_id", "slug"], name: "index_unique_assembly_slug_and_organization", unique: true t.index ["decidim_organization_id"], name: "index_decidim_assemblies_on_decidim_organization_id" t.index ["decidim_scope_id"], name: "index_decidim_assemblies_on_decidim_scope_id" + t.index ["follows_count"], name: "index_decidim_assemblies_on_follows_count" t.index ["parent_id"], name: "decidim_assemblies_assemblies_on_parent_id" end @@ -275,6 +277,7 @@ t.integer "weight", default: 0, null: false t.integer "attachment_collection_id" t.index ["attached_to_id", "attached_to_type"], name: "index_decidim_attachments_on_attached_to" + t.index ["attachment_collection_id"], name: "index_decidim_attachments_attachment_collection_id" t.index ["attachment_collection_id"], name: "index_decidim_attachments_on_attachment_collection_id" end @@ -352,9 +355,12 @@ t.integer "endorsements_count", default: 0, null: false t.integer "comments_count", default: 0, null: false t.integer "follows_count", default: 0, null: false + t.index ["comments_count"], name: "index_decidim_blogs_posts_on_comments_count" t.index ["decidim_author_id", "decidim_author_type"], name: "index_decidim_blogs_posts_on_decidim_author" + t.index ["decidim_author_id"], name: "index_decidim_blogs_posts_on_decidim_author_id" t.index ["decidim_component_id"], name: "index_decidim_blogs_posts_on_decidim_component_id" t.index ["decidim_user_group_id"], name: "index_decidim_blogs_posts_on_decidim_user_group_id" + t.index ["follows_count"], name: "index_decidim_blogs_posts_on_follows_count" end create_table "decidim_budgets_budgets", id: :serial, force: :cascade do |t| @@ -403,8 +409,11 @@ t.date "selected_at" t.integer "comments_count", default: 0, null: false t.integer "follows_count", default: 0, null: false + t.index ["comments_count"], name: "index_decidim_budgets_projects_on_comments_count" t.index ["decidim_budgets_budget_id"], name: "index_decidim_budgets_projects_on_decidim_budgets_budget_id" t.index ["decidim_scope_id"], name: "index_decidim_budgets_projects_on_decidim_scope_id" + t.index ["follows_count"], name: "index_decidim_budgets_projects_on_follows_count" + t.index ["selected_at"], name: "index_decidim_budgets_projects_on_selected_at" end create_table "decidim_calendar_external_events", force: :cascade do |t| @@ -483,6 +492,7 @@ t.string "decidim_participatory_space_type" t.integer "decidim_participatory_space_id" t.datetime "deleted_at" + t.index ["comments_count"], name: "index_decidim_comments_comments_on_comments_count" t.index ["created_at"], name: "index_decidim_comments_comments_on_created_at" t.index ["decidim_author_id", "decidim_author_type"], name: "index_decidim_comments_comments_on_decidim_author" t.index ["decidim_author_id"], name: "decidim_comments_comment_author" @@ -575,11 +585,13 @@ t.integer "follows_count", default: 0, null: false t.boolean "comments_enabled", default: true t.index ["closed_at"], name: "index_decidim_debates_debates_on_closed_at" + t.index ["comments_count"], name: "index_decidim_debates_debates_on_comments_count" t.index ["decidim_author_id", "decidim_author_type"], name: "index_decidim_debates_debates_on_decidim_author" t.index ["decidim_component_id"], name: "index_decidim_debates_debates_on_decidim_component_id" t.index ["decidim_scope_id"], name: "index_decidim_debates_debates_on_decidim_scope_id" t.index ["decidim_user_group_id"], name: "index_decidim_debates_debates_on_decidim_user_group_id" t.index ["endorsements_count"], name: "idx_decidim_debates_debates_on_endorsemnts_count" + t.index ["follows_count"], name: "index_decidim_debates_debates_on_follows_count" end create_table "decidim_editor_images", force: :cascade do |t| @@ -851,10 +863,14 @@ t.string "state" t.integer "iframe_access_level", default: 0 t.integer "iframe_embed_type", default: 0 + t.index ["closed_at"], name: "index_decidim_meetings_meetings_on_closed_at" t.index ["decidim_author_id", "decidim_author_type"], name: "index_decidim_meetings_meetings_on_author" t.index ["decidim_author_id"], name: "index_decidim_meetings_meetings_on_decidim_author_id" t.index ["decidim_component_id"], name: "index_decidim_meetings_meetings_on_decidim_component_id" t.index ["decidim_scope_id"], name: "index_decidim_meetings_meetings_on_decidim_scope_id" + t.index ["follows_count"], name: "index_decidim_meetings_meetings_on_follows_count" + t.index ["published_at"], name: "index_decidim_meetings_meetings_on_published_at" + t.index ["state"], name: "index_decidim_meetings_meetings_on_state" end create_table "decidim_meetings_polls", force: :cascade do |t| @@ -883,6 +899,7 @@ t.integer "status", default: 0 t.index ["decidim_questionnaire_id"], name: "index_decidim_meetings_questions_on_decidim_questionnaire_id" t.index ["position"], name: "index_decidim_meetings_questions_on_position" + t.index ["status"], name: "index_decidim_meetings_questions_on_status" end create_table "decidim_meetings_registrations", force: :cascade do |t| @@ -894,6 +911,7 @@ t.datetime "validated_at" t.bigint "decidim_user_group_id" t.boolean "public_participation", default: false + t.index ["code"], name: "index_decidim_meetings_registrations_on_code" t.index ["decidim_meeting_id"], name: "index_decidim_meetings_registrations_on_decidim_meeting_id" t.index ["decidim_user_group_id"], name: "index_decidim_meetings_registrations_on_decidim_user_group_id" t.index ["decidim_user_id", "decidim_meeting_id"], name: "decidim_meetings_registrations_user_meeting_unique", unique: true @@ -1086,6 +1104,7 @@ t.boolean "enable_participatory_space_filters", default: true t.index ["host"], name: "index_decidim_organizations_on_host", unique: true t.index ["name"], name: "index_decidim_organizations_on_name", unique: true + t.index ["secondary_hosts"], name: "index_decidim_organizations_on_secondary_hosts" end create_table "decidim_pages_pages", id: :serial, force: :cascade do |t| @@ -1113,6 +1132,7 @@ t.jsonb "participatory_structure" t.boolean "promoted", default: false t.index ["decidim_organization_id"], name: "decidim_participatory_process_group_organization" + t.index ["promoted"], name: "index_decidim_participatory_process_groups_on_promoted" end create_table "decidim_participatory_process_steps", id: :serial, force: :cascade do |t| @@ -1197,6 +1217,9 @@ t.index ["decidim_participatory_process_type_id"], name: "index_decidim_processes_on_decidim_process_type_id" t.index ["decidim_scope_id"], name: "idx_process_on_scope_id" t.index ["decidim_scope_type_id"], name: "index_decidim_participatory_processes_on_decidim_scope_type_id" + t.index ["follows_count"], name: "index_decidim_participatory_processes_on_follows_count" + t.index ["promoted"], name: "index_decidim_participatory_processes_on_promoted" + t.index ["published_at"], name: "index_decidim_participatory_processes_on_published_at" end create_table "decidim_participatory_space_links", id: :serial, force: :cascade do |t| @@ -1250,8 +1273,10 @@ t.integer "comments_count", default: 0, null: false t.integer "follows_count", default: 0, null: false t.index ["body"], name: "decidim_proposals_collaborative_draft_body_search" + t.index ["comments_count"], name: "index_decidim_proposals_collaborative_drafts_on_comments_count" t.index ["decidim_component_id"], name: "decidim_proposals_collaborative_drafts_on_decidim_component_id" t.index ["decidim_scope_id"], name: "decidim_proposals_collaborative_drafts_on_decidim_scope_id" + t.index ["follows_count"], name: "index_decidim_proposals_collaborative_drafts_on_follows_count" t.index ["state"], name: "decidim_proposals_collaborative_drafts_on_state" t.index ["title"], name: "decidim_proposals_collaborative_drafts_title_search" t.index ["updated_at"], name: "decidim_proposals_collaborative_drafts_on_updated_at" @@ -1338,10 +1363,14 @@ t.integer "decidim_proposals_proposal_state_id" t.index "md5((body)::text)", name: "decidim_proposals_proposal_body_search" t.index "md5((title)::text)", name: "decidim_proposals_proposal_title_search" + t.index ["answered_at"], name: "index_decidim_proposals_proposals_on_answered_at" + t.index ["comments_count"], name: "index_decidim_proposals_proposals_on_comments_count" t.index ["created_at"], name: "index_decidim_proposals_proposals_on_created_at" t.index ["decidim_component_id"], name: "index_decidim_proposals_proposals_on_decidim_component_id" t.index ["decidim_scope_id"], name: "index_decidim_proposals_proposals_on_decidim_scope_id" + t.index ["follows_count"], name: "index_decidim_proposals_proposals_on_follows_count" t.index ["proposal_votes_count"], name: "index_decidim_proposals_proposals_on_proposal_votes_count" + t.index ["published_at"], name: "index_decidim_proposals_proposals_on_published_at" t.index ["state"], name: "index_decidim_proposals_proposals_on_state" end @@ -1515,6 +1544,7 @@ t.string "decidim_author_type", null: false t.integer "comments_count", default: 0, null: false t.index ["cancelled_by_user_id"], name: "index_decidim_sortitions_sortitions_on_cancelled_by_user_id" + t.index ["comments_count"], name: "index_decidim_sortitions_sortitions_on_comments_count" t.index ["decidim_author_id", "decidim_author_type"], name: "index_decidim_sortitions_sortitions_on_decidim_author" t.index ["decidim_author_id"], name: "index_decidim_sortitions_sortitions_on_decidim_author_id" t.index ["decidim_component_id"], name: "index_sortitions__on_feature" @@ -1706,6 +1736,7 @@ t.index ["confirmation_token"], name: "index_decidim_users_on_confirmation_token", unique: true t.index ["decidim_organization_id"], name: "index_decidim_users_on_decidim_organization_id" t.index ["email", "decidim_organization_id"], name: "index_decidim_users_on_email_and_decidim_organization_id", unique: true, where: "((deleted_at IS NULL) AND (managed = false) AND ((type)::text = 'Decidim::User'::text))" + t.index ["follows_count"], name: "index_decidim_users_on_follows_count" t.index ["id", "type"], name: "index_decidim_users_on_id_and_type" t.index ["invitation_token"], name: "index_decidim_users_on_invitation_token", unique: true t.index ["invitations_count"], name: "index_decidim_users_on_invitations_count" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 039607a3..dbedb2cf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,7 +4,7 @@ Decidim::Dev.dummy_app_path = File.expand_path(Rails.root.to_s) require "decidim/dev/test/base_spec_helper" -Dir.glob("./spec/support/**/*.rb").sort.each { |f| require f } +Dir.glob("./spec/support/**/*.rb").each { |f| require f } RSpec.configure do |config| config.formatter = ENV.fetch("RSPEC_FORMAT", "progress").to_sym