From b751078fcd21d13f6e4b63d7a86dd2be893d2753 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 1 Dec 2023 05:38:15 -0500 Subject: [PATCH 01/14] Eliminate double subject call in admin/ controller specs (#28158) --- .../account_moderation_notes_controller_spec.rb | 6 +++--- .../admin/custom_emojis_controller_spec.rb | 16 ++++++++-------- .../admin/report_notes_controller_spec.rb | 10 +++++----- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spec/controllers/admin/account_moderation_notes_controller_spec.rb b/spec/controllers/admin/account_moderation_notes_controller_spec.rb index 3e1b4b280..8d24a7af3 100644 --- a/spec/controllers/admin/account_moderation_notes_controller_spec.rb +++ b/spec/controllers/admin/account_moderation_notes_controller_spec.rb @@ -20,7 +20,7 @@ RSpec.describe Admin::AccountModerationNotesController do it 'successfully creates a note' do expect { subject }.to change(AccountModerationNote, :count).by(1) - expect(subject).to redirect_to admin_account_path(target_account.id) + expect(response).to redirect_to admin_account_path(target_account.id) end end @@ -29,7 +29,7 @@ RSpec.describe Admin::AccountModerationNotesController do it 'falls to create a note' do expect { subject }.to_not change(AccountModerationNote, :count) - expect(subject).to render_template 'admin/accounts/show' + expect(response).to render_template 'admin/accounts/show' end end end @@ -42,7 +42,7 @@ RSpec.describe Admin::AccountModerationNotesController do it 'destroys note' do expect { subject }.to change(AccountModerationNote, :count).by(-1) - expect(subject).to redirect_to admin_account_path(target_account.id) + expect(response).to redirect_to admin_account_path(target_account.id) end end end diff --git a/spec/controllers/admin/custom_emojis_controller_spec.rb b/spec/controllers/admin/custom_emojis_controller_spec.rb index 6c32a3a57..9e732200d 100644 --- a/spec/controllers/admin/custom_emojis_controller_spec.rb +++ b/spec/controllers/admin/custom_emojis_controller_spec.rb @@ -12,24 +12,24 @@ describe Admin::CustomEmojisController do end describe 'GET #index' do - subject { get :index } - before do Fabricate(:custom_emoji) end it 'renders index page' do - expect(subject).to have_http_status 200 - expect(subject).to render_template :index + get :index + + expect(response).to have_http_status 200 + expect(response).to render_template :index end end describe 'GET #new' do - subject { get :new } - it 'renders new page' do - expect(subject).to have_http_status 200 - expect(subject).to render_template :new + get :new + + expect(response).to have_http_status 200 + expect(response).to render_template :new end end diff --git a/spec/controllers/admin/report_notes_controller_spec.rb b/spec/controllers/admin/report_notes_controller_spec.rb index b5ba4a84d..4ddf4a4e2 100644 --- a/spec/controllers/admin/report_notes_controller_spec.rb +++ b/spec/controllers/admin/report_notes_controller_spec.rb @@ -27,7 +27,7 @@ describe Admin::ReportNotesController do it 'creates a report note and resolves report' do expect { subject }.to change(ReportNote, :count).by(1) expect(report.reload).to be_action_taken - expect(subject).to redirect_to admin_reports_path + expect(response).to redirect_to admin_reports_path end end @@ -37,7 +37,7 @@ describe Admin::ReportNotesController do it 'creates a report note and does not resolve report' do expect { subject }.to change(ReportNote, :count).by(1) expect(report.reload).to_not be_action_taken - expect(subject).to redirect_to admin_report_path(report) + expect(response).to redirect_to admin_report_path(report) end end end @@ -52,7 +52,7 @@ describe Admin::ReportNotesController do it 'creates a report note and unresolves report' do expect { subject }.to change(ReportNote, :count).by(1) expect(report.reload).to_not be_action_taken - expect(subject).to redirect_to admin_report_path(report) + expect(response).to redirect_to admin_report_path(report) end end @@ -62,7 +62,7 @@ describe Admin::ReportNotesController do it 'creates a report note and does not unresolve report' do expect { subject }.to change(ReportNote, :count).by(1) expect(report.reload).to be_action_taken - expect(subject).to redirect_to admin_report_path(report) + expect(response).to redirect_to admin_report_path(report) end end end @@ -86,7 +86,7 @@ describe Admin::ReportNotesController do it 'deletes note' do expect { subject }.to change(ReportNote, :count).by(-1) - expect(subject).to redirect_to admin_report_path(report_note.report) + expect(response).to redirect_to admin_report_path(report_note.report) end end end From 440b80b2e795c21a22de4514160679e68561d98b Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 1 Dec 2023 06:00:41 -0500 Subject: [PATCH 02/14] Model concerns organization into module namespaces (#28149) --- .rubocop_todo.yml | 18 ++++++------- app/models/account.rb | 25 ++++++++++--------- .../associations.rb} | 2 +- .../{account_avatar.rb => account/avatar.rb} | 2 +- .../counters.rb} | 2 +- .../finder_concern.rb} | 2 +- .../{account_header.rb => account/header.rb} | 2 +- .../interactions.rb} | 2 +- .../merging.rb} | 2 +- .../{account_search.rb => account/search.rb} | 2 +- .../statuses_search.rb} | 2 +- .../safe_reblog_insert.rb} | 2 +- .../search_concern.rb} | 2 +- .../snapshot_concern.rb} | 2 +- .../threading_concern.rb} | 2 +- .../has_settings.rb} | 2 +- .../concerns/{ => user}/ldap_authenticable.rb | 2 +- .../concerns/{ => user}/omniauthable.rb | 2 +- .../concerns/{ => user}/pam_authenticable.rb | 2 +- app/models/status.rb | 10 ++++---- app/models/user.rb | 11 ++++---- app/views/settings/profiles/show.html.haml | 4 +-- lib/mastodon/cli/maintenance.rb | 4 +-- spec/models/account_spec.rb | 4 +-- .../counters_spec.rb} | 2 +- .../finder_concern_spec.rb} | 2 +- .../interactions_spec.rb} | 2 +- .../statuses_search_spec.rb} | 2 +- .../threading_concern_spec.rb} | 2 +- .../search_spec.rb} | 2 +- .../statuses_search_spec.rb} | 2 +- 31 files changed, 62 insertions(+), 62 deletions(-) rename app/models/concerns/{account_associations.rb => account/associations.rb} (99%) rename app/models/concerns/{account_avatar.rb => account/avatar.rb} (98%) rename app/models/concerns/{account_counters.rb => account/counters.rb} (99%) rename app/models/concerns/{account_finder_concern.rb => account/finder_concern.rb} (98%) rename app/models/concerns/{account_header.rb => account/header.rb} (98%) rename app/models/concerns/{account_interactions.rb => account/interactions.rb} (99%) rename app/models/concerns/{account_merging.rb => account/merging.rb} (98%) rename app/models/concerns/{account_search.rb => account/search.rb} (99%) rename app/models/concerns/{account_statuses_search.rb => account/statuses_search.rb} (97%) rename app/models/concerns/{status_safe_reblog_insert.rb => status/safe_reblog_insert.rb} (98%) rename app/models/concerns/{status_search_concern.rb => status/search_concern.rb} (97%) rename app/models/concerns/{status_snapshot_concern.rb => status/snapshot_concern.rb} (96%) rename app/models/concerns/{status_threading_concern.rb => status/threading_concern.rb} (98%) rename app/models/concerns/{has_user_settings.rb => user/has_settings.rb} (99%) rename app/models/concerns/{ => user}/ldap_authenticable.rb (98%) rename app/models/concerns/{ => user}/omniauthable.rb (99%) rename app/models/concerns/{ => user}/pam_authenticable.rb (98%) rename spec/models/concerns/{account_counters_spec.rb => account/counters_spec.rb} (98%) rename spec/models/concerns/{account_finder_concern_spec.rb => account/finder_concern_spec.rb} (98%) rename spec/models/concerns/{account_interactions_spec.rb => account/interactions_spec.rb} (99%) rename spec/models/concerns/{account_statuses_search_spec.rb => account/statuses_search_spec.rb} (98%) rename spec/models/concerns/{status_threading_concern_spec.rb => status/threading_concern_spec.rb} (99%) rename spec/search/models/concerns/{account_search_spec.rb => account/search_spec.rb} (98%) rename spec/search/models/concerns/{account_statuses_search_spec.rb => account/statuses_search_spec.rb} (98%) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index dbd5beac2..9fb163ceb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -107,7 +107,7 @@ Rails/ApplicationController: # Include: app/models/**/*.rb Rails/HasAndBelongsToMany: Exclude: - - 'app/models/concerns/account_associations.rb' + - 'app/models/concerns/account/associations.rb' - 'app/models/preview_card.rb' - 'app/models/status.rb' - 'app/models/tag.rb' @@ -116,7 +116,7 @@ Rails/HasAndBelongsToMany: # Include: app/models/**/*.rb Rails/HasManyOrHasOneDependent: Exclude: - - 'app/models/concerns/account_counters.rb' + - 'app/models/concerns/account/counters.rb' - 'app/models/conversation.rb' - 'app/models/custom_emoji.rb' - 'app/models/custom_emoji_category.rb' @@ -172,7 +172,7 @@ Rails/SkipsModelValidations: Exclude: - 'app/controllers/admin/invites_controller.rb' - 'app/controllers/concerns/session_tracking_concern.rb' - - 'app/models/concerns/account_merging.rb' + - 'app/models/concerns/account/merging.rb' - 'app/models/concerns/expireable.rb' - 'app/models/status.rb' - 'app/models/trends/links.rb' @@ -252,7 +252,7 @@ Rails/WhereExists: - 'app/lib/feed_manager.rb' - 'app/lib/status_cache_hydrator.rb' - 'app/lib/suspicious_sign_in_detector.rb' - - 'app/models/concerns/account_interactions.rb' + - 'app/models/concerns/account/interactions.rb' - 'app/models/featured_tag.rb' - 'app/models/poll.rb' - 'app/models/session_activation.rb' @@ -342,8 +342,8 @@ Style/GuardClause: - 'app/lib/request_pool.rb' - 'app/lib/webfinger.rb' - 'app/lib/webfinger_resource.rb' - - 'app/models/concerns/account_counters.rb' - - 'app/models/concerns/ldap_authenticable.rb' + - 'app/models/concerns/account/counters.rb' + - 'app/models/concerns/user/ldap_authenticable.rb' - 'app/models/tag.rb' - 'app/models/user.rb' - 'app/services/fan_out_on_write_service.rb' @@ -372,8 +372,8 @@ Style/HashAsLastArrayItem: Exclude: - 'app/controllers/admin/statuses_controller.rb' - 'app/controllers/api/v1/statuses_controller.rb' - - 'app/models/concerns/account_counters.rb' - - 'app/models/concerns/status_threading_concern.rb' + - 'app/models/concerns/account/counters.rb' + - 'app/models/concerns/status/threading_concern.rb' - 'app/models/status.rb' - 'app/services/batched_remove_status_service.rb' - 'app/services/notify_service.rb' @@ -486,7 +486,7 @@ Style/RedundantReturn: # AllowedMethods: present?, blank?, presence, try, try! Style/SafeNavigation: Exclude: - - 'app/models/concerns/account_finder_concern.rb' + - 'app/models/concerns/account/finder_concern.rb' # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. diff --git a/app/models/account.rb b/app/models/account.rb index 03edcb2a2..4119944e5 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -70,19 +70,20 @@ class Account < ApplicationRecord URL_PREFIX_RE = %r{\Ahttp(s?)://[^/]+} USERNAME_ONLY_RE = /\A#{USERNAME_RE}\z/i - include Attachmentable - include AccountAssociations - include AccountAvatar - include AccountFinderConcern - include AccountHeader - include AccountInteractions - include Paginable - include AccountCounters - include DomainNormalizable + include Attachmentable # Load prior to Avatar & Header concerns + + include Account::Associations + include Account::Avatar + include Account::Counters + include Account::FinderConcern + include Account::Header + include Account::Interactions + include Account::Merging + include Account::Search + include Account::StatusesSearch include DomainMaterializable - include AccountMerging - include AccountSearch - include AccountStatusesSearch + include DomainNormalizable + include Paginable enum protocol: { ostatus: 0, activitypub: 1 } enum suspension_origin: { local: 0, remote: 1 }, _prefix: true diff --git a/app/models/concerns/account_associations.rb b/app/models/concerns/account/associations.rb similarity index 99% rename from app/models/concerns/account_associations.rb rename to app/models/concerns/account/associations.rb index 592812e96..31902ae21 100644 --- a/app/models/concerns/account_associations.rb +++ b/app/models/concerns/account/associations.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module AccountAssociations +module Account::Associations extend ActiveSupport::Concern included do diff --git a/app/models/concerns/account_avatar.rb b/app/models/concerns/account/avatar.rb similarity index 98% rename from app/models/concerns/account_avatar.rb rename to app/models/concerns/account/avatar.rb index b5919a9a2..39f599db1 100644 --- a/app/models/concerns/account_avatar.rb +++ b/app/models/concerns/account/avatar.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module AccountAvatar +module Account::Avatar extend ActiveSupport::Concern IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].freeze diff --git a/app/models/concerns/account_counters.rb b/app/models/concerns/account/counters.rb similarity index 99% rename from app/models/concerns/account_counters.rb rename to app/models/concerns/account/counters.rb index 3fabb5205..fb69be9b7 100644 --- a/app/models/concerns/account_counters.rb +++ b/app/models/concerns/account/counters.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module AccountCounters +module Account::Counters extend ActiveSupport::Concern ALLOWED_COUNTER_KEYS = %i(statuses_count following_count followers_count).freeze diff --git a/app/models/concerns/account_finder_concern.rb b/app/models/concerns/account/finder_concern.rb similarity index 98% rename from app/models/concerns/account_finder_concern.rb rename to app/models/concerns/account/finder_concern.rb index 37c3b8895..7faaddeb4 100644 --- a/app/models/concerns/account_finder_concern.rb +++ b/app/models/concerns/account/finder_concern.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module AccountFinderConcern +module Account::FinderConcern extend ActiveSupport::Concern class_methods do diff --git a/app/models/concerns/account_header.rb b/app/models/concerns/account/header.rb similarity index 98% rename from app/models/concerns/account_header.rb rename to app/models/concerns/account/header.rb index e184880f9..44ae774e9 100644 --- a/app/models/concerns/account_header.rb +++ b/app/models/concerns/account/header.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module AccountHeader +module Account::Header extend ActiveSupport::Concern IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].freeze diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account/interactions.rb similarity index 99% rename from app/models/concerns/account_interactions.rb rename to app/models/concerns/account/interactions.rb index 3c64ebd9f..0ea26e628 100644 --- a/app/models/concerns/account_interactions.rb +++ b/app/models/concerns/account/interactions.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module AccountInteractions +module Account::Interactions extend ActiveSupport::Concern class_methods do diff --git a/app/models/concerns/account_merging.rb b/app/models/concerns/account/merging.rb similarity index 98% rename from app/models/concerns/account_merging.rb rename to app/models/concerns/account/merging.rb index 14e157a3d..960ee1819 100644 --- a/app/models/concerns/account_merging.rb +++ b/app/models/concerns/account/merging.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module AccountMerging +module Account::Merging extend ActiveSupport::Concern def merge_with!(other_account) diff --git a/app/models/concerns/account_search.rb b/app/models/concerns/account/search.rb similarity index 99% rename from app/models/concerns/account_search.rb rename to app/models/concerns/account/search.rb index b855727b4..b02b9bd46 100644 --- a/app/models/concerns/account_search.rb +++ b/app/models/concerns/account/search.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module AccountSearch +module Account::Search extend ActiveSupport::Concern DISALLOWED_TSQUERY_CHARACTERS = /['?\\:‘’]/ diff --git a/app/models/concerns/account_statuses_search.rb b/app/models/concerns/account/statuses_search.rb similarity index 97% rename from app/models/concerns/account_statuses_search.rb rename to app/models/concerns/account/statuses_search.rb index 4b2bc4117..334b71450 100644 --- a/app/models/concerns/account_statuses_search.rb +++ b/app/models/concerns/account/statuses_search.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module AccountStatusesSearch +module Account::StatusesSearch extend ActiveSupport::Concern included do diff --git a/app/models/concerns/status_safe_reblog_insert.rb b/app/models/concerns/status/safe_reblog_insert.rb similarity index 98% rename from app/models/concerns/status_safe_reblog_insert.rb rename to app/models/concerns/status/safe_reblog_insert.rb index 0007b46d4..60ddb78e5 100644 --- a/app/models/concerns/status_safe_reblog_insert.rb +++ b/app/models/concerns/status/safe_reblog_insert.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module StatusSafeReblogInsert +module Status::SafeReblogInsert extend ActiveSupport::Concern class_methods do diff --git a/app/models/concerns/status_search_concern.rb b/app/models/concerns/status/search_concern.rb similarity index 97% rename from app/models/concerns/status_search_concern.rb rename to app/models/concerns/status/search_concern.rb index 7252fde73..c16db8bd8 100644 --- a/app/models/concerns/status_search_concern.rb +++ b/app/models/concerns/status/search_concern.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module StatusSearchConcern +module Status::SearchConcern extend ActiveSupport::Concern included do diff --git a/app/models/concerns/status_snapshot_concern.rb b/app/models/concerns/status/snapshot_concern.rb similarity index 96% rename from app/models/concerns/status_snapshot_concern.rb rename to app/models/concerns/status/snapshot_concern.rb index 9741b9aeb..ba624d943 100644 --- a/app/models/concerns/status_snapshot_concern.rb +++ b/app/models/concerns/status/snapshot_concern.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module StatusSnapshotConcern +module Status::SnapshotConcern extend ActiveSupport::Concern included do diff --git a/app/models/concerns/status_threading_concern.rb b/app/models/concerns/status/threading_concern.rb similarity index 98% rename from app/models/concerns/status_threading_concern.rb rename to app/models/concerns/status/threading_concern.rb index 2ca3b66c2..2606fd2f2 100644 --- a/app/models/concerns/status_threading_concern.rb +++ b/app/models/concerns/status/threading_concern.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module StatusThreadingConcern +module Status::ThreadingConcern extend ActiveSupport::Concern def ancestors(limit, account = nil) diff --git a/app/models/concerns/has_user_settings.rb b/app/models/concerns/user/has_settings.rb similarity index 99% rename from app/models/concerns/has_user_settings.rb rename to app/models/concerns/user/has_settings.rb index b7c7104a1..bfa8aa2ca 100644 --- a/app/models/concerns/has_user_settings.rb +++ b/app/models/concerns/user/has_settings.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module HasUserSettings +module User::HasSettings extend ActiveSupport::Concern included do diff --git a/app/models/concerns/ldap_authenticable.rb b/app/models/concerns/user/ldap_authenticable.rb similarity index 98% rename from app/models/concerns/ldap_authenticable.rb rename to app/models/concerns/user/ldap_authenticable.rb index 775df0817..d84ff084b 100644 --- a/app/models/concerns/ldap_authenticable.rb +++ b/app/models/concerns/user/ldap_authenticable.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module LdapAuthenticable +module User::LdapAuthenticable extend ActiveSupport::Concern class_methods do diff --git a/app/models/concerns/omniauthable.rb b/app/models/concerns/user/omniauthable.rb similarity index 99% rename from app/models/concerns/omniauthable.rb rename to app/models/concerns/user/omniauthable.rb index 3983fbcda..6d1d1b8cc 100644 --- a/app/models/concerns/omniauthable.rb +++ b/app/models/concerns/user/omniauthable.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Omniauthable +module User::Omniauthable extend ActiveSupport::Concern TEMP_EMAIL_PREFIX = 'change@me' diff --git a/app/models/concerns/pam_authenticable.rb b/app/models/concerns/user/pam_authenticable.rb similarity index 98% rename from app/models/concerns/pam_authenticable.rb rename to app/models/concerns/user/pam_authenticable.rb index f97f986a4..a682058cc 100644 --- a/app/models/concerns/pam_authenticable.rb +++ b/app/models/concerns/user/pam_authenticable.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module PamAuthenticable +module User::PamAuthenticable extend ActiveSupport::Concern included do diff --git a/app/models/status.rb b/app/models/status.rb index 41c895029..7b1ca69c7 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -30,14 +30,14 @@ # class Status < ApplicationRecord + include Cacheable include Discard::Model include Paginable - include Cacheable - include StatusThreadingConcern - include StatusSnapshotConcern include RateLimitable - include StatusSafeReblogInsert - include StatusSearchConcern + include Status::SafeReblogInsert + include Status::SearchConcern + include Status::SnapshotConcern + include Status::ThreadingConcern rate_limit by: :account, family: :statuses diff --git a/app/models/user.rb b/app/models/user.rb index b0eba97c3..550f8bfd3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -53,9 +53,12 @@ class User < ApplicationRecord filtered_languages ) - include Redisable include LanguagesHelper - include HasUserSettings + include Redisable + include User::HasSettings + include User::LdapAuthenticable + include User::Omniauthable + include User::PamAuthenticable # The home and list feeds will be stored in Redis for this amount # of time, and status fan-out to followers will include only people @@ -75,10 +78,6 @@ class User < ApplicationRecord devise :registerable, :recoverable, :validatable, :confirmable - include Omniauthable - include PamAuthenticable - include LdapAuthenticable - belongs_to :account, inverse_of: :user belongs_to :invite, counter_cache: :uses, optional: true belongs_to :created_by_application, class_name: 'Doorkeeper::Application', optional: true diff --git a/app/views/settings/profiles/show.html.haml b/app/views/settings/profiles/show.html.haml index 7c13dc7f4..5f9613c93 100644 --- a/app/views/settings/profiles/show.html.haml +++ b/app/views/settings/profiles/show.html.haml @@ -33,7 +33,7 @@ .fields-row .fields-row__column.fields-row__column-6 .fields-group - = f.input :avatar, wrapper: :with_block_label, input_html: { accept: AccountAvatar::IMAGE_MIME_TYPES.join(',') }, hint: t('simple_form.hints.defaults.avatar', dimensions: '400x400', size: number_to_human_size(AccountAvatar::LIMIT)) + = f.input :avatar, wrapper: :with_block_label, input_html: { accept: Account::Avatar::IMAGE_MIME_TYPES.join(',') }, hint: t('simple_form.hints.defaults.avatar', dimensions: '400x400', size: number_to_human_size(Account::Avatar::LIMIT)) .fields-row__column.fields-row__column-6 .fields-group @@ -46,7 +46,7 @@ .fields-row .fields-row__column.fields-row__column-6 .fields-group - = f.input :header, wrapper: :with_block_label, input_html: { accept: AccountHeader::IMAGE_MIME_TYPES.join(',') }, hint: t('simple_form.hints.defaults.header', dimensions: '1500x500', size: number_to_human_size(AccountHeader::LIMIT)) + = f.input :header, wrapper: :with_block_label, input_html: { accept: Account::Header::IMAGE_MIME_TYPES.join(',') }, hint: t('simple_form.hints.defaults.header', dimensions: '1500x500', size: number_to_human_size(Account::Header::LIMIT)) .fields-row__column.fields-row__column-6 .fields-group diff --git a/lib/mastodon/cli/maintenance.rb b/lib/mastodon/cli/maintenance.rb index a95b7a30c..c53d74254 100644 --- a/lib/mastodon/cli/maintenance.rb +++ b/lib/mastodon/cli/maintenance.rb @@ -67,8 +67,8 @@ module Mastodon::CLI local? ? username : "#{username}@#{domain}" end - # This is a duplicate of the AccountMerging concern because we need it to - # be independent from code version. + # This is a duplicate of the Account::Merging concern because we need it + # to be independent from code version. def merge_with!(other_account) # Since it's the same remote resource, the remote resource likely # already believes we are following/blocking, so it's safe to diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 9652ea191..522549125 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -451,7 +451,7 @@ RSpec.describe Account do end it 'limits via constant by default' do - stub_const('AccountSearch::DEFAULT_LIMIT', 1) + stub_const('Account::Search::DEFAULT_LIMIT', 1) 2.times.each { Fabricate(:account, display_name: 'Display Name') } results = described_class.search_for('display') expect(results.size).to eq 1 @@ -595,7 +595,7 @@ RSpec.describe Account do end it 'limits by 10 by default' do - stub_const('AccountSearch::DEFAULT_LIMIT', 1) + stub_const('Account::Search::DEFAULT_LIMIT', 1) 2.times { Fabricate(:account, display_name: 'Display Name') } results = described_class.advanced_search_for('display', account) expect(results.size).to eq 1 diff --git a/spec/models/concerns/account_counters_spec.rb b/spec/models/concerns/account/counters_spec.rb similarity index 98% rename from spec/models/concerns/account_counters_spec.rb rename to spec/models/concerns/account/counters_spec.rb index fb02d79f1..2e1cd700b 100644 --- a/spec/models/concerns/account_counters_spec.rb +++ b/spec/models/concerns/account/counters_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe AccountCounters do +describe Account::Counters do let!(:account) { Fabricate(:account) } describe '#increment_count!' do diff --git a/spec/models/concerns/account_finder_concern_spec.rb b/spec/models/concerns/account/finder_concern_spec.rb similarity index 98% rename from spec/models/concerns/account_finder_concern_spec.rb rename to spec/models/concerns/account/finder_concern_spec.rb index 3a94c4d54..ab5149e98 100644 --- a/spec/models/concerns/account_finder_concern_spec.rb +++ b/spec/models/concerns/account/finder_concern_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe AccountFinderConcern do +describe Account::FinderConcern do describe 'local finders' do let!(:account) { Fabricate(:account, username: 'Alice') } diff --git a/spec/models/concerns/account_interactions_spec.rb b/spec/models/concerns/account/interactions_spec.rb similarity index 99% rename from spec/models/concerns/account_interactions_spec.rb rename to spec/models/concerns/account/interactions_spec.rb index 6687c8443..6fac41e07 100644 --- a/spec/models/concerns/account_interactions_spec.rb +++ b/spec/models/concerns/account/interactions_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe AccountInteractions do +describe Account::Interactions do let(:account) { Fabricate(:account, username: 'account') } let(:account_id) { account.id } let(:account_ids) { [account_id] } diff --git a/spec/models/concerns/account_statuses_search_spec.rb b/spec/models/concerns/account/statuses_search_spec.rb similarity index 98% rename from spec/models/concerns/account_statuses_search_spec.rb rename to spec/models/concerns/account/statuses_search_spec.rb index 46362936f..ab249d62d 100644 --- a/spec/models/concerns/account_statuses_search_spec.rb +++ b/spec/models/concerns/account/statuses_search_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe AccountStatusesSearch do +describe Account::StatusesSearch do let(:account) { Fabricate(:account, indexable: indexable) } before do diff --git a/spec/models/concerns/status_threading_concern_spec.rb b/spec/models/concerns/status/threading_concern_spec.rb similarity index 99% rename from spec/models/concerns/status_threading_concern_spec.rb rename to spec/models/concerns/status/threading_concern_spec.rb index 2eac1ca6e..09fb21856 100644 --- a/spec/models/concerns/status_threading_concern_spec.rb +++ b/spec/models/concerns/status/threading_concern_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe StatusThreadingConcern do +describe Status::ThreadingConcern do describe '#ancestors' do let!(:alice) { Fabricate(:account, username: 'alice') } let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') } diff --git a/spec/search/models/concerns/account_search_spec.rb b/spec/search/models/concerns/account/search_spec.rb similarity index 98% rename from spec/search/models/concerns/account_search_spec.rb rename to spec/search/models/concerns/account/search_spec.rb index 65e1e4de1..d8d7f355d 100644 --- a/spec/search/models/concerns/account_search_spec.rb +++ b/spec/search/models/concerns/account/search_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe AccountSearch do +describe Account::Search do describe 'a non-discoverable account becoming discoverable' do let(:account) { Account.find_by(username: 'search_test_account_1') } diff --git a/spec/search/models/concerns/account_statuses_search_spec.rb b/spec/search/models/concerns/account/statuses_search_spec.rb similarity index 98% rename from spec/search/models/concerns/account_statuses_search_spec.rb rename to spec/search/models/concerns/account/statuses_search_spec.rb index d35cfa563..bf2606eec 100644 --- a/spec/search/models/concerns/account_statuses_search_spec.rb +++ b/spec/search/models/concerns/account/statuses_search_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe AccountStatusesSearch do +describe Account::StatusesSearch do describe 'a non-indexable account becoming indexable' do let(:account) { Account.find_by(username: 'search_test_account_1') } From 272592d16d40e804ec325ef3b5e6de9bbad5f2dd Mon Sep 17 00:00:00 2001 From: Michael Stanclift Date: Fri, 1 Dec 2023 05:06:37 -0600 Subject: [PATCH 03/14] Change startup command for Puma in Docker Compose (#28138) --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index bcfa4c85f..93451d961 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -59,7 +59,7 @@ services: image: ghcr.io/mastodon/mastodon:v4.2.0 restart: always env_file: .env.production - command: bash -c "rm -f /mastodon/tmp/pids/server.pid; bundle exec rails s -p 3000" + command: bundle exec puma -C config/puma.rb networks: - external_network - internal_network From 92fa9b109f78647710c52d86fa777ab3972e2f1b Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 1 Dec 2023 06:56:47 -0500 Subject: [PATCH 04/14] Add spec coverage for media CLI usage command (#28167) --- spec/lib/mastodon/cli/media_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/lib/mastodon/cli/media_spec.rb b/spec/lib/mastodon/cli/media_spec.rb index 9543640e9..305d67d28 100644 --- a/spec/lib/mastodon/cli/media_spec.rb +++ b/spec/lib/mastodon/cli/media_spec.rb @@ -78,4 +78,16 @@ describe Mastodon::CLI::Media do end end end + + describe '#usage' do + context 'without options' do + let(:options) { {} } + + it 'reports about storage size' do + expect { cli.invoke(:usage, [], options) }.to output( + a_string_including('0 Bytes') + ).to_stdout + end + end + end end From 7753e5f715ba105a8ec3dd335e8af4a9448aee63 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 1 Dec 2023 07:00:34 -0500 Subject: [PATCH 05/14] Add shared example for CLI command specs (#28165) --- spec/lib/mastodon/cli/accounts_spec.rb | 8 ++------ spec/lib/mastodon/cli/cache_spec.rb | 6 +----- spec/lib/mastodon/cli/canonical_email_blocks_spec.rb | 6 +----- spec/lib/mastodon/cli/domains_spec.rb | 6 +----- spec/lib/mastodon/cli/email_domain_blocks_spec.rb | 6 +----- spec/lib/mastodon/cli/emoji_spec.rb | 6 +----- spec/lib/mastodon/cli/feeds_spec.rb | 6 +----- spec/lib/mastodon/cli/ip_blocks_spec.rb | 6 +----- spec/lib/mastodon/cli/main_spec.rb | 6 +----- spec/lib/mastodon/cli/maintenance_spec.rb | 6 +----- spec/lib/mastodon/cli/media_spec.rb | 6 +----- spec/lib/mastodon/cli/preview_cards_spec.rb | 6 +----- spec/lib/mastodon/cli/search_spec.rb | 6 +----- spec/lib/mastodon/cli/settings_spec.rb | 6 +----- spec/lib/mastodon/cli/statuses_spec.rb | 6 +----- spec/lib/mastodon/cli/upgrade_spec.rb | 6 +----- spec/support/examples/cli.rb | 11 +++++++++++ 17 files changed, 28 insertions(+), 81 deletions(-) create mode 100644 spec/support/examples/cli.rb diff --git a/spec/lib/mastodon/cli/accounts_spec.rb b/spec/lib/mastodon/cli/accounts_spec.rb index 626cf4778..3216d0d1b 100644 --- a/spec/lib/mastodon/cli/accounts_spec.rb +++ b/spec/lib/mastodon/cli/accounts_spec.rb @@ -6,6 +6,8 @@ require 'mastodon/cli/accounts' describe Mastodon::CLI::Accounts do let(:cli) { described_class.new } + it_behaves_like 'CLI Command' + # `parallelize_with_progress` cannot run in transactions, so instead, # stub it with an alternative implementation that runs sequentially # and can run in transactions. @@ -24,12 +26,6 @@ describe Mastodon::CLI::Accounts do end end - describe '.exit_on_failure?' do - it 'returns true' do - expect(described_class.exit_on_failure?).to be true - end - end - describe '#create' do shared_examples 'a new user with given email address and username' do it 'creates a new user with the specified email address' do diff --git a/spec/lib/mastodon/cli/cache_spec.rb b/spec/lib/mastodon/cli/cache_spec.rb index 3ab42dc8c..c1ce04710 100644 --- a/spec/lib/mastodon/cli/cache_spec.rb +++ b/spec/lib/mastodon/cli/cache_spec.rb @@ -6,11 +6,7 @@ require 'mastodon/cli/cache' describe Mastodon::CLI::Cache do let(:cli) { described_class.new } - describe '.exit_on_failure?' do - it 'returns true' do - expect(described_class.exit_on_failure?).to be true - end - end + it_behaves_like 'CLI Command' describe '#clear' do before { allow(Rails.cache).to receive(:clear) } diff --git a/spec/lib/mastodon/cli/canonical_email_blocks_spec.rb b/spec/lib/mastodon/cli/canonical_email_blocks_spec.rb index eb57a3cd1..6e4675748 100644 --- a/spec/lib/mastodon/cli/canonical_email_blocks_spec.rb +++ b/spec/lib/mastodon/cli/canonical_email_blocks_spec.rb @@ -6,11 +6,7 @@ require 'mastodon/cli/canonical_email_blocks' describe Mastodon::CLI::CanonicalEmailBlocks do let(:cli) { described_class.new } - describe '.exit_on_failure?' do - it 'returns true' do - expect(described_class.exit_on_failure?).to be true - end - end + it_behaves_like 'CLI Command' describe '#find' do let(:arguments) { ['user@example.com'] } diff --git a/spec/lib/mastodon/cli/domains_spec.rb b/spec/lib/mastodon/cli/domains_spec.rb index ea58845c0..765b63e2a 100644 --- a/spec/lib/mastodon/cli/domains_spec.rb +++ b/spec/lib/mastodon/cli/domains_spec.rb @@ -4,9 +4,5 @@ require 'rails_helper' require 'mastodon/cli/domains' describe Mastodon::CLI::Domains do - describe '.exit_on_failure?' do - it 'returns true' do - expect(described_class.exit_on_failure?).to be true - end - end + it_behaves_like 'CLI Command' end diff --git a/spec/lib/mastodon/cli/email_domain_blocks_spec.rb b/spec/lib/mastodon/cli/email_domain_blocks_spec.rb index 333ae3f2b..060943b18 100644 --- a/spec/lib/mastodon/cli/email_domain_blocks_spec.rb +++ b/spec/lib/mastodon/cli/email_domain_blocks_spec.rb @@ -4,9 +4,5 @@ require 'rails_helper' require 'mastodon/cli/email_domain_blocks' describe Mastodon::CLI::EmailDomainBlocks do - describe '.exit_on_failure?' do - it 'returns true' do - expect(described_class.exit_on_failure?).to be true - end - end + it_behaves_like 'CLI Command' end diff --git a/spec/lib/mastodon/cli/emoji_spec.rb b/spec/lib/mastodon/cli/emoji_spec.rb index 9b5865372..5d109eb52 100644 --- a/spec/lib/mastodon/cli/emoji_spec.rb +++ b/spec/lib/mastodon/cli/emoji_spec.rb @@ -4,9 +4,5 @@ require 'rails_helper' require 'mastodon/cli/emoji' describe Mastodon::CLI::Emoji do - describe '.exit_on_failure?' do - it 'returns true' do - expect(described_class.exit_on_failure?).to be true - end - end + it_behaves_like 'CLI Command' end diff --git a/spec/lib/mastodon/cli/feeds_spec.rb b/spec/lib/mastodon/cli/feeds_spec.rb index 030f08721..e16113c85 100644 --- a/spec/lib/mastodon/cli/feeds_spec.rb +++ b/spec/lib/mastodon/cli/feeds_spec.rb @@ -6,11 +6,7 @@ require 'mastodon/cli/feeds' describe Mastodon::CLI::Feeds do let(:cli) { described_class.new } - describe '.exit_on_failure?' do - it 'returns true' do - expect(described_class.exit_on_failure?).to be true - end - end + it_behaves_like 'CLI Command' describe '#build' do before { Fabricate(:account) } diff --git a/spec/lib/mastodon/cli/ip_blocks_spec.rb b/spec/lib/mastodon/cli/ip_blocks_spec.rb index 030d9fcb1..684314dc7 100644 --- a/spec/lib/mastodon/cli/ip_blocks_spec.rb +++ b/spec/lib/mastodon/cli/ip_blocks_spec.rb @@ -6,11 +6,7 @@ require 'mastodon/cli/ip_blocks' describe Mastodon::CLI::IpBlocks do let(:cli) { described_class.new } - describe '.exit_on_failure?' do - it 'returns true' do - expect(described_class.exit_on_failure?).to be true - end - end + it_behaves_like 'CLI Command' describe '#add' do let(:ip_list) do diff --git a/spec/lib/mastodon/cli/main_spec.rb b/spec/lib/mastodon/cli/main_spec.rb index e3709afe3..b5b5d6906 100644 --- a/spec/lib/mastodon/cli/main_spec.rb +++ b/spec/lib/mastodon/cli/main_spec.rb @@ -4,11 +4,7 @@ require 'rails_helper' require 'mastodon/cli/main' describe Mastodon::CLI::Main do - describe '.exit_on_failure?' do - it 'returns true' do - expect(described_class.exit_on_failure?).to be true - end - end + it_behaves_like 'CLI Command' describe 'version' do it 'returns the Mastodon version' do diff --git a/spec/lib/mastodon/cli/maintenance_spec.rb b/spec/lib/mastodon/cli/maintenance_spec.rb index a6789ea5a..95e695ab5 100644 --- a/spec/lib/mastodon/cli/maintenance_spec.rb +++ b/spec/lib/mastodon/cli/maintenance_spec.rb @@ -6,11 +6,7 @@ require 'mastodon/cli/maintenance' describe Mastodon::CLI::Maintenance do let(:cli) { described_class.new } - describe '.exit_on_failure?' do - it 'returns true' do - expect(described_class.exit_on_failure?).to be true - end - end + it_behaves_like 'CLI Command' describe '#fix_duplicates' do context 'when the database version is too old' do diff --git a/spec/lib/mastodon/cli/media_spec.rb b/spec/lib/mastodon/cli/media_spec.rb index 305d67d28..15f84c14b 100644 --- a/spec/lib/mastodon/cli/media_spec.rb +++ b/spec/lib/mastodon/cli/media_spec.rb @@ -6,11 +6,7 @@ require 'mastodon/cli/media' describe Mastodon::CLI::Media do let(:cli) { described_class.new } - describe '.exit_on_failure?' do - it 'returns true' do - expect(described_class.exit_on_failure?).to be true - end - end + it_behaves_like 'CLI Command' describe '#remove' do context 'with --prune-profiles and --remove-headers' do diff --git a/spec/lib/mastodon/cli/preview_cards_spec.rb b/spec/lib/mastodon/cli/preview_cards_spec.rb index 1e064ed58..a766d250e 100644 --- a/spec/lib/mastodon/cli/preview_cards_spec.rb +++ b/spec/lib/mastodon/cli/preview_cards_spec.rb @@ -6,11 +6,7 @@ require 'mastodon/cli/preview_cards' describe Mastodon::CLI::PreviewCards do let(:cli) { described_class.new } - describe '.exit_on_failure?' do - it 'returns true' do - expect(described_class.exit_on_failure?).to be true - end - end + it_behaves_like 'CLI Command' describe '#remove' do context 'with relevant preview cards' do diff --git a/spec/lib/mastodon/cli/search_spec.rb b/spec/lib/mastodon/cli/search_spec.rb index d5cae5bf4..785dc2bd6 100644 --- a/spec/lib/mastodon/cli/search_spec.rb +++ b/spec/lib/mastodon/cli/search_spec.rb @@ -4,9 +4,5 @@ require 'rails_helper' require 'mastodon/cli/search' describe Mastodon::CLI::Search do - describe '.exit_on_failure?' do - it 'returns true' do - expect(described_class.exit_on_failure?).to be true - end - end + it_behaves_like 'CLI Command' end diff --git a/spec/lib/mastodon/cli/settings_spec.rb b/spec/lib/mastodon/cli/settings_spec.rb index ae58e74e5..7dcd1110b 100644 --- a/spec/lib/mastodon/cli/settings_spec.rb +++ b/spec/lib/mastodon/cli/settings_spec.rb @@ -4,11 +4,7 @@ require 'rails_helper' require 'mastodon/cli/settings' describe Mastodon::CLI::Settings do - describe '.exit_on_failure?' do - it 'returns true' do - expect(described_class.exit_on_failure?).to be true - end - end + it_behaves_like 'CLI Command' describe 'subcommand "registrations"' do let(:cli) { Mastodon::CLI::Registrations.new } diff --git a/spec/lib/mastodon/cli/statuses_spec.rb b/spec/lib/mastodon/cli/statuses_spec.rb index 38ebcd993..70e4e2c08 100644 --- a/spec/lib/mastodon/cli/statuses_spec.rb +++ b/spec/lib/mastodon/cli/statuses_spec.rb @@ -6,11 +6,7 @@ require 'mastodon/cli/statuses' describe Mastodon::CLI::Statuses do let(:cli) { described_class.new } - describe '.exit_on_failure?' do - it 'returns true' do - expect(described_class.exit_on_failure?).to be true - end - end + it_behaves_like 'CLI Command' describe '#remove', use_transactional_tests: false do context 'with small batch size' do diff --git a/spec/lib/mastodon/cli/upgrade_spec.rb b/spec/lib/mastodon/cli/upgrade_spec.rb index 9e0ab9d06..817044f7e 100644 --- a/spec/lib/mastodon/cli/upgrade_spec.rb +++ b/spec/lib/mastodon/cli/upgrade_spec.rb @@ -4,9 +4,5 @@ require 'rails_helper' require 'mastodon/cli/upgrade' describe Mastodon::CLI::Upgrade do - describe '.exit_on_failure?' do - it 'returns true' do - expect(described_class.exit_on_failure?).to be true - end - end + it_behaves_like 'CLI Command' end diff --git a/spec/support/examples/cli.rb b/spec/support/examples/cli.rb new file mode 100644 index 000000000..091c842bd --- /dev/null +++ b/spec/support/examples/cli.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +shared_examples 'CLI Command' do + it 'configures Thor to exit on failure' do + expect(described_class.exit_on_failure?).to be true + end + + it 'descends from the CLI base class' do + expect(described_class.new).to be_a(Mastodon::CLI::Base) + end +end From 1564799952ec4b8039eecb28125493814bd56ed0 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 1 Dec 2023 09:18:45 -0500 Subject: [PATCH 06/14] Add spec coverage for media CLI `refresh` command (#28166) --- lib/mastodon/cli/media.rb | 1 + spec/lib/mastodon/cli/media_spec.rb | 73 +++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/lib/mastodon/cli/media.rb b/lib/mastodon/cli/media.rb index c90616177..c3275b799 100644 --- a/lib/mastodon/cli/media.rb +++ b/lib/mastodon/cli/media.rb @@ -265,6 +265,7 @@ module Mastodon::CLI elsif options[:days].present? scope = MediaAttachment.remote else + say('Specify the source of media attachments', :red) exit(1) end diff --git a/spec/lib/mastodon/cli/media_spec.rb b/spec/lib/mastodon/cli/media_spec.rb index 15f84c14b..6d510c1f5 100644 --- a/spec/lib/mastodon/cli/media_spec.rb +++ b/spec/lib/mastodon/cli/media_spec.rb @@ -86,4 +86,77 @@ describe Mastodon::CLI::Media do end end end + + describe '#refresh' do + context 'without any options' do + let(:options) { {} } + + it 'warns about usage and exits' do + expect { cli.invoke(:refresh, [], options) }.to output( + a_string_including('Specify the source') + ).to_stdout.and raise_error(SystemExit) + end + end + + context 'with --status option' do + before do + media_attachment.update(file_file_name: nil) + end + + let(:media_attachment) { Fabricate(:media_attachment, status: status, remote_url: 'https://host.example/asset.jpg') } + let(:options) { { status: status.id } } + let(:status) { Fabricate(:status) } + + it 'redownloads the attachment file' do + expect { cli.invoke(:refresh, [], options) }.to output( + a_string_including('Downloaded 1 media') + ).to_stdout + end + end + + context 'with --account option' do + context 'when the account does not exist' do + let(:options) { { account: 'not-real-user@example.host' } } + + it 'warns about usage and exits' do + expect { cli.invoke(:refresh, [], options) }.to output( + a_string_including('No such account') + ).to_stdout.and raise_error(SystemExit) + end + end + + context 'when the account exists' do + before do + media_attachment.update(file_file_name: nil) + end + + let(:media_attachment) { Fabricate(:media_attachment, account: account) } + let(:options) { { account: account.acct } } + let(:account) { Fabricate(:account) } + + it 'redownloads the attachment file' do + expect { cli.invoke(:refresh, [], options) }.to output( + a_string_including('Downloaded 1 media') + ).to_stdout + end + end + end + + context 'with --domain option' do + before do + media_attachment.update(file_file_name: nil) + end + + let(:domain) { 'example.host' } + let(:media_attachment) { Fabricate(:media_attachment, account: account) } + let(:options) { { domain: domain } } + let(:account) { Fabricate(:account, domain: domain) } + + it 'redownloads the attachment file' do + expect { cli.invoke(:refresh, [], options) }.to output( + a_string_including('Downloaded 1 media') + ).to_stdout + end + end + end end From f70f39dd04886c2ced6d424cdcb8690fcddd52f7 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 1 Dec 2023 10:52:47 -0500 Subject: [PATCH 07/14] Add explicit `dependent: nil` to associations (#28169) --- .rubocop_todo.yml | 14 -------------- app/models/concerns/account/counters.rb | 2 +- app/models/conversation.rb | 2 +- app/models/custom_emoji.rb | 2 +- app/models/custom_emoji_category.rb | 2 +- app/models/domain_block.rb | 2 +- app/models/invite.rb | 2 +- app/models/status.rb | 14 +++++++++----- app/models/user.rb | 8 ++++---- app/models/web/push_subscription.rb | 2 +- 10 files changed, 20 insertions(+), 30 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9fb163ceb..03543c8e0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -112,20 +112,6 @@ Rails/HasAndBelongsToMany: - 'app/models/status.rb' - 'app/models/tag.rb' -# Configuration parameters: Include. -# Include: app/models/**/*.rb -Rails/HasManyOrHasOneDependent: - Exclude: - - 'app/models/concerns/account/counters.rb' - - 'app/models/conversation.rb' - - 'app/models/custom_emoji.rb' - - 'app/models/custom_emoji_category.rb' - - 'app/models/domain_block.rb' - - 'app/models/invite.rb' - - 'app/models/status.rb' - - 'app/models/user.rb' - - 'app/models/web/push_subscription.rb' - # Configuration parameters: Include. # Include: app/controllers/**/*.rb, app/mailers/**/*.rb Rails/LexicallyScopedActionFilter: diff --git a/app/models/concerns/account/counters.rb b/app/models/concerns/account/counters.rb index fb69be9b7..448839812 100644 --- a/app/models/concerns/account/counters.rb +++ b/app/models/concerns/account/counters.rb @@ -6,7 +6,7 @@ module Account::Counters ALLOWED_COUNTER_KEYS = %i(statuses_count following_count followers_count).freeze included do - has_one :account_stat, inverse_of: :account + has_one :account_stat, inverse_of: :account, dependent: nil after_save :save_account_stat end diff --git a/app/models/conversation.rb b/app/models/conversation.rb index 5de259962..a7fe14884 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -13,7 +13,7 @@ class Conversation < ApplicationRecord validates :uri, uniqueness: true, if: :uri? - has_many :statuses + has_many :statuses, dependent: nil def local? uri.nil? diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb index 717de2772..97b1c63bf 100644 --- a/app/models/custom_emoji.rb +++ b/app/models/custom_emoji.rb @@ -37,7 +37,7 @@ class CustomEmoji < ApplicationRecord belongs_to :category, class_name: 'CustomEmojiCategory', optional: true - has_one :local_counterpart, -> { where(domain: nil) }, class_name: 'CustomEmoji', primary_key: :shortcode, foreign_key: :shortcode, inverse_of: false + has_one :local_counterpart, -> { where(domain: nil) }, class_name: 'CustomEmoji', primary_key: :shortcode, foreign_key: :shortcode, inverse_of: false, dependent: nil has_attached_file :image, styles: { static: { format: 'png', convert_options: '-coalesce +profile "!icc,*" +set date:modify +set date:create +set date:timestamp' } }, validate_media_type: false diff --git a/app/models/custom_emoji_category.rb b/app/models/custom_emoji_category.rb index 3c87f2b2e..f48074651 100644 --- a/app/models/custom_emoji_category.rb +++ b/app/models/custom_emoji_category.rb @@ -11,7 +11,7 @@ # class CustomEmojiCategory < ApplicationRecord - has_many :emojis, class_name: 'CustomEmoji', foreign_key: 'category_id', inverse_of: :category + has_many :emojis, class_name: 'CustomEmoji', foreign_key: 'category_id', inverse_of: :category, dependent: nil validates :name, presence: true, uniqueness: true end diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb index a7af2d62e..ff23f8fcc 100644 --- a/app/models/domain_block.rb +++ b/app/models/domain_block.rb @@ -25,7 +25,7 @@ class DomainBlock < ApplicationRecord validates :domain, presence: true, uniqueness: true, domain: true - has_many :accounts, foreign_key: :domain, primary_key: :domain, inverse_of: false + has_many :accounts, foreign_key: :domain, primary_key: :domain, inverse_of: false, dependent: nil delegate :count, to: :accounts, prefix: true scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) } diff --git a/app/models/invite.rb b/app/models/invite.rb index 8e816cef0..c0cbc5845 100644 --- a/app/models/invite.rb +++ b/app/models/invite.rb @@ -20,7 +20,7 @@ class Invite < ApplicationRecord include Expireable belongs_to :user, inverse_of: :invites - has_many :users, inverse_of: :invite + has_many :users, inverse_of: :invite, dependent: nil scope :available, -> { where(expires_at: nil).or(where('expires_at >= ?', Time.now.utc)) } diff --git a/app/models/status.rb b/app/models/status.rb index 7b1ca69c7..eb7159dc6 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -66,12 +66,14 @@ class Status < ApplicationRecord has_many :bookmarks, inverse_of: :status, dependent: :destroy has_many :reblogs, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblog, dependent: :destroy has_many :reblogged_by_accounts, through: :reblogs, class_name: 'Account', source: :account - has_many :replies, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :thread + has_many :replies, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :thread, dependent: nil has_many :mentions, dependent: :destroy, inverse_of: :status has_many :mentioned_accounts, through: :mentions, source: :account, class_name: 'Account' - has_many :active_mentions, -> { active }, class_name: 'Mention', inverse_of: :status has_many :media_attachments, dependent: :nullify + # The `dependent` option is enabled by the initial `mentions` association declaration + has_many :active_mentions, -> { active }, class_name: 'Mention', inverse_of: :status # rubocop:disable Rails/HasManyOrHasOneDependent + # Those associations are used for the private search index has_many :local_mentioned, -> { merge(Account.local) }, through: :active_mentions, source: :account has_many :local_favorited, -> { merge(Account.local) }, through: :favourites, source: :account @@ -80,11 +82,13 @@ class Status < ApplicationRecord has_and_belongs_to_many :tags - has_one :preview_cards_status, inverse_of: :status # Because of a composite primary key, the dependent option cannot be used + # Because of a composite primary key, the `dependent` option cannot be used on this association + has_one :preview_cards_status, inverse_of: :status # rubocop:disable Rails/HasManyOrHasOneDependent + has_one :notification, as: :activity, dependent: :destroy - has_one :status_stat, inverse_of: :status + has_one :status_stat, inverse_of: :status, dependent: nil has_one :poll, inverse_of: :status, dependent: :destroy - has_one :trend, class_name: 'StatusTrend', inverse_of: :status + has_one :trend, class_name: 'StatusTrend', inverse_of: :status, dependent: nil validates :uri, uniqueness: true, presence: true, unless: :local? validates :text, presence: true, unless: -> { with_media? || reblog? } diff --git a/app/models/user.rb b/app/models/user.rb index 550f8bfd3..a1574c02a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -84,12 +84,12 @@ class User < ApplicationRecord belongs_to :role, class_name: 'UserRole', optional: true accepts_nested_attributes_for :account - has_many :applications, class_name: 'Doorkeeper::Application', as: :owner - has_many :backups, inverse_of: :user - has_many :invites, inverse_of: :user + has_many :applications, class_name: 'Doorkeeper::Application', as: :owner, dependent: nil + has_many :backups, inverse_of: :user, dependent: nil + has_many :invites, inverse_of: :user, dependent: nil has_many :markers, inverse_of: :user, dependent: :destroy has_many :webauthn_credentials, dependent: :destroy - has_many :ips, class_name: 'UserIp', inverse_of: :user + has_many :ips, class_name: 'UserIp', inverse_of: :user, dependent: nil has_one :invite_request, class_name: 'UserInviteRequest', inverse_of: :user, dependent: :destroy accepts_nested_attributes_for :invite_request, reject_if: ->(attributes) { attributes['text'].blank? && !Setting.require_invite_text } diff --git a/app/models/web/push_subscription.rb b/app/models/web/push_subscription.rb index 0ffbe068e..a3a2ec3f0 100644 --- a/app/models/web/push_subscription.rb +++ b/app/models/web/push_subscription.rb @@ -19,7 +19,7 @@ class Web::PushSubscription < ApplicationRecord belongs_to :user, optional: true belongs_to :access_token, class_name: 'Doorkeeper::AccessToken', optional: true - has_one :session_activation, foreign_key: 'web_push_subscription_id', inverse_of: :web_push_subscription + has_one :session_activation, foreign_key: 'web_push_subscription_id', inverse_of: :web_push_subscription, dependent: nil validates :endpoint, presence: true validates :key_p256dh, presence: true From a98fccf84e9deed1ea1aa52b5adbc0c1f0bdfaab Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 1 Dec 2023 10:52:52 -0500 Subject: [PATCH 08/14] Fix `Style/SelfAssignment` cop (#28171) --- lib/mastodon/snowflake.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mastodon/snowflake.rb b/lib/mastodon/snowflake.rb index 0a596b294..ec4f6140c 100644 --- a/lib/mastodon/snowflake.rb +++ b/lib/mastodon/snowflake.rb @@ -99,7 +99,7 @@ module Mastodon::Snowflake def id_at(timestamp, with_random: true) id = timestamp.to_i * 1000 id += rand(1000) if with_random - id = id << 16 + id <<= 16 id += rand(2**16) if with_random id end From d83d01eb1e2f2ae56cd3f3a40e254fcfec51360c Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 1 Dec 2023 10:52:56 -0500 Subject: [PATCH 09/14] Fix `Lint/RedundantSafeNavigation` cop (#28172) --- app/controllers/api/v1/accounts_controller.rb | 2 +- app/models/trends/history.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/accounts_controller.rb b/app/controllers/api/v1/accounts_controller.rb index 653529316..be251b425 100644 --- a/app/controllers/api/v1/accounts_controller.rb +++ b/app/controllers/api/v1/accounts_controller.rb @@ -49,7 +49,7 @@ class Api::V1::AccountsController < Api::BaseController end def mute - MuteService.new.call(current_user.account, @account, notifications: truthy_param?(:notifications), duration: (params[:duration]&.to_i || 0)) + MuteService.new.call(current_user.account, @account, notifications: truthy_param?(:notifications), duration: params[:duration].to_i) render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships end diff --git a/app/models/trends/history.rb b/app/models/trends/history.rb index db3689933..21331f00d 100644 --- a/app/models/trends/history.rb +++ b/app/models/trends/history.rb @@ -37,7 +37,7 @@ class Trends::History end def uses - with_redis { |redis| redis.get(key_for(:uses))&.to_i || 0 } + with_redis { |redis| redis.get(key_for(:uses)).to_i } end def add(account_id) From aa8563d43df93647db50e52eddccba63500e0c88 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 1 Dec 2023 10:53:15 -0500 Subject: [PATCH 10/14] Fix `Style/SuperWithArgsParentheses` cop (#28174) --- spec/support/signed_request_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/support/signed_request_helpers.rb b/spec/support/signed_request_helpers.rb index 33d7dba6b..eba4095e4 100644 --- a/spec/support/signed_request_helpers.rb +++ b/spec/support/signed_request_helpers.rb @@ -2,7 +2,7 @@ module SignedRequestHelpers def get(path, headers: nil, sign_with: nil, **args) - return super path, headers: headers, **args if sign_with.nil? + return super(path, headers: headers, **args) if sign_with.nil? headers ||= {} headers['Date'] = Time.now.utc.httpdate @@ -16,6 +16,6 @@ module SignedRequestHelpers headers['Signature'] = "keyId=\"#{key_id}\",algorithm=\"rsa-sha256\",headers=\"#{signed_headers.keys.join(' ').downcase}\",signature=\"#{signature}\"" - super path, headers: headers, **args + super(path, headers: headers, **args) end end From 5631f139c1f6f923923a82f8c55d5ab0820a2788 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 1 Dec 2023 10:53:35 -0500 Subject: [PATCH 11/14] Fix `Lint/SymbolConversion` cop (#28175) --- app/models/concerns/remotable.rb | 2 +- app/models/user_settings/setting.rb | 2 +- config/deploy.rb | 2 +- spec/models/concerns/remotable_spec.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/concerns/remotable.rb b/app/models/concerns/remotable.rb index cb8f46e68..bd8b6f4eb 100644 --- a/app/models/concerns/remotable.rb +++ b/app/models/concerns/remotable.rb @@ -5,7 +5,7 @@ module Remotable class_methods do def remotable_attachment(attachment_name, limit, suppress_errors: true, download_on_assign: true, attribute_name: nil) - attribute_name ||= "#{attachment_name}_remote_url".to_sym + attribute_name ||= :"#{attachment_name}_remote_url" define_method("download_#{attachment_name}!") do |url = nil| url ||= self[attribute_name] diff --git a/app/models/user_settings/setting.rb b/app/models/user_settings/setting.rb index 9c1701744..1ab6cbeab 100644 --- a/app/models/user_settings/setting.rb +++ b/app/models/user_settings/setting.rb @@ -62,7 +62,7 @@ class UserSettings::Setting def key if namespace - "#{namespace}.#{name}".to_sym + :"#{namespace}.#{name}" else name end diff --git a/config/deploy.rb b/config/deploy.rb index b19567a72..75bfcc26f 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -20,7 +20,7 @@ namespace :systemd do SYSTEMD_SERVICES.each do |service| SERVICE_ACTIONS.each do |action| desc "Perform a #{action} on #{service} service" - task "#{service}:#{action}".to_sym do + task :"#{service}:#{action}" do on roles(:app) do # runs e.g. "sudo restart mastodon-sidekiq.service" sudo :systemctl, action, "#{fetch(:application)}-#{service}.service" diff --git a/spec/models/concerns/remotable_spec.rb b/spec/models/concerns/remotable_spec.rb index db690da3c..9f6aeb7fb 100644 --- a/spec/models/concerns/remotable_spec.rb +++ b/spec/models/concerns/remotable_spec.rb @@ -31,7 +31,7 @@ RSpec.describe Remotable do end end - let(:attribute_name) { "#{hoge}_remote_url".to_sym } + let(:attribute_name) { :"#{hoge}_remote_url" } let(:code) { 200 } let(:file) { 'filename="foo.txt"' } let(:foo) { foo_class.new } From 3bc437b99a19bba26c0c637b18ce6c7410d5a606 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 1 Dec 2023 11:00:44 -0500 Subject: [PATCH 12/14] Fix `Style/RedundantParentheses` cop (#28176) --- app/controllers/api/base_controller.rb | 2 +- app/lib/feed_manager.rb | 4 ++-- lib/mastodon/cli/media.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index c81ba32b0..b3c60fcaf 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -64,7 +64,7 @@ class Api::BaseController < ApplicationController end def doorkeeper_unauthorized_render_options(error: nil) - { json: { error: (error.try(:description) || 'Not authorized') } } + { json: { error: error.try(:description) || 'Not authorized' } } end def doorkeeper_forbidden_render_options(*) diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index 4e645a11f..53767486f 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -420,8 +420,8 @@ class FeedManager check_for_blocks = status.active_mentions.pluck(:account_id) check_for_blocks.push(status.in_reply_to_account) if status.reply? && !status.in_reply_to_account_id.nil? - should_filter = blocks_or_mutes?(receiver_id, check_for_blocks, :mentions) # Filter if it's from someone I blocked, in reply to someone I blocked, or mentioning someone I blocked (or muted) - should_filter ||= (status.account.silenced? && !Follow.where(account_id: receiver_id, target_account_id: status.account_id).exists?) # of if the account is silenced and I'm not following them + should_filter = blocks_or_mutes?(receiver_id, check_for_blocks, :mentions) # Filter if it's from someone I blocked, in reply to someone I blocked, or mentioning someone I blocked (or muted) + should_filter ||= status.account.silenced? && !Follow.where(account_id: receiver_id, target_account_id: status.account_id).exists? # of if the account is silenced and I'm not following them should_filter end diff --git a/lib/mastodon/cli/media.rb b/lib/mastodon/cli/media.rb index c3275b799..a796bb729 100644 --- a/lib/mastodon/cli/media.rb +++ b/lib/mastodon/cli/media.rb @@ -48,8 +48,8 @@ module Mastodon::CLI next if account.avatar.blank? && account.header.blank? next if options[:remove_headers] && account.header.blank? - size = (account.header_file_size || 0) - size += (account.avatar_file_size || 0) if options[:prune_profiles] + size = account.header_file_size || 0 + size += account.avatar_file_size || 0 if options[:prune_profiles] unless dry_run? account.header.destroy From 469ee2ae36d0c4b355fd5486c294133be75288a0 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 1 Dec 2023 11:07:19 -0500 Subject: [PATCH 13/14] Fix `Style/HashEachMethods` cop (#28173) --- db/seeds/03_roles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/seeds/03_roles.rb b/db/seeds/03_roles.rb index 8b359582b..95a989a95 100644 --- a/db/seeds/03_roles.rb +++ b/db/seeds/03_roles.rb @@ -6,6 +6,6 @@ UserRole.everyone # Create default roles defined in config file default_roles = YAML.load_file(Rails.root.join('config', 'roles.yml')) -default_roles.each do |_, config| +default_roles.each_value do |config| UserRole.create_with(position: config['position'], permissions_as_keys: config['permissions'], highlighted: true).find_or_create_by(name: config['name']) end From 456597dae5251af841e46ab0608e0d44a7de1197 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 1 Dec 2023 17:22:15 +0100 Subject: [PATCH 14/14] Update dependency doorkeeper to v5.6.8 (#28177) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 40f85c7d4..4c78e6b0a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -245,7 +245,7 @@ GEM docile (1.4.0) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) - doorkeeper (5.6.7) + doorkeeper (5.6.8) railties (>= 5) dotenv (2.8.1) dotenv-rails (2.8.1) @@ -617,7 +617,7 @@ GEM redlock (1.3.2) redis (>= 3.0.0, < 6.0) regexp_parser (2.8.2) - reline (0.4.0) + reline (0.4.1) io-console (~> 0.5) request_store (1.5.1) rack (>= 1.4)