From 541f64b2bb785ce9721a27da0ed8bf97610d8c73 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 23 May 2023 07:26:10 -0400 Subject: [PATCH 01/10] Fix Rails/Exit cop (#24743) --- .rubocop.yml | 3 ++- .rubocop_todo.yml | 6 ------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index ceade6e582..46cf0275f8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -171,10 +171,11 @@ Rails/FilePath: Rails/HttpStatus: EnforcedStyle: numeric -# Reason: Allowed only in the `tootctl` CLI application code +# Reason: Allowed in `tootctl` CLI code and in boot ENV checker # https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsexit Rails/Exit: Exclude: + - 'config/boot.rb' - 'lib/mastodon/*_cli.rb' - 'lib/mastodon/cli_helper.rb' - 'lib/cli.rb' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index de6857e071..22412a053d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -712,12 +712,6 @@ Rails/DuplicateAssociation: - 'app/serializers/activitypub/collection_serializer.rb' - 'app/serializers/activitypub/note_serializer.rb' -# Configuration parameters: Include. -# Include: app/**/*.rb, config/**/*.rb, lib/**/*.rb -Rails/Exit: - Exclude: - - 'config/boot.rb' - # Configuration parameters: Include. # Include: app/models/**/*.rb Rails/HasAndBelongsToMany: From fea0830614612f64d1d23d668b7ff44d1edf774a Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 23 May 2023 14:27:17 +0200 Subject: [PATCH 02/10] Remove invalid X-Frame-Options: ALLOWALL (#25070) --- app/controllers/media_controller.rb | 2 +- app/controllers/statuses_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/media_controller.rb b/app/controllers/media_controller.rb index 99a3f3431d..3bf5b7eba7 100644 --- a/app/controllers/media_controller.rb +++ b/app/controllers/media_controller.rb @@ -45,6 +45,6 @@ class MediaController < ApplicationController end def allow_iframing - response.headers['X-Frame-Options'] = 'ALLOWALL' + response.headers.delete('X-Frame-Options') end end diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb index f1b2bc350d..1ff0fbd600 100644 --- a/app/controllers/statuses_controller.rb +++ b/app/controllers/statuses_controller.rb @@ -45,7 +45,7 @@ class StatusesController < ApplicationController return not_found if @status.hidden? || @status.reblog? expires_in 180, public: true - response.headers['X-Frame-Options'] = 'ALLOWALL' + response.headers.delete('X-Frame-Options') render layout: 'embedded' end From 9017df7178cff50c58f8ab4e88b268d6afb129f6 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 23 May 2023 14:27:37 +0200 Subject: [PATCH 03/10] Remove dead code in Api::V1::FeaturedTagsController (#25073) --- app/controllers/api/v1/featured_tags_controller.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/controllers/api/v1/featured_tags_controller.rb b/app/controllers/api/v1/featured_tags_controller.rb index 5c81877bd9..516046f009 100644 --- a/app/controllers/api/v1/featured_tags_controller.rb +++ b/app/controllers/api/v1/featured_tags_controller.rb @@ -31,8 +31,4 @@ class Api::V1::FeaturedTagsController < Api::BaseController def set_featured_tags @featured_tags = current_account.featured_tags.order(statuses_count: :desc) end - - def featured_tag_params - params.require(:name) - end end From 100840c06e5c771524cb2ef55dbb99b077984911 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 23 May 2023 14:28:21 +0200 Subject: [PATCH 04/10] Fix video player offering to expand in a lightbox when it's in an iframe (#25067) --- app/javascript/mastodon/containers/media_container.jsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/javascript/mastodon/containers/media_container.jsx b/app/javascript/mastodon/containers/media_container.jsx index d988808975..ede8641d65 100644 --- a/app/javascript/mastodon/containers/media_container.jsx +++ b/app/javascript/mastodon/containers/media_container.jsx @@ -73,6 +73,13 @@ export default class MediaContainer extends PureComponent { render () { const { locale, components } = this.props; + let handleOpenVideo; + + // Don't offer to expand the video in a lightbox if we're in a frame + if (window.self === window.top) { + handleOpenVideo = this.handleOpenVideo; + } + return ( <> @@ -89,7 +96,7 @@ export default class MediaContainer extends PureComponent { ...(componentName === 'Video' ? { componentIndex: i, - onOpenVideo: this.handleOpenVideo, + onOpenVideo: handleOpenVideo, } : { onOpenMedia: this.handleOpenMedia, }), From dfa5889fc080df6a60951829946032d40c222ccd Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 23 May 2023 15:00:36 +0200 Subject: [PATCH 05/10] Change Identity to not destroy associated User on destroy (#25098) --- app/models/identity.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/identity.rb b/app/models/identity.rb index 6f10fed4d7..c95a68a6f6 100644 --- a/app/models/identity.rb +++ b/app/models/identity.rb @@ -13,7 +13,7 @@ # class Identity < ApplicationRecord - belongs_to :user, dependent: :destroy + belongs_to :user validates :uid, presence: true, uniqueness: { scope: :provider } validates :provider, presence: true From ca66e61b933b97a74f1f79b820a2fa3bd5ffc5f2 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 23 May 2023 15:17:09 +0200 Subject: [PATCH 06/10] Add support for custom sign-up URLs (#25014) --- app/helpers/application_helper.rb | 2 +- .../mastodon/features/interaction_modal/index.jsx | 6 ++++-- .../mastodon/features/ui/components/header.jsx | 11 ++++++++--- .../features/ui/components/sign_in_banner.jsx | 8 +++++--- app/serializers/rest/instance_serializer.rb | 1 + 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 19d297725e..cdd5927c40 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -52,7 +52,7 @@ module ApplicationHelper if closed_registrations? || omniauth_only? 'https://joinmastodon.org/#getting-started' else - new_user_registration_path + ENV.fetch('SSO_ACCOUNT_SIGN_UP', new_user_registration_path) end end diff --git a/app/javascript/mastodon/features/interaction_modal/index.jsx b/app/javascript/mastodon/features/interaction_modal/index.jsx index 0f3b36122b..b1ff72b0ef 100644 --- a/app/javascript/mastodon/features/interaction_modal/index.jsx +++ b/app/javascript/mastodon/features/interaction_modal/index.jsx @@ -9,6 +9,7 @@ import { openModal, closeModal } from 'mastodon/actions/modal'; const mapStateToProps = (state, { accountId }) => ({ displayNameHtml: state.getIn(['accounts', accountId, 'display_name_html']), + signupUrl: state.getIn(['server', 'server', 'registrations', 'url'], '/auth/sign_up'), }); const mapDispatchToProps = (dispatch) => ({ @@ -81,6 +82,7 @@ class InteractionModal extends PureComponent { url: PropTypes.string, type: PropTypes.oneOf(['reply', 'reblog', 'favourite', 'follow']), onSignupClick: PropTypes.func.isRequired, + signupUrl: PropTypes.string.isRequired, }; handleSignupClick = () => { @@ -88,7 +90,7 @@ class InteractionModal extends PureComponent { }; render () { - const { url, type, displayNameHtml } = this.props; + const { url, type, displayNameHtml, signupUrl } = this.props; const name = ; @@ -121,7 +123,7 @@ class InteractionModal extends PureComponent { if (registrationsOpen) { signupButton = ( - + ); diff --git a/app/javascript/mastodon/features/ui/components/header.jsx b/app/javascript/mastodon/features/ui/components/header.jsx index 79b43ecb60..c73626865c 100644 --- a/app/javascript/mastodon/features/ui/components/header.jsx +++ b/app/javascript/mastodon/features/ui/components/header.jsx @@ -16,6 +16,10 @@ const Account = connect(state => ({ )); +const mapStateToProps = (state) => ({ + signupUrl: state.getIn(['server', 'server', 'registrations', 'url'], '/auth/sign_up'), +}); + const mapDispatchToProps = (dispatch) => ({ openClosedRegistrationsModal() { dispatch(openModal('CLOSED_REGISTRATIONS')); @@ -31,11 +35,12 @@ class Header extends PureComponent { static propTypes = { openClosedRegistrationsModal: PropTypes.func, location: PropTypes.object, + signupUrl: PropTypes.string.isRequired, }; render () { const { signedIn } = this.context.identity; - const { location, openClosedRegistrationsModal } = this.props; + const { location, openClosedRegistrationsModal, signupUrl } = this.props; let content; @@ -51,7 +56,7 @@ class Header extends PureComponent { if (registrationsOpen) { signupButton = ( - + ); @@ -87,4 +92,4 @@ class Header extends PureComponent { } -export default withRouter(connect(null, mapDispatchToProps)(Header)); +export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Header)); diff --git a/app/javascript/mastodon/features/ui/components/sign_in_banner.jsx b/app/javascript/mastodon/features/ui/components/sign_in_banner.jsx index 984a574e56..53aefd34cc 100644 --- a/app/javascript/mastodon/features/ui/components/sign_in_banner.jsx +++ b/app/javascript/mastodon/features/ui/components/sign_in_banner.jsx @@ -1,11 +1,11 @@ import { useCallback } from 'react'; import { FormattedMessage } from 'react-intl'; -import { useDispatch } from 'react-redux'; +import { useAppDispatch, useAppSelector } from 'mastodon/store'; import { registrationsOpen } from 'mastodon/initial_state'; import { openModal } from 'mastodon/actions/modal'; const SignInBanner = () => { - const dispatch = useDispatch(); + const dispatch = useAppDispatch(); const openClosedRegistrationsModal = useCallback( () => dispatch(openModal('CLOSED_REGISTRATIONS')), @@ -14,9 +14,11 @@ const SignInBanner = () => { let signupButton; + const signupUrl = useAppSelector((state) => state.getIn(['server', 'server', 'registrations', 'url'], '/auth/sign_up')); + if (registrationsOpen) { signupButton = ( - + ); diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index a07840f0ca..14aeda9462 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -85,6 +85,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer enabled: registrations_enabled?, approval_required: Setting.registrations_mode == 'approved', message: registrations_enabled? ? nil : registrations_message, + url: ENV.fetch('SSO_ACCOUNT_SIGN_UP', nil), } end From c9f980b26812ec737f81ee9c56b70241c8a372ad Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 23 May 2023 09:44:11 -0400 Subject: [PATCH 07/10] Add request spec for backups download (#25099) --- spec/requests/backups_spec.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 spec/requests/backups_spec.rb diff --git a/spec/requests/backups_spec.rb b/spec/requests/backups_spec.rb new file mode 100644 index 0000000000..a6c2efe0db --- /dev/null +++ b/spec/requests/backups_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Backups' do + include RoutingHelper + + describe 'GET backups#download' do + let(:user) { Fabricate(:user) } + let(:backup) { Fabricate(:backup, user: user) } + + before do + sign_in user + end + + it 'Downloads a user backup' do + get download_backup_path(backup) + + expect(response).to redirect_to(backup_dump_url) + end + + def backup_dump_url + full_asset_url(backup.dump.url) + end + end +end From b6b4ea4ca5bdf3c92abbaf4ed3fe82587a0233f1 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 23 May 2023 10:08:26 -0400 Subject: [PATCH 08/10] Move the mastodon/*_cli files to mastodon/cli/* (#24139) --- .rubocop.yml | 18 +++-- .rubocop_todo.yml | 16 ++--- bin/tootctl | 4 +- .../{accounts_cli.rb => cli/accounts.rb} | 12 ++-- lib/mastodon/{cache_cli.rb => cli/cache.rb} | 12 ++-- .../canonical_email_blocks.rb} | 12 ++-- .../{domains_cli.rb => cli/domains.rb} | 12 ++-- .../email_domain_blocks.rb} | 12 ++-- lib/mastodon/{emoji_cli.rb => cli/emoji.rb} | 10 +-- lib/mastodon/{feeds_cli.rb => cli/feeds.rb} | 12 ++-- lib/mastodon/{cli_helper.rb => cli/helper.rb} | 4 +- .../{ip_blocks_cli.rb => cli/ip_blocks.rb} | 10 +-- lib/{cli.rb => mastodon/cli/main.rb} | 66 +++++++++---------- .../maintenance.rb} | 12 ++-- lib/mastodon/{media_cli.rb => cli/media.rb} | 12 ++-- .../preview_cards.rb} | 12 ++-- lib/mastodon/{search_cli.rb => cli/search.rb} | 12 ++-- .../{settings_cli.rb => cli/settings.rb} | 14 ++-- .../{statuses_cli.rb => cli/statuses.rb} | 12 ++-- .../{upgrade_cli.rb => cli/upgrade.rb} | 12 ++-- .../ip_blocks_spec.rb} | 4 +- .../{cli_spec.rb => cli/main_spec.rb} | 4 +- .../settings_spec.rb} | 6 +- 23 files changed, 149 insertions(+), 151 deletions(-) rename lib/mastodon/{accounts_cli.rb => cli/accounts.rb} (99%) rename lib/mastodon/{cache_cli.rb => cli/cache.rb} (91%) rename lib/mastodon/{canonical_email_blocks_cli.rb => cli/canonical_email_blocks.rb} (86%) rename lib/mastodon/{domains_cli.rb => cli/domains.rb} (98%) rename lib/mastodon/{email_domain_blocks_cli.rb => cli/email_domain_blocks.rb} (94%) rename lib/mastodon/{emoji_cli.rb => cli/emoji.rb} (96%) rename lib/mastodon/{feeds_cli.rb => cli/feeds.rb} (90%) rename lib/mastodon/{cli_helper.rb => cli/helper.rb} (98%) rename lib/mastodon/{ip_blocks_cli.rb => cli/ip_blocks.rb} (96%) rename lib/{cli.rb => mastodon/cli/main.rb} (75%) rename lib/mastodon/{maintenance_cli.rb => cli/maintenance.rb} (99%) rename lib/mastodon/{media_cli.rb => cli/media.rb} (98%) rename lib/mastodon/{preview_cards_cli.rb => cli/preview_cards.rb} (90%) rename lib/mastodon/{search_cli.rb => cli/search.rb} (95%) rename lib/mastodon/{settings_cli.rb => cli/settings.rb} (80%) rename lib/mastodon/{statuses_cli.rb => cli/statuses.rb} (98%) rename lib/mastodon/{upgrade_cli.rb => cli/upgrade.rb} (96%) rename spec/lib/mastodon/{ip_blocks_cli_spec.rb => cli/ip_blocks_spec.rb} (99%) rename spec/lib/mastodon/{cli_spec.rb => cli/main_spec.rb} (81%) rename spec/lib/mastodon/{settings_cli_spec.rb => cli/settings_spec.rb} (92%) diff --git a/.rubocop.yml b/.rubocop.yml index 46cf0275f8..4eef9d63e6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -43,7 +43,7 @@ Layout/LineLength: - !ruby/regexp / \# .*$/ - !ruby/regexp /^\# .*$/ Exclude: - - lib/**/*cli*.rb + - 'lib/mastodon/cli/*.rb' - db/*migrate/**/* - db/seeds/**/* @@ -57,7 +57,7 @@ Lint/UselessAccessModifier: # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsabcsize Metrics/AbcSize: Exclude: - - 'lib/**/*cli*.rb' + - 'lib/mastodon/cli/*.rb' - db/*migrate/**/* # Reason: Some functions cannot be broken up, but others may be refactor candidates @@ -66,7 +66,7 @@ Metrics/BlockLength: CountAsOne: ['array', 'hash', 'heredoc', 'method_call'] Exclude: - 'config/routes.rb' - - 'lib/mastodon/*_cli.rb' + - 'lib/mastodon/cli/*.rb' - 'lib/tasks/*.rake' - 'app/models/concerns/account_associations.rb' - 'app/models/concerns/account_interactions.rb' @@ -95,14 +95,14 @@ Metrics/BlockLength: # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsblocknesting Metrics/BlockNesting: Exclude: - - 'lib/mastodon/*_cli.rb' + - 'lib/mastodon/cli/*.rb' # Reason: Some Excluded files would be candidates for refactoring but not currently addressed # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsclasslength Metrics/ClassLength: CountAsOne: ['array', 'hash', 'heredoc', 'method_call'] Exclude: - - 'lib/mastodon/*_cli.rb' + - 'lib/mastodon/cli/*.rb' - 'app/controllers/admin/accounts_controller.rb' - 'app/controllers/api/base_controller.rb' - 'app/controllers/api/v1/admin/accounts_controller.rb' @@ -146,7 +146,7 @@ Metrics/ClassLength: # https://docs.rubocop.org/rubocop/cops_metrics.html#metricscyclomaticcomplexity Metrics/CyclomaticComplexity: Exclude: - - lib/mastodon/*cli*.rb + - lib/mastodon/cli/*.rb - db/*migrate/**/* # Reason: Currently disabled in .rubocop_todo.yml @@ -154,7 +154,7 @@ Metrics/CyclomaticComplexity: Metrics/MethodLength: CountAsOne: [array, heredoc] Exclude: - - 'lib/mastodon/*_cli.rb' + - 'lib/mastodon/cli/*.rb' # Reason: # https://docs.rubocop.org/rubocop/cops_metrics.html#metricsmodulelength @@ -176,9 +176,7 @@ Rails/HttpStatus: Rails/Exit: Exclude: - 'config/boot.rb' - - 'lib/mastodon/*_cli.rb' - - 'lib/mastodon/cli_helper.rb' - - 'lib/cli.rb' + - 'lib/mastodon/cli/*.rb' # Reason: Some single letter camel case files shouldn't be split # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecfilepath diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 22412a053d..94439ce479 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -846,9 +846,9 @@ Rails/SkipsModelValidations: - 'db/post_migrate/20220617202502_migrate_roles.rb' - 'db/post_migrate/20221101190723_backfill_admin_action_logs.rb' - 'db/post_migrate/20221206114142_backfill_admin_action_logs_again.rb' - - 'lib/cli.rb' - - 'lib/mastodon/accounts_cli.rb' - - 'lib/mastodon/maintenance_cli.rb' + - 'lib/mastodon/cli/accounts.rb' + - 'lib/mastodon/cli/main.rb' + - 'lib/mastodon/cli/maintenance.rb' - 'spec/controllers/api/v1/admin/accounts_controller_spec.rb' - 'spec/lib/activitypub/activity/follow_spec.rb' - 'spec/services/follow_service_spec.rb' @@ -929,7 +929,7 @@ Rails/WhereExists: - 'app/validators/vote_validator.rb' - 'app/workers/move_worker.rb' - 'db/migrate/20190529143559_preserve_old_layout_for_existing_users.rb' - - 'lib/mastodon/email_domain_blocks_cli.rb' + - 'lib/mastodon/cli/email_domain_blocks.rb' - 'lib/tasks/tests.rake' - 'spec/controllers/api/v1/accounts/notes_controller_spec.rb' - 'spec/controllers/api/v1/tags_controller_spec.rb' @@ -991,7 +991,7 @@ Style/FormatStringToken: Exclude: - 'app/models/privacy_policy.rb' - 'config/initializers/devise.rb' - - 'lib/mastodon/maintenance_cli.rb' + - 'lib/mastodon/cli/maintenance.rb' - 'lib/paperclip/color_extractor.rb' # This cop supports unsafe autocorrection (--autocorrect-all). @@ -1436,9 +1436,9 @@ Style/GuardClause: - 'db/post_migrate/20220704024901_migrate_settings_to_user_roles.rb' - 'lib/devise/two_factor_ldap_authenticatable.rb' - 'lib/devise/two_factor_pam_authenticatable.rb' - - 'lib/mastodon/accounts_cli.rb' - - 'lib/mastodon/maintenance_cli.rb' - - 'lib/mastodon/media_cli.rb' + - 'lib/mastodon/cli/accounts.rb' + - 'lib/mastodon/cli/maintenance.rb' + - 'lib/mastodon/cli/media.rb' - 'lib/paperclip/attachment_extensions.rb' - 'lib/tasks/repo.rake' diff --git a/bin/tootctl b/bin/tootctl index 9c7ae8b871..b3311c6b2a 100755 --- a/bin/tootctl +++ b/bin/tootctl @@ -2,11 +2,11 @@ APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' -require_relative '../lib/cli' +require_relative '../lib/mastodon/cli/main' begin Chewy.strategy(:mastodon) do - Mastodon::CLI.start(ARGV) + Mastodon::CLI::Main.start(ARGV) end rescue Interrupt exit(130) diff --git a/lib/mastodon/accounts_cli.rb b/lib/mastodon/cli/accounts.rb similarity index 99% rename from lib/mastodon/accounts_cli.rb rename to lib/mastodon/cli/accounts.rb index c09577c9ef..a44f63db03 100644 --- a/lib/mastodon/accounts_cli.rb +++ b/lib/mastodon/cli/accounts.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true require 'set' -require_relative '../../config/boot' -require_relative '../../config/environment' -require_relative 'cli_helper' +require_relative '../../../config/boot' +require_relative '../../../config/environment' +require_relative 'helper' -module Mastodon - class AccountsCLI < Thor - include CLIHelper +module Mastodon::CLI + class Accounts < Thor + include Helper def self.exit_on_failure? true diff --git a/lib/mastodon/cache_cli.rb b/lib/mastodon/cli/cache.rb similarity index 91% rename from lib/mastodon/cache_cli.rb rename to lib/mastodon/cli/cache.rb index 803404c34f..b0bf6aabd8 100644 --- a/lib/mastodon/cache_cli.rb +++ b/lib/mastodon/cli/cache.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require_relative '../../config/boot' -require_relative '../../config/environment' -require_relative 'cli_helper' +require_relative '../../../config/boot' +require_relative '../../../config/environment' +require_relative 'helper' -module Mastodon - class CacheCLI < Thor - include CLIHelper +module Mastodon::CLI + class Cache < Thor + include Helper def self.exit_on_failure? true diff --git a/lib/mastodon/canonical_email_blocks_cli.rb b/lib/mastodon/cli/canonical_email_blocks.rb similarity index 86% rename from lib/mastodon/canonical_email_blocks_cli.rb rename to lib/mastodon/cli/canonical_email_blocks.rb index ec228d466a..f3c427a2c7 100644 --- a/lib/mastodon/canonical_email_blocks_cli.rb +++ b/lib/mastodon/cli/canonical_email_blocks.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true require 'concurrent' -require_relative '../../config/boot' -require_relative '../../config/environment' -require_relative 'cli_helper' +require_relative '../../../config/boot' +require_relative '../../../config/environment' +require_relative 'helper' -module Mastodon - class CanonicalEmailBlocksCLI < Thor - include CLIHelper +module Mastodon::CLI + class CanonicalEmailBlocks < Thor + include Helper def self.exit_on_failure? true diff --git a/lib/mastodon/domains_cli.rb b/lib/mastodon/cli/domains.rb similarity index 98% rename from lib/mastodon/domains_cli.rb rename to lib/mastodon/cli/domains.rb index 05f08f4623..8b5f03ce0f 100644 --- a/lib/mastodon/domains_cli.rb +++ b/lib/mastodon/cli/domains.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true require 'concurrent' -require_relative '../../config/boot' -require_relative '../../config/environment' -require_relative 'cli_helper' +require_relative '../../../config/boot' +require_relative '../../../config/environment' +require_relative 'helper' -module Mastodon - class DomainsCLI < Thor - include CLIHelper +module Mastodon::CLI + class Domains < Thor + include Helper def self.exit_on_failure? true diff --git a/lib/mastodon/email_domain_blocks_cli.rb b/lib/mastodon/cli/email_domain_blocks.rb similarity index 94% rename from lib/mastodon/email_domain_blocks_cli.rb rename to lib/mastodon/cli/email_domain_blocks.rb index f39f470691..6ef35cc8cf 100644 --- a/lib/mastodon/email_domain_blocks_cli.rb +++ b/lib/mastodon/cli/email_domain_blocks.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true require 'concurrent' -require_relative '../../config/boot' -require_relative '../../config/environment' -require_relative 'cli_helper' +require_relative '../../../config/boot' +require_relative '../../../config/environment' +require_relative 'helper' -module Mastodon - class EmailDomainBlocksCLI < Thor - include CLIHelper +module Mastodon::CLI + class EmailDomainBlocks < Thor + include Helper def self.exit_on_failure? true diff --git a/lib/mastodon/emoji_cli.rb b/lib/mastodon/cli/emoji.rb similarity index 96% rename from lib/mastodon/emoji_cli.rb rename to lib/mastodon/cli/emoji.rb index 8f2432a3e2..9b41a59c29 100644 --- a/lib/mastodon/emoji_cli.rb +++ b/lib/mastodon/cli/emoji.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true require 'rubygems/package' -require_relative '../../config/boot' -require_relative '../../config/environment' -require_relative 'cli_helper' +require_relative '../../../config/boot' +require_relative '../../../config/environment' +require_relative 'helper' -module Mastodon - class EmojiCLI < Thor +module Mastodon::CLI + class Emoji < Thor def self.exit_on_failure? true end diff --git a/lib/mastodon/feeds_cli.rb b/lib/mastodon/cli/feeds.rb similarity index 90% rename from lib/mastodon/feeds_cli.rb rename to lib/mastodon/cli/feeds.rb index fcfb487404..4307b880f7 100644 --- a/lib/mastodon/feeds_cli.rb +++ b/lib/mastodon/cli/feeds.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require_relative '../../config/boot' -require_relative '../../config/environment' -require_relative 'cli_helper' +require_relative '../../../config/boot' +require_relative '../../../config/environment' +require_relative 'helper' -module Mastodon - class FeedsCLI < Thor - include CLIHelper +module Mastodon::CLI + class Feeds < Thor + include Helper include Redisable def self.exit_on_failure? diff --git a/lib/mastodon/cli_helper.rb b/lib/mastodon/cli/helper.rb similarity index 98% rename from lib/mastodon/cli_helper.rb rename to lib/mastodon/cli/helper.rb index ab1351ae80..b277e16ebd 100644 --- a/lib/mastodon/cli_helper.rb +++ b/lib/mastodon/cli/helper.rb @@ -9,8 +9,8 @@ HttpLog.configuration.logger = dev_null Paperclip.options[:log] = false Chewy.logger = dev_null -module Mastodon - module CLIHelper +module Mastodon::CLI + module Helper def dry_run? options[:dry_run] end diff --git a/lib/mastodon/ip_blocks_cli.rb b/lib/mastodon/cli/ip_blocks.rb similarity index 96% rename from lib/mastodon/ip_blocks_cli.rb rename to lib/mastodon/cli/ip_blocks.rb index 82a08753bc..561d64d182 100644 --- a/lib/mastodon/ip_blocks_cli.rb +++ b/lib/mastodon/cli/ip_blocks.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true require 'rubygems/package' -require_relative '../../config/boot' -require_relative '../../config/environment' -require_relative 'cli_helper' +require_relative '../../../config/boot' +require_relative '../../../config/environment' +require_relative 'helper' -module Mastodon - class IpBlocksCLI < Thor +module Mastodon::CLI + class IpBlocks < Thor def self.exit_on_failure? true end diff --git a/lib/cli.rb b/lib/mastodon/cli/main.rb similarity index 75% rename from lib/cli.rb rename to lib/mastodon/cli/main.rb index ac235cf039..0f2236f78f 100644 --- a/lib/cli.rb +++ b/lib/mastodon/cli/main.rb @@ -1,73 +1,73 @@ # frozen_string_literal: true require 'thor' -require_relative 'mastodon/media_cli' -require_relative 'mastodon/emoji_cli' -require_relative 'mastodon/accounts_cli' -require_relative 'mastodon/feeds_cli' -require_relative 'mastodon/search_cli' -require_relative 'mastodon/settings_cli' -require_relative 'mastodon/statuses_cli' -require_relative 'mastodon/domains_cli' -require_relative 'mastodon/preview_cards_cli' -require_relative 'mastodon/cache_cli' -require_relative 'mastodon/upgrade_cli' -require_relative 'mastodon/email_domain_blocks_cli' -require_relative 'mastodon/canonical_email_blocks_cli' -require_relative 'mastodon/ip_blocks_cli' -require_relative 'mastodon/maintenance_cli' -require_relative 'mastodon/version' +require_relative 'media' +require_relative 'emoji' +require_relative 'accounts' +require_relative 'feeds' +require_relative 'search' +require_relative 'settings' +require_relative 'statuses' +require_relative 'domains' +require_relative 'preview_cards' +require_relative 'cache' +require_relative 'upgrade' +require_relative 'email_domain_blocks' +require_relative 'canonical_email_blocks' +require_relative 'ip_blocks' +require_relative 'maintenance' +require_relative '../version' -module Mastodon - class CLI < Thor +module Mastodon::CLI + class Main < Thor def self.exit_on_failure? true end desc 'media SUBCOMMAND ...ARGS', 'Manage media files' - subcommand 'media', Mastodon::MediaCLI + subcommand 'media', Media desc 'emoji SUBCOMMAND ...ARGS', 'Manage custom emoji' - subcommand 'emoji', Mastodon::EmojiCLI + subcommand 'emoji', Emoji desc 'accounts SUBCOMMAND ...ARGS', 'Manage accounts' - subcommand 'accounts', Mastodon::AccountsCLI + subcommand 'accounts', Accounts desc 'feeds SUBCOMMAND ...ARGS', 'Manage feeds' - subcommand 'feeds', Mastodon::FeedsCLI + subcommand 'feeds', Feeds desc 'search SUBCOMMAND ...ARGS', 'Manage the search engine' - subcommand 'search', Mastodon::SearchCLI + subcommand 'search', Search desc 'settings SUBCOMMAND ...ARGS', 'Manage dynamic settings' - subcommand 'settings', Mastodon::SettingsCLI + subcommand 'settings', Settings desc 'statuses SUBCOMMAND ...ARGS', 'Manage statuses' - subcommand 'statuses', Mastodon::StatusesCLI + subcommand 'statuses', Statuses desc 'domains SUBCOMMAND ...ARGS', 'Manage account domains' - subcommand 'domains', Mastodon::DomainsCLI + subcommand 'domains', Domains desc 'preview_cards SUBCOMMAND ...ARGS', 'Manage preview cards' - subcommand 'preview_cards', Mastodon::PreviewCardsCLI + subcommand 'preview_cards', PreviewCards desc 'cache SUBCOMMAND ...ARGS', 'Manage cache' - subcommand 'cache', Mastodon::CacheCLI + subcommand 'cache', Cache desc 'upgrade SUBCOMMAND ...ARGS', 'Various version upgrade utilities' - subcommand 'upgrade', Mastodon::UpgradeCLI + subcommand 'upgrade', Upgrade desc 'email_domain_blocks SUBCOMMAND ...ARGS', 'Manage e-mail domain blocks' - subcommand 'email_domain_blocks', Mastodon::EmailDomainBlocksCLI + subcommand 'email_domain_blocks', EmailDomainBlocks desc 'ip_blocks SUBCOMMAND ...ARGS', 'Manage IP blocks' - subcommand 'ip_blocks', Mastodon::IpBlocksCLI + subcommand 'ip_blocks', IpBlocks desc 'canonical_email_blocks SUBCOMMAND ...ARGS', 'Manage canonical e-mail blocks' - subcommand 'canonical_email_blocks', Mastodon::CanonicalEmailBlocksCLI + subcommand 'canonical_email_blocks', CanonicalEmailBlocks desc 'maintenance SUBCOMMAND ...ARGS', 'Various maintenance utilities' - subcommand 'maintenance', Mastodon::MaintenanceCLI + subcommand 'maintenance', Maintenance option :dry_run, type: :boolean desc 'self-destruct', 'Erase the server from the federation' diff --git a/lib/mastodon/maintenance_cli.rb b/lib/mastodon/cli/maintenance.rb similarity index 99% rename from lib/mastodon/maintenance_cli.rb rename to lib/mastodon/cli/maintenance.rb index 88bd191ea9..d9f1b02570 100644 --- a/lib/mastodon/maintenance_cli.rb +++ b/lib/mastodon/cli/maintenance.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true require 'tty-prompt' -require_relative '../../config/boot' -require_relative '../../config/environment' -require_relative 'cli_helper' +require_relative '../../../config/boot' +require_relative '../../../config/environment' +require_relative 'helper' -module Mastodon - class MaintenanceCLI < Thor - include CLIHelper +module Mastodon::CLI + class Maintenance < Thor + include Helper def self.exit_on_failure? true diff --git a/lib/mastodon/media_cli.rb b/lib/mastodon/cli/media.rb similarity index 98% rename from lib/mastodon/media_cli.rb rename to lib/mastodon/cli/media.rb index 1bedcd9beb..509c4ca264 100644 --- a/lib/mastodon/media_cli.rb +++ b/lib/mastodon/cli/media.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require_relative '../../config/boot' -require_relative '../../config/environment' -require_relative 'cli_helper' +require_relative '../../../config/boot' +require_relative '../../../config/environment' +require_relative 'helper' -module Mastodon - class MediaCLI < Thor +module Mastodon::CLI + class Media < Thor include ActionView::Helpers::NumberHelper - include CLIHelper + include Helper VALID_PATH_SEGMENTS_SIZE = [7, 10].freeze diff --git a/lib/mastodon/preview_cards_cli.rb b/lib/mastodon/cli/preview_cards.rb similarity index 90% rename from lib/mastodon/preview_cards_cli.rb rename to lib/mastodon/cli/preview_cards.rb index cf4407250c..794b25693a 100644 --- a/lib/mastodon/preview_cards_cli.rb +++ b/lib/mastodon/cli/preview_cards.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true require 'tty-prompt' -require_relative '../../config/boot' -require_relative '../../config/environment' -require_relative 'cli_helper' +require_relative '../../../config/boot' +require_relative '../../../config/environment' +require_relative 'helper' -module Mastodon - class PreviewCardsCLI < Thor +module Mastodon::CLI + class PreviewCards < Thor include ActionView::Helpers::NumberHelper - include CLIHelper + include Helper def self.exit_on_failure? true diff --git a/lib/mastodon/search_cli.rb b/lib/mastodon/cli/search.rb similarity index 95% rename from lib/mastodon/search_cli.rb rename to lib/mastodon/cli/search.rb index 31e9a3d5af..ccece5b5f8 100644 --- a/lib/mastodon/search_cli.rb +++ b/lib/mastodon/cli/search.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require_relative '../../config/boot' -require_relative '../../config/environment' -require_relative 'cli_helper' +require_relative '../../../config/boot' +require_relative '../../../config/environment' +require_relative 'helper' -module Mastodon - class SearchCLI < Thor - include CLIHelper +module Mastodon::CLI + class Search < Thor + include Helper # Indices are sorted by amount of data to be expected in each, so that # smaller indices can go online sooner diff --git a/lib/mastodon/settings_cli.rb b/lib/mastodon/cli/settings.rb similarity index 80% rename from lib/mastodon/settings_cli.rb rename to lib/mastodon/cli/settings.rb index 488c655dee..5869efc466 100644 --- a/lib/mastodon/settings_cli.rb +++ b/lib/mastodon/cli/settings.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require_relative '../../config/boot' -require_relative '../../config/environment' -require_relative 'cli_helper' +require_relative '../../../config/boot' +require_relative '../../../config/environment' +require_relative 'helper' -module Mastodon - class RegistrationsCLI < Thor +module Mastodon::CLI + class Registrations < Thor def self.exit_on_failure? true end @@ -37,8 +37,8 @@ module Mastodon end end - class SettingsCLI < Thor + class Settings < Thor desc 'registrations SUBCOMMAND ...ARGS', 'Manage state of registrations' - subcommand 'registrations', RegistrationsCLI + subcommand 'registrations', Registrations end end diff --git a/lib/mastodon/statuses_cli.rb b/lib/mastodon/cli/statuses.rb similarity index 98% rename from lib/mastodon/statuses_cli.rb rename to lib/mastodon/cli/statuses.rb index baab83e297..e5eb759608 100644 --- a/lib/mastodon/statuses_cli.rb +++ b/lib/mastodon/cli/statuses.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require_relative '../../config/boot' -require_relative '../../config/environment' -require_relative 'cli_helper' +require_relative '../../../config/boot' +require_relative '../../../config/environment' +require_relative 'helper' -module Mastodon - class StatusesCLI < Thor - include CLIHelper +module Mastodon::CLI + class Statuses < Thor + include Helper include ActionView::Helpers::NumberHelper def self.exit_on_failure? diff --git a/lib/mastodon/upgrade_cli.rb b/lib/mastodon/cli/upgrade.rb similarity index 96% rename from lib/mastodon/upgrade_cli.rb rename to lib/mastodon/cli/upgrade.rb index 2b60f9eee5..f20fa4cdf4 100644 --- a/lib/mastodon/upgrade_cli.rb +++ b/lib/mastodon/cli/upgrade.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require_relative '../../config/boot' -require_relative '../../config/environment' -require_relative 'cli_helper' +require_relative '../../../config/boot' +require_relative '../../../config/environment' +require_relative 'helper' -module Mastodon - class UpgradeCLI < Thor - include CLIHelper +module Mastodon::CLI + class Upgrade < Thor + include Helper def self.exit_on_failure? true diff --git a/spec/lib/mastodon/ip_blocks_cli_spec.rb b/spec/lib/mastodon/cli/ip_blocks_spec.rb similarity index 99% rename from spec/lib/mastodon/ip_blocks_cli_spec.rb rename to spec/lib/mastodon/cli/ip_blocks_spec.rb index 27c005772b..e7639d9aaf 100644 --- a/spec/lib/mastodon/ip_blocks_cli_spec.rb +++ b/spec/lib/mastodon/cli/ip_blocks_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true require 'rails_helper' -require 'mastodon/ip_blocks_cli' +require 'mastodon/cli/ip_blocks' -RSpec.describe Mastodon::IpBlocksCLI do +RSpec.describe Mastodon::CLI::IpBlocks do let(:cli) { described_class.new } describe '#add' do diff --git a/spec/lib/mastodon/cli_spec.rb b/spec/lib/mastodon/cli/main_spec.rb similarity index 81% rename from spec/lib/mastodon/cli_spec.rb rename to spec/lib/mastodon/cli/main_spec.rb index 419f8b864e..105c4ec371 100644 --- a/spec/lib/mastodon/cli_spec.rb +++ b/spec/lib/mastodon/cli/main_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true require 'rails_helper' -require 'cli' +require 'mastodon/cli/main' -describe Mastodon::CLI do +describe Mastodon::CLI::Main do describe 'version' do it 'returns the Mastodon version' do expect { described_class.new.invoke(:version) }.to output( diff --git a/spec/lib/mastodon/settings_cli_spec.rb b/spec/lib/mastodon/cli/settings_spec.rb similarity index 92% rename from spec/lib/mastodon/settings_cli_spec.rb rename to spec/lib/mastodon/cli/settings_spec.rb index 713cb7e437..01f0775628 100644 --- a/spec/lib/mastodon/settings_cli_spec.rb +++ b/spec/lib/mastodon/cli/settings_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true require 'rails_helper' -require 'mastodon/settings_cli' +require 'mastodon/cli/settings' -RSpec.describe Mastodon::SettingsCLI do +RSpec.describe Mastodon::CLI::Settings do describe 'subcommand "registrations"' do - let(:cli) { Mastodon::RegistrationsCLI.new } + let(:cli) { Mastodon::CLI::Registrations.new } before do Setting.registrations_mode = nil From 778e4a7bf73b196a6a98bd839b7fd9c44de3d6f7 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 23 May 2023 10:40:21 -0400 Subject: [PATCH 09/10] Fix RSpec/ExpectInHook cop (#25100) --- .rubocop_todo.yml | 6 ------ spec/controllers/api/v1/media_controller_spec.rb | 8 ++------ .../settings/applications_controller_spec.rb | 4 +--- spec/lib/status_filter_spec.rb | 16 ++++++++-------- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 94439ce479..effe4cae56 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -393,12 +393,6 @@ RSpec/ExpectChange: - 'spec/services/unsuspend_account_service_spec.rb' - 'spec/workers/scheduler/accounts_statuses_cleanup_scheduler_spec.rb' -RSpec/ExpectInHook: - Exclude: - - 'spec/controllers/api/v1/media_controller_spec.rb' - - 'spec/controllers/settings/applications_controller_spec.rb' - - 'spec/lib/status_filter_spec.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: implicit, each, example diff --git a/spec/controllers/api/v1/media_controller_spec.rb b/spec/controllers/api/v1/media_controller_spec.rb index 20d58e8c03..79a9d1474a 100644 --- a/spec/controllers/api/v1/media_controller_spec.rb +++ b/spec/controllers/api/v1/media_controller_spec.rb @@ -15,23 +15,19 @@ RSpec.describe Api::V1::MediaController do describe 'POST #create' do describe 'with paperclip errors' do context 'when imagemagick cant identify the file type' do - before do + it 'returns http 422' do expect_any_instance_of(Account).to receive_message_chain(:media_attachments, :create!).and_raise(Paperclip::Errors::NotIdentifiedByImageMagickError) post :create, params: { file: fixture_file_upload('attachment.jpg', 'image/jpeg') } - end - it 'returns http 422' do expect(response).to have_http_status(422) end end context 'when there is a generic error' do - before do + it 'returns http 422' do expect_any_instance_of(Account).to receive_message_chain(:media_attachments, :create!).and_raise(Paperclip::Error) post :create, params: { file: fixture_file_upload('attachment.jpg', 'image/jpeg') } - end - it 'returns http 422' do expect(response).to have_http_status(500) end end diff --git a/spec/controllers/settings/applications_controller_spec.rb b/spec/controllers/settings/applications_controller_spec.rb index c0a57380e8..169304b3ed 100644 --- a/spec/controllers/settings/applications_controller_spec.rb +++ b/spec/controllers/settings/applications_controller_spec.rb @@ -182,12 +182,10 @@ describe Settings::ApplicationsController do describe 'regenerate' do let(:token) { user.token_for_app(app) } - before do + it 'creates new token' do expect(token).to_not be_nil post :regenerate, params: { id: app.id } - end - it 'creates new token' do expect(user.token_for_app(app)).to_not eql(token) end end diff --git a/spec/lib/status_filter_spec.rb b/spec/lib/status_filter_spec.rb index 08519bc590..98e2ef913a 100644 --- a/spec/lib/status_filter_spec.rb +++ b/spec/lib/status_filter_spec.rb @@ -7,7 +7,7 @@ describe StatusFilter do let(:status) { Fabricate(:status) } context 'without an account' do - subject { described_class.new(status, nil) } + subject(:filter) { described_class.new(status, nil) } context 'when there are no connections' do it { is_expected.to_not be_filtered } @@ -22,16 +22,16 @@ describe StatusFilter do end context 'when status policy does not allow show' do - before do + it 'filters the status' do expect_any_instance_of(StatusPolicy).to receive(:show?).and_return(false) - end - it { is_expected.to be_filtered } + expect(filter).to be_filtered + end end end context 'with real account' do - subject { described_class.new(status, account) } + subject(:filter) { described_class.new(status, account) } let(:account) { Fabricate(:account) } @@ -73,11 +73,11 @@ describe StatusFilter do end context 'when status policy does not allow show' do - before do + it 'filters the status' do expect_any_instance_of(StatusPolicy).to receive(:show?).and_return(false) - end - it { is_expected.to be_filtered } + expect(filter).to be_filtered + end end end end From b896b16cb3c8626fbee12a7eda7f882114b1a040 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 23 May 2023 10:49:11 -0400 Subject: [PATCH 10/10] Fix RSpec/PredicateMatcher cop (#25102) --- .rubocop_todo.yml | 9 --------- .../api/v1/accounts/notes_controller_spec.rb | 2 +- spec/models/user_spec.rb | 14 +++++++------- spec/services/post_status_service_spec.rb | 2 +- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index effe4cae56..2e9f6c429f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -556,15 +556,6 @@ RSpec/PendingWithoutReason: Exclude: - 'spec/models/account_spec.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers. -# SupportedStyles: inflected, explicit -RSpec/PredicateMatcher: - Exclude: - - 'spec/controllers/api/v1/accounts/notes_controller_spec.rb' - - 'spec/models/user_spec.rb' - - 'spec/services/post_status_service_spec.rb' - RSpec/StubbedMock: Exclude: - 'spec/controllers/api/base_controller_spec.rb' diff --git a/spec/controllers/api/v1/accounts/notes_controller_spec.rb b/spec/controllers/api/v1/accounts/notes_controller_spec.rb index fd4d34f691..4107105afd 100644 --- a/spec/controllers/api/v1/accounts/notes_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/notes_controller_spec.rb @@ -43,7 +43,7 @@ describe Api::V1::Accounts::NotesController do it 'does not create account note' do subject - expect(AccountNote.where(account_id: user.account.id, target_account_id: account.id).exists?).to be_falsey + expect(AccountNote.where(account_id: user.account.id, target_account_id: account.id)).to_not exist end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ae46f0ae45..d3e0ac63a4 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -115,19 +115,19 @@ RSpec.describe User do it 'allows a non-blacklisted user to be created' do user = User.new(email: 'foo@example.com', account: account, password: password, agreement: true) - expect(user.valid?).to be_truthy + expect(user).to be_valid end it 'does not allow a blacklisted user to be created' do user = User.new(email: 'foo@mvrht.com', account: account, password: password, agreement: true) - expect(user.valid?).to be_falsey + expect(user).to_not be_valid end it 'does not allow a subdomain blacklisted user to be created' do user = User.new(email: 'foo@mvrht.com.topdomain.tld', account: account, password: password, agreement: true) - expect(user.valid?).to be_falsey + expect(user).to_not be_valid end end @@ -350,17 +350,17 @@ RSpec.describe User do it 'does not allow a user to be created unless they are whitelisted' do user = User.new(email: 'foo@example.com', account: account, password: password, agreement: true) - expect(user.valid?).to be_falsey + expect(user).to_not be_valid end it 'allows a user to be created if they are whitelisted' do user = User.new(email: 'foo@mastodon.space', account: account, password: password, agreement: true) - expect(user.valid?).to be_truthy + expect(user).to be_valid end it 'does not allow a user with a whitelisted top domain as subdomain in their email address to be created' do user = User.new(email: 'foo@mastodon.space.userdomain.com', account: account, password: password, agreement: true) - expect(user.valid?).to be_falsey + expect(user).to_not be_valid end context do @@ -374,7 +374,7 @@ RSpec.describe User do Rails.configuration.x.email_domains_blacklist = 'blacklisted.mastodon.space' user = User.new(email: 'foo@blacklisted.mastodon.space', account: account, password: password) - expect(user.valid?).to be_falsey + expect(user).to_not be_valid end end end diff --git a/spec/services/post_status_service_spec.rb b/spec/services/post_status_service_spec.rb index 33153c3d07..f577122710 100644 --- a/spec/services/post_status_service_spec.rb +++ b/spec/services/post_status_service_spec.rb @@ -48,7 +48,7 @@ RSpec.describe PostStatusService, type: :service do expect(status.params['text']).to eq 'Hi future!' expect(status.params['media_ids']).to eq [media.id] expect(media.reload.status).to be_nil - expect(Status.where(text: 'Hi future!').exists?).to be_falsey + expect(Status.where(text: 'Hi future!')).to_not exist end it 'does not change statuses count' do