From a80efb449e09177f9f06ec0a5c0b9c904f1a3d44 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 6 Jun 2023 10:42:23 +0200 Subject: [PATCH 01/17] Configure Renovate (#25255) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Renaud Chaput --- .github/dependabot.yml | 99 ---------------- .github/renovate.json5 | 109 ++++++++++++++++++ .github/workflows/lint-css.yml | 1 + .github/workflows/lint-haml.yml | 1 + .github/workflows/lint-js.yml | 1 + .github/workflows/lint-json.yml | 1 + .github/workflows/lint-md.yml | 1 + .github/workflows/lint-ruby.yml | 1 + .github/workflows/lint-yml.yml | 1 + .github/workflows/rebase-needed.yml | 2 + .github/workflows/test-js.yml | 1 + .../workflows/test-migrations-one-step.yml | 1 + .../workflows/test-migrations-two-step.yml | 1 + .github/workflows/test-ruby.yml | 1 + 14 files changed, 122 insertions(+), 99 deletions(-) delete mode 100644 .github/dependabot.yml create mode 100644 .github/renovate.json5 diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 5e6556cb53..0000000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,99 +0,0 @@ -# To get started with Dependabot version updates, you'll need to specify which -# package ecosystems to update and where the package manifests are located. -# Please see the documentation for all configuration options: -# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates - -version: 2 -updates: - - package-ecosystem: npm - directory: '/' - schedule: - interval: weekly - open-pull-requests-limit: 99 - allow: - - dependency-type: direct - ignore: - # This version needs to match Rails major version, so stick to 6.x only - - dependency-name: '@rails/ujs' - versions: - - '>= 7' - # TODO: This requires code changes for migration - - dependency-name: 'tesseract.js' - versions: - - '>= 3' - # TODO: This version needs manual updates for breaking changes - - dependency-name: 'react-hotkeys' - versions: - - '>= 2' - # TODO: This version requires code changes - - dependency-name: 'webpack-dev-server' - versions: - - '>= 4' - # TODO: This version was ignored in https://github.com/mastodon/mastodon/pull/15238 - - dependency-name: 'webpack-cli' - versions: - - '>= 4' - - - package-ecosystem: bundler - directory: '/' - schedule: - interval: weekly - open-pull-requests-limit: 99 - allow: - - dependency-type: direct - ignore: - # This version needs to match Rails major version, so stick to 6.x only - - dependency-name: 'rails-i18n' - versions: - - '>= 7.0.0' - # This version needs manual updates https://github.com/rails/sprockets/blob/master/UPGRADING.md#guide-to-upgrading-from-sprockets-3x-to-4x - - dependency-name: 'sprockets' - versions: - - '>= 4.0.0' - # This version needs manual updates https://github.com/rails/sprockets/blob/master/UPGRADING.md#guide-to-upgrading-from-sprockets-3x-to-4x - - dependency-name: 'strong_migrations' - versions: - - '>= 1.0.0' - # This version needs updates and to sync with sidekiq-unique-jobs - - dependency-name: 'sidekiq' - versions: - - '>= 7.0.0' - # This version needs updates and to sync with sidekiq - - dependency-name: 'sidekiq-unique-jobs' - versions: - - '>= 8.0.0' - # This version needs updates and to sync with sidekiq and sidekiq-unique-jobs - - dependency-name: 'redis' - versions: - - '>= 5.0.0' - # TODO: was ignored in https://github.com/mastodon/mastodon/pull/13964 - - dependency-name: 'fog-openstack' - versions: - - '>= 1.0.0' - # sassc dependency issue tracked in https://github.com/BetterErrors/better_errors/issues/516 - - dependency-name: 'better_errors' - versions: - - '2.10.0' - - - package-ecosystem: github-actions - directory: '/' - schedule: - interval: weekly - open-pull-requests-limit: 99 - allow: - - dependency-type: direct - - - package-ecosystem: docker - directory: '/' - schedule: - interval: weekly - open-pull-requests-limit: 99 - ignore: - - dependency-name: 'moritzheiber/ruby-jemalloc' - update-types: - # only suggest patch releases for ruby and needs to sync with .ruby-version - - 'version-update:semver-minor' - - dependency-name: 'node' - update-types: - # only node minor releases allowed unless .nvmrc major is changed - - 'version-update:semver-major' diff --git a/.github/renovate.json5 b/.github/renovate.json5 new file mode 100644 index 0000000000..22878636f9 --- /dev/null +++ b/.github/renovate.json5 @@ -0,0 +1,109 @@ +{ + $schema: 'https://docs.renovatebot.com/renovate-schema.json', + extends: [ + 'config:base', + ':dependencyDashboard', + ':labels(dependencies)', + ':maintainLockFilesMonthly', // update non-direct dependencies monthly + ':prConcurrentLimit10', // only 10 open PRs at the same time + ], + stabilityDays: 3, // Wait 3 days after the package has been published before upgrading it + // packageRules order is important, they are applied from top to bottom and are merged, + // so for example grouping rules needs to be at the bottom + packageRules: [ + { + // Ignore major version bumps for these node packages + matchManagers: ['npm'], + matchPackageNames: [ + '@rails/ujs', // Needs to match the major Rails version + 'tesseract.js', // Requires code changes + 'react-hotkeys', // Requires code changes + + // Requires Webpacker upgrade or replacement + '@types/webpack', + 'babel-loader', + 'compression-webpack-plugin', + 'css-loader', + 'imports-loader', + 'mini-css-extract-plugin', + 'postcss-loader', + 'sass-loader', + 'terser-webpack-plugin', + 'webpack', + 'webpack-assets-manifest', + 'webpack-bundle-analyzer', + 'webpack-dev-server', + 'webpack-cli', + + // react-router: Requires manual upgrade + 'history', + 'react-router-dom', + ], + matchUpdateTypes: ['major'], + enabled: false, + }, + { + // Ignore major version bumps for these Ruby packages + matchManagers: ['bundler'], + matchPackageNames: [ + 'sprockets', // Requires manual upgrade https://github.com/rails/sprockets/blob/master/UPGRADING.md#guide-to-upgrading-from-sprockets-3x-to-4x + 'strong_migrations', // Requires manual upgrade + 'sidekiq', // Requires manual upgrade + 'sidekiq-unique-jobs', // Requires manual upgrades and sync with Sidekiq version + 'redis', // Requires manual upgrade and sync with Sidekiq version + 'fog-openstack', // TODO: was ignored in https://github.com/mastodon/mastodon/pull/13964 + + // Needs major Rails version bump + 'rack', + 'rails', + 'rails-i18n', + ], + matchUpdateTypes: ['major'], + enabled: false, + }, + { + // Update Github Actions and Docker images weekly + matchManagers: ['github-actions', 'dockerfile', 'docker-compose'], + extends: ['schedule:weekly'], + }, + { + // Ignore major & minor bumps for the ruby image, this needs to be synced with .ruby-version + matchManagers: ['dockerfile'], + matchPackageNames: ['moritzheiber/ruby-jemalloc'], + matchUpdateTypes: ['minor', 'major'], + enabled: false, + }, + { + // Ignore major bump for the node image, this needs to be synced with .nvmrc + matchManagers: ['dockerfile'], + matchPackageNames: ['node'], + matchUpdateTypes: ['major'], + enabled: false, + }, + { + // Ignore major postgres bumps in the docker-compose file, as those break dev environments + matchManagers: ['docker-compose'], + matchPackageNames: ['postgres'], + matchUpdateTypes: ['major'], + enabled: false, + }, + { + // Update devDependencies every week, with one grouped PR + matchDepTypes: 'devDependencies', + matchUpdateTypes: ['patch', 'minor'], + excludePackageNames: [ + 'typescript', // Typescript has many changes in minor versions, needs to be checked every time + ], + groupName: 'devDependencies (non-major)', + extends: ['schedule:weekly'], + }, + { + // Update @types/* packages every week, with one grouped PR + matchPackagePrefixes: '@types/', + matchUpdateTypes: ['patch', 'minor'], + groupName: 'DefinitelyTyped types (non-major)', + extends: ['schedule:weekly'], + addLabels: ['typescript'], + }, + ], +} diff --git a/.github/workflows/lint-css.yml b/.github/workflows/lint-css.yml index 51bde39bc1..4d3c2ce5af 100644 --- a/.github/workflows/lint-css.yml +++ b/.github/workflows/lint-css.yml @@ -3,6 +3,7 @@ on: push: branches-ignore: - 'dependabot/**' + - 'renovate/**' paths: - 'package.json' - 'yarn.lock' diff --git a/.github/workflows/lint-haml.yml b/.github/workflows/lint-haml.yml index 2ddbca7818..56d817123a 100644 --- a/.github/workflows/lint-haml.yml +++ b/.github/workflows/lint-haml.yml @@ -3,6 +3,7 @@ on: push: branches-ignore: - 'dependabot/**' + - 'renovate/**' paths: - '.github/workflows/haml-lint-problem-matcher.json' - '.github/workflows/lint-haml.yml' diff --git a/.github/workflows/lint-js.yml b/.github/workflows/lint-js.yml index 547035ab3f..1f0cfd1e70 100644 --- a/.github/workflows/lint-js.yml +++ b/.github/workflows/lint-js.yml @@ -3,6 +3,7 @@ on: push: branches-ignore: - 'dependabot/**' + - 'renovate/**' paths: - 'package.json' - 'yarn.lock' diff --git a/.github/workflows/lint-json.yml b/.github/workflows/lint-json.yml index 7dfc0e0588..8712d8bd80 100644 --- a/.github/workflows/lint-json.yml +++ b/.github/workflows/lint-json.yml @@ -3,6 +3,7 @@ on: push: branches-ignore: - 'dependabot/**' + - 'renovate/**' paths: - 'package.json' - 'yarn.lock' diff --git a/.github/workflows/lint-md.yml b/.github/workflows/lint-md.yml index b489ce9684..d19a0470db 100644 --- a/.github/workflows/lint-md.yml +++ b/.github/workflows/lint-md.yml @@ -3,6 +3,7 @@ on: push: branches-ignore: - 'dependabot/**' + - 'renovate/**' paths: - '.github/workflows/lint-md.yml' - '.nvmrc' diff --git a/.github/workflows/lint-ruby.yml b/.github/workflows/lint-ruby.yml index de54fe9ae5..0395c8639f 100644 --- a/.github/workflows/lint-ruby.yml +++ b/.github/workflows/lint-ruby.yml @@ -3,6 +3,7 @@ on: push: branches-ignore: - 'dependabot/**' + - 'renovate/**' paths: - 'Gemfile*' - '.rubocop*.yml' diff --git a/.github/workflows/lint-yml.yml b/.github/workflows/lint-yml.yml index d77451ee62..295e9610b3 100644 --- a/.github/workflows/lint-yml.yml +++ b/.github/workflows/lint-yml.yml @@ -3,6 +3,7 @@ on: push: branches-ignore: - 'dependabot/**' + - 'renovate/**' paths: - 'package.json' - 'yarn.lock' diff --git a/.github/workflows/rebase-needed.yml b/.github/workflows/rebase-needed.yml index 6a8035210c..131a62a576 100644 --- a/.github/workflows/rebase-needed.yml +++ b/.github/workflows/rebase-needed.yml @@ -4,10 +4,12 @@ on: push: branches-ignore: - 'dependabot/**' + - 'renovate/**' - 'l10n_main' pull_request_target: branches-ignore: - 'dependabot/**' + - 'renovate/**' - 'l10n_main' types: [synchronize] diff --git a/.github/workflows/test-js.yml b/.github/workflows/test-js.yml index 32e21d23ce..3306105f9e 100644 --- a/.github/workflows/test-js.yml +++ b/.github/workflows/test-js.yml @@ -3,6 +3,7 @@ on: push: branches-ignore: - 'dependabot/**' + - 'renovate/**' paths: - 'package.json' - 'yarn.lock' diff --git a/.github/workflows/test-migrations-one-step.yml b/.github/workflows/test-migrations-one-step.yml index 212b2cfe73..a91fd819a2 100644 --- a/.github/workflows/test-migrations-one-step.yml +++ b/.github/workflows/test-migrations-one-step.yml @@ -3,6 +3,7 @@ on: push: branches-ignore: - 'dependabot/**' + - 'renovate/**' pull_request: jobs: diff --git a/.github/workflows/test-migrations-two-step.yml b/.github/workflows/test-migrations-two-step.yml index 310153929d..50266fb8a0 100644 --- a/.github/workflows/test-migrations-two-step.yml +++ b/.github/workflows/test-migrations-two-step.yml @@ -3,6 +3,7 @@ on: push: branches-ignore: - 'dependabot/**' + - 'renovate/**' pull_request: jobs: diff --git a/.github/workflows/test-ruby.yml b/.github/workflows/test-ruby.yml index f284745ea4..07cb1d41f8 100644 --- a/.github/workflows/test-ruby.yml +++ b/.github/workflows/test-ruby.yml @@ -4,6 +4,7 @@ on: push: branches-ignore: - 'dependabot/**' + - 'renovate/**' pull_request: env: From 4eda233e09a782df5a935859346a04c10935491e Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 6 Jun 2023 10:42:47 +0200 Subject: [PATCH 02/17] Add webhook templating (#23289) Co-authored-by: Claire --- app/controllers/admin/webhooks_controller.rb | 2 +- app/lib/webhooks/payload_renderer.rb | 67 +++++++++++++++++++ app/models/webhook.rb | 15 ++++- app/views/admin/webhooks/_form.html.haml | 3 + app/views/admin/webhooks/show.html.haml | 16 ++--- app/workers/webhooks/delivery_worker.rb | 2 +- config/locales/simple_form.en.yml | 2 + ...20230129023109_add_template_to_webhooks.rb | 7 ++ db/schema.rb | 1 + spec/lib/webhooks/payload_renderer_spec.rb | 30 +++++++++ 10 files changed, 134 insertions(+), 11 deletions(-) create mode 100644 app/lib/webhooks/payload_renderer.rb create mode 100644 db/migrate/20230129023109_add_template_to_webhooks.rb create mode 100644 spec/lib/webhooks/payload_renderer_spec.rb diff --git a/app/controllers/admin/webhooks_controller.rb b/app/controllers/admin/webhooks_controller.rb index 1ed3fd18ab..01d9ba8ce2 100644 --- a/app/controllers/admin/webhooks_controller.rb +++ b/app/controllers/admin/webhooks_controller.rb @@ -71,7 +71,7 @@ module Admin end def resource_params - params.require(:webhook).permit(:url, events: []) + params.require(:webhook).permit(:url, :template, events: []) end end end diff --git a/app/lib/webhooks/payload_renderer.rb b/app/lib/webhooks/payload_renderer.rb new file mode 100644 index 0000000000..3d2731f6dc --- /dev/null +++ b/app/lib/webhooks/payload_renderer.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +class Webhooks::PayloadRenderer + class DocumentTraverser + INT_REGEX = /[0-9]+/ + + def initialize(document) + @document = document.with_indifferent_access + end + + def get(path) + value = @document.dig(*parse_path(path)) + string = Oj.dump(value) + + # We want to make sure people can use the variable inside + # other strings, so it can't be wrapped in quotes. + if value.is_a?(String) + string[1...-1] + else + string + end + end + + private + + def parse_path(path) + path.split('.').filter_map do |segment| + if segment.match(INT_REGEX) + segment.to_i + else + segment.presence + end + end + end + end + + class TemplateParser < Parslet::Parser + rule(:dot) { str('.') } + rule(:digit) { match('[0-9]') } + rule(:property_name) { match('[a-z_]').repeat(1) } + rule(:array_index) { digit.repeat(1) } + rule(:segment) { (property_name | array_index) } + rule(:path) { property_name >> (dot >> segment).repeat } + rule(:variable) { (str('}}').absent? >> path).repeat.as(:variable) } + rule(:expression) { str('{{') >> variable >> str('}}') } + rule(:text) { (str('{{').absent? >> any).repeat(1) } + rule(:text_with_expressions) { (text.as(:text) | expression).repeat.as(:text) } + root(:text_with_expressions) + end + + EXPRESSION_REGEXP = / + \{\{ + [a-z_]+ + (\. + ([a-z_]+|[0-9]+) + )* + \}\} + /iox + + def initialize(json) + @document = DocumentTraverser.new(Oj.load(json)) + end + + def render(template) + template.gsub(EXPRESSION_REGEXP) { |match| @document.get(match[2...-2]) } + end +end diff --git a/app/models/webhook.rb b/app/models/webhook.rb index c556bcc2bb..c46fce743e 100644 --- a/app/models/webhook.rb +++ b/app/models/webhook.rb @@ -11,6 +11,7 @@ # enabled :boolean default(TRUE), not null # created_at :datetime not null # updated_at :datetime not null +# template :text # class Webhook < ApplicationRecord @@ -30,6 +31,7 @@ class Webhook < ApplicationRecord validates :events, presence: true validate :validate_events + validate :validate_template before_validation :strip_events before_validation :generate_secret @@ -49,7 +51,18 @@ class Webhook < ApplicationRecord private def validate_events - errors.add(:events, :invalid) if events.any? { |e| !EVENTS.include?(e) } + errors.add(:events, :invalid) if events.any? { |e| EVENTS.exclude?(e) } + end + + def validate_template + return if template.blank? + + begin + parser = Webhooks::PayloadRenderer::TemplateParser.new + parser.parse(template) + rescue Parslet::ParseFailed + errors.add(:template, :invalid) + end end def strip_events diff --git a/app/views/admin/webhooks/_form.html.haml b/app/views/admin/webhooks/_form.html.haml index c1e8f8979b..8d019ff43b 100644 --- a/app/views/admin/webhooks/_form.html.haml +++ b/app/views/admin/webhooks/_form.html.haml @@ -7,5 +7,8 @@ .fields-group = f.input :events, collection: Webhook::EVENTS, wrapper: :with_block_label, include_blank: false, as: :check_boxes, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li' + .fields-group + = f.input :template, wrapper: :with_block_label, input_html: { placeholder: '{ "content": "Hello {{object.username}}" }' } + .actions = f.button :button, @webhook.new_record? ? t('admin.webhooks.add_new') : t('generic.save_changes'), type: :submit diff --git a/app/views/admin/webhooks/show.html.haml b/app/views/admin/webhooks/show.html.haml index cc450de26d..5ac809efc5 100644 --- a/app/views/admin/webhooks/show.html.haml +++ b/app/views/admin/webhooks/show.html.haml @@ -2,14 +2,14 @@ = t('admin.webhooks.title') - content_for :heading do - %h2 - %small - = fa_icon 'inbox' - = t('admin.webhooks.webhook') - = @webhook.url - -- content_for :heading_actions do - = link_to t('admin.webhooks.edit'), edit_admin_webhook_path, class: 'button' if can?(:update, @webhook) + .content__heading__row + %h2 + %small + = fa_icon 'inbox' + = t('admin.webhooks.webhook') + = @webhook.url + .content__heading__actions + = link_to t('admin.webhooks.edit'), edit_admin_webhook_path, class: 'button' if can?(:update, @webhook) .table-wrapper %table.table.horizontal-table diff --git a/app/workers/webhooks/delivery_worker.rb b/app/workers/webhooks/delivery_worker.rb index f8ed669fb5..3bbc8e2255 100644 --- a/app/workers/webhooks/delivery_worker.rb +++ b/app/workers/webhooks/delivery_worker.rb @@ -8,7 +8,7 @@ class Webhooks::DeliveryWorker def perform(webhook_id, body) @webhook = Webhook.find(webhook_id) - @body = body + @body = @webhook.template.blank? ? body : Webhooks::PayloadRenderer.new(body).render(@webhook.template) @response = nil perform_request diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 9c747e595d..f92e66e55a 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -131,6 +131,7 @@ en: position: Higher role decides conflict resolution in certain situations. Certain actions can only be performed on roles with a lower priority webhook: events: Select events to send + template: Compose your own JSON payload using variable interpolation. Leave blank for default JSON. url: Where events will be sent to labels: account: @@ -304,6 +305,7 @@ en: position: Priority webhook: events: Enabled events + template: Payload template url: Endpoint URL 'no': 'No' not_recommended: Not recommended diff --git a/db/migrate/20230129023109_add_template_to_webhooks.rb b/db/migrate/20230129023109_add_template_to_webhooks.rb new file mode 100644 index 0000000000..73bdd73ff9 --- /dev/null +++ b/db/migrate/20230129023109_add_template_to_webhooks.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddTemplateToWebhooks < ActiveRecord::Migration[6.1] + def change + add_column :webhooks, :template, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 35fbb8d2ef..fd708b44a0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1136,6 +1136,7 @@ ActiveRecord::Schema.define(version: 2023_06_05_085710) do t.boolean "enabled", default: true, null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.text "template" t.index ["url"], name: "index_webhooks_on_url", unique: true end diff --git a/spec/lib/webhooks/payload_renderer_spec.rb b/spec/lib/webhooks/payload_renderer_spec.rb new file mode 100644 index 0000000000..074847c74c --- /dev/null +++ b/spec/lib/webhooks/payload_renderer_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Webhooks::PayloadRenderer do + subject(:renderer) { described_class.new(json) } + + let(:event) { Webhooks::EventPresenter.new(type, object) } + let(:payload) { ActiveModelSerializers::SerializableResource.new(event, serializer: REST::Admin::WebhookEventSerializer, scope: nil, scope_name: :current_user).as_json } + let(:json) { Oj.dump(payload) } + + describe '#render' do + context 'when event is account.approved' do + let(:type) { 'account.approved' } + let(:object) { Fabricate(:account, display_name: 'Foo"') } + + it 'renders event-related variables into template' do + expect(renderer.render('foo={{event}}')).to eq 'foo=account.approved' + end + + it 'renders event-specific variables into template' do + expect(renderer.render('foo={{object.username}}')).to eq "foo=#{object.username}" + end + + it 'escapes values for use in JSON' do + expect(renderer.render('foo={{object.account.display_name}}')).to eq 'foo=Foo\\"' + end + end + end +end From 683373285264c92cb0ed08c73e460ec471479ec3 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 6 Jun 2023 11:05:25 +0200 Subject: [PATCH 03/17] Fix autocomplete suggestions being cut off in compose form (#25275) --- app/javascript/styles/mastodon/components.scss | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/javascript/styles/mastodon/components.scss b/app/javascript/styles/mastodon/components.scss index 85348db7c7..8ff0908bf6 100644 --- a/app/javascript/styles/mastodon/components.scss +++ b/app/javascript/styles/mastodon/components.scss @@ -3113,10 +3113,10 @@ $ui-header-height: 55px; .compose-form__highlightable { display: flex; flex-direction: column; - overflow: hidden; flex: 0 1 auto; border-radius: 4px; transition: box-shadow 300ms linear; + min-height: 0; &.active { transition: none; @@ -3158,7 +3158,6 @@ $ui-header-height: 55px; .compose-form { flex: 1; - overflow-y: hidden; display: flex; flex-direction: column; min-height: 310px; From 50a8f5b8a7d865276aef1c6afd13c58e20fb0b36 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 6 Jun 2023 11:18:56 +0200 Subject: [PATCH 04/17] Update dependency react-redux to v8.0.7 (#25298) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- yarn.lock | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/yarn.lock b/yarn.lock index fd751c0419..8839ed68d7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2520,9 +2520,9 @@ "@types/node" "*" "@types/scheduler@*": - version "0.16.1" - resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.1.tgz#18845205e86ff0038517aab7a18a62a6b9f71275" - integrity sha512-EaCxbanVeyxDRTQBkdLb3Bvl/HK7PBK6UJjsSixB0iHKoWxE5uu2Q/DgtpOhPIojN0Zl1whvOd7PoHs2P0s5eA== + version "0.16.3" + resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.3.tgz#cef09e3ec9af1d63d2a6cc5b383a737e24e6dcf5" + integrity sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ== "@types/semver@^7.3.12": version "7.3.13" @@ -4583,9 +4583,9 @@ csstype@^2.6.7: integrity sha512-ul26pfSQTZW8dcOnD2iiJssfXw0gdNVX9IJDH/X3K5DGPfj+fUYe3kB+swUY6BF3oZDxaID3AJt+9/ojSAE05A== csstype@^3.0.2: - version "3.0.6" - resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.6.tgz#865d0b5833d7d8d40f4e5b8a6d76aea3de4725ef" - integrity sha512-+ZAmfyWMT7TiIlzdqJgjMb7S4f1beorDbWbsocyK4RaiqA5RTX3K14bnBWmmA9QEM0gRdsjyyrEmcyga8Zsxmw== + version "3.1.2" + resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.2.tgz#1d4bf9d572f11c14031f0436e1c10bc1f571f50b" + integrity sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ== damerau-levenshtein@^1.0.8: version "1.0.8" @@ -9714,7 +9714,7 @@ react-intl@^6.4.2: intl-messageformat "10.3.5" tslib "^2.4.0" -"react-is@^16.12.0 || ^17.0.0 || ^18.0.0", react-is@^18.2.0: +"react-is@^16.12.0 || ^17.0.0 || ^18.0.0", react-is@^18.0.0, react-is@^18.2.0: version "18.2.0" resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b" integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w== @@ -9729,11 +9729,6 @@ react-is@^17.0.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== -react-is@^18.0.0: - version "18.1.0" - resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.1.0.tgz#61aaed3096d30eacf2a2127118b5b41387d32a67" - integrity sha512-Fl7FuabXsJnV5Q1qIOQwx/sagGF18kogb4gpfcG4gjLBWO0WDiiz1ko/ExayuxE7InyQkBLkxRFG5oxY6Uu3Kg== - react-lifecycles-compat@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362" @@ -9778,9 +9773,9 @@ react-redux-loading-bar@^5.0.4: react-lifecycles-compat "^3.0.4" react-redux@^8.0.4: - version "8.0.5" - resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-8.0.5.tgz#e5fb8331993a019b8aaf2e167a93d10af469c7bd" - integrity sha512-Q2f6fCKxPFpkXt1qNRZdEDLlScsDWyrgSj0mliK59qU6W5gvBiKkdMEG2lJzhd1rCctf0hb6EtePPLZ2e0m1uw== + version "8.0.7" + resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-8.0.7.tgz#b74ef2f7ce2076e354540aa3511d3670c2b62571" + integrity sha512-1vRQuCQI5Y2uNmrMXg81RXKiBHY3jBzvCvNmZF437O/Z9/pZ+ba2uYHbemYXb3g8rjsacBGo+/wmfrQKzMhJsg== dependencies: "@babel/runtime" "^7.12.1" "@types/hoist-non-react-statics" "^3.3.1" From fb5bf5cbf8dd83cffabc0de9637513e0d077697d Mon Sep 17 00:00:00 2001 From: alfe Date: Tue, 6 Jun 2023 18:28:50 +0900 Subject: [PATCH 05/17] Rewrite `` as FC and TS (#25259) --- .../mastodon/components/load_more.jsx | 28 ------------------- .../mastodon/components/load_more.tsx | 24 ++++++++++++++++ .../mastodon/components/scrollable_list.jsx | 2 +- .../features/account_gallery/index.jsx | 2 +- .../compose/components/search_results.jsx | 2 +- .../mastodon/features/directory/index.jsx | 2 +- .../mastodon/features/explore/results.jsx | 2 +- 7 files changed, 29 insertions(+), 33 deletions(-) delete mode 100644 app/javascript/mastodon/components/load_more.jsx create mode 100644 app/javascript/mastodon/components/load_more.tsx diff --git a/app/javascript/mastodon/components/load_more.jsx b/app/javascript/mastodon/components/load_more.jsx deleted file mode 100644 index 6b7ecdea0a..0000000000 --- a/app/javascript/mastodon/components/load_more.jsx +++ /dev/null @@ -1,28 +0,0 @@ -import PropTypes from 'prop-types'; -import { PureComponent } from 'react'; - -import { FormattedMessage } from 'react-intl'; - -export default class LoadMore extends PureComponent { - - static propTypes = { - onClick: PropTypes.func, - disabled: PropTypes.bool, - visible: PropTypes.bool, - }; - - static defaultProps = { - visible: true, - }; - - render() { - const { disabled, visible } = this.props; - - return ( - - ); - } - -} diff --git a/app/javascript/mastodon/components/load_more.tsx b/app/javascript/mastodon/components/load_more.tsx new file mode 100644 index 0000000000..8b5746ad30 --- /dev/null +++ b/app/javascript/mastodon/components/load_more.tsx @@ -0,0 +1,24 @@ +import { FormattedMessage } from 'react-intl'; + +interface Props { + onClick: (event: React.MouseEvent) => void; + disabled?: boolean; + visible?: boolean; +} +export const LoadMore: React.FC = ({ + onClick, + disabled, + visible = true, +}) => { + return ( + + ); +}; diff --git a/app/javascript/mastodon/components/scrollable_list.jsx b/app/javascript/mastodon/components/scrollable_list.jsx index 9a0c4c8a7e..53a84ecb53 100644 --- a/app/javascript/mastodon/components/scrollable_list.jsx +++ b/app/javascript/mastodon/components/scrollable_list.jsx @@ -15,7 +15,7 @@ import IntersectionObserverArticleContainer from '../containers/intersection_obs import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from '../features/ui/util/fullscreen'; import IntersectionObserverWrapper from '../features/ui/util/intersection_observer_wrapper'; -import LoadMore from './load_more'; +import { LoadMore } from './load_more'; import LoadPending from './load_pending'; import LoadingIndicator from './loading_indicator'; diff --git a/app/javascript/mastodon/features/account_gallery/index.jsx b/app/javascript/mastodon/features/account_gallery/index.jsx index 27de4740ca..653a258667 100644 --- a/app/javascript/mastodon/features/account_gallery/index.jsx +++ b/app/javascript/mastodon/features/account_gallery/index.jsx @@ -9,7 +9,7 @@ import { connect } from 'react-redux'; import { lookupAccount, fetchAccount } from 'mastodon/actions/accounts'; import { openModal } from 'mastodon/actions/modal'; import ColumnBackButton from 'mastodon/components/column_back_button'; -import LoadMore from 'mastodon/components/load_more'; +import { LoadMore } from 'mastodon/components/load_more'; import LoadingIndicator from 'mastodon/components/loading_indicator'; import ScrollContainer from 'mastodon/containers/scroll_container'; import BundleColumnError from 'mastodon/features/ui/components/bundle_column_error'; diff --git a/app/javascript/mastodon/features/compose/components/search_results.jsx b/app/javascript/mastodon/features/compose/components/search_results.jsx index b329cae791..b11ac478a4 100644 --- a/app/javascript/mastodon/features/compose/components/search_results.jsx +++ b/app/javascript/mastodon/features/compose/components/search_results.jsx @@ -6,7 +6,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { Icon } from 'mastodon/components/icon'; -import LoadMore from 'mastodon/components/load_more'; +import { LoadMore } from 'mastodon/components/load_more'; import { ImmutableHashtag as Hashtag } from '../../../components/hashtag'; import AccountContainer from '../../../containers/account_container'; diff --git a/app/javascript/mastodon/features/directory/index.jsx b/app/javascript/mastodon/features/directory/index.jsx index d4854f1869..635b6f4113 100644 --- a/app/javascript/mastodon/features/directory/index.jsx +++ b/app/javascript/mastodon/features/directory/index.jsx @@ -13,7 +13,7 @@ import { addColumn, removeColumn, moveColumn, changeColumnParams } from 'mastodo import { fetchDirectory, expandDirectory } from 'mastodon/actions/directory'; import Column from 'mastodon/components/column'; import ColumnHeader from 'mastodon/components/column_header'; -import LoadMore from 'mastodon/components/load_more'; +import { LoadMore } from 'mastodon/components/load_more'; import LoadingIndicator from 'mastodon/components/loading_indicator'; import { RadioButton } from 'mastodon/components/radio_button'; import ScrollContainer from 'mastodon/containers/scroll_container'; diff --git a/app/javascript/mastodon/features/explore/results.jsx b/app/javascript/mastodon/features/explore/results.jsx index 6b053a9dc1..dc1f720220 100644 --- a/app/javascript/mastodon/features/explore/results.jsx +++ b/app/javascript/mastodon/features/explore/results.jsx @@ -11,7 +11,7 @@ import { connect } from 'react-redux'; import { expandSearch } from 'mastodon/actions/search'; import { ImmutableHashtag as Hashtag } from 'mastodon/components/hashtag'; -import LoadMore from 'mastodon/components/load_more'; +import { LoadMore } from 'mastodon/components/load_more'; import LoadingIndicator from 'mastodon/components/loading_indicator'; import Account from 'mastodon/containers/account_container'; import Status from 'mastodon/containers/status_container'; From b22bfae4f93d635dc9416d45ad11b29d9f5104e5 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 6 Jun 2023 07:34:04 -0400 Subject: [PATCH 06/17] Add coverage for `DomainBlock#public_domain` method (#25283) --- spec/models/domain_block_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/models/domain_block_spec.rb b/spec/models/domain_block_spec.rb index f10f470279..e123c03d66 100644 --- a/spec/models/domain_block_spec.rb +++ b/spec/models/domain_block_spec.rb @@ -91,4 +91,22 @@ RSpec.describe DomainBlock do expect(newer.stricter_than?(older)).to be false end end + + describe '#public_domain' do + context 'with a domain block that is obfuscated' do + let(:domain_block) { Fabricate(:domain_block, domain: 'hostname.example.com', obfuscate: true) } + + it 'garbles the domain' do + expect(domain_block.public_domain).to eq 'hostna**.******e.com' + end + end + + context 'with a domain block that is not obfuscated' do + let(:domain_block) { Fabricate(:domain_block, domain: 'example.com', obfuscate: false) } + + it 'returns the domain value' do + expect(domain_block.public_domain).to eq 'example.com' + end + end + end end From eb6f8181e12ad0d7c47ae7c71ca6b737c844e35c Mon Sep 17 00:00:00 2001 From: Daniel M Brasil Date: Tue, 6 Jun 2023 08:37:09 -0300 Subject: [PATCH 07/17] Add test coverage for `Mastodon::CLI::Accounts#reset_relationships` (#25194) --- spec/lib/mastodon/cli/accounts_spec.rb | 113 +++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/spec/lib/mastodon/cli/accounts_spec.rb b/spec/lib/mastodon/cli/accounts_spec.rb index cf1d612f3d..a263d673de 100644 --- a/spec/lib/mastodon/cli/accounts_spec.rb +++ b/spec/lib/mastodon/cli/accounts_spec.rb @@ -1248,4 +1248,117 @@ describe Mastodon::CLI::Accounts do end end end + + describe '#reset_relationships' do + let(:target_account) { Fabricate(:account) } + let(:arguments) { [target_account.username] } + + context 'when no option is given' do + it 'exits with an error message indicating that at least one option is required' do + expect { cli.invoke(:reset_relationships, arguments) }.to output( + a_string_including('Please specify either --follows or --followers, or both') + ).to_stdout + .and raise_error(SystemExit) + end + end + + context 'when the given username is not found' do + let(:arguments) { ['non_existent_username'] } + + it 'exits with an error message indicating that there is no such account' do + expect { cli.invoke(:reset_relationships, arguments, follows: true) }.to output( + a_string_including('No such account') + ).to_stdout + .and raise_error(SystemExit) + end + end + + context 'when the given username is found' do + let(:total_relationships) { 10 } + let!(:accounts) { Fabricate.times(total_relationships, :account) } + + context 'with --follows option' do + let(:options) { { follows: true } } + + before do + accounts.each { |account| target_account.follow!(account) } + end + + it 'resets all "following" relationships from the target account' do + cli.invoke(:reset_relationships, arguments, options) + + expect(target_account.reload.following).to be_empty + end + + it 'calls BootstrapTimelineWorker once to rebuild the timeline' do + allow(BootstrapTimelineWorker).to receive(:perform_async) + + cli.invoke(:reset_relationships, arguments, options) + + expect(BootstrapTimelineWorker).to have_received(:perform_async).with(target_account.id).once + end + + it 'displays a successful message' do + expect { cli.invoke(:reset_relationships, arguments, options) }.to output( + a_string_including("Processed #{total_relationships} relationships") + ).to_stdout + end + end + + context 'with --followers option' do + let(:options) { { followers: true } } + + before do + accounts.each { |account| account.follow!(target_account) } + end + + it 'resets all "followers" relationships from the target account' do + cli.invoke(:reset_relationships, arguments, options) + + expect(target_account.reload.followers).to be_empty + end + + it 'displays a successful message' do + expect { cli.invoke(:reset_relationships, arguments, options) }.to output( + a_string_including("Processed #{total_relationships} relationships") + ).to_stdout + end + end + + context 'with --follows and --followers options' do + let(:options) { { followers: true, follows: true } } + + before do + accounts.first(6).each { |account| account.follow!(target_account) } + accounts.last(4).each { |account| target_account.follow!(account) } + end + + it 'resets all "followers" relationships from the target account' do + cli.invoke(:reset_relationships, arguments, options) + + expect(target_account.reload.followers).to be_empty + end + + it 'resets all "following" relationships from the target account' do + cli.invoke(:reset_relationships, arguments, options) + + expect(target_account.reload.following).to be_empty + end + + it 'calls BootstrapTimelineWorker once to rebuild the timeline' do + allow(BootstrapTimelineWorker).to receive(:perform_async) + + cli.invoke(:reset_relationships, arguments, options) + + expect(BootstrapTimelineWorker).to have_received(:perform_async).with(target_account.id).once + end + + it 'displays a successful message' do + expect { cli.invoke(:reset_relationships, arguments, options) }.to output( + a_string_including("Processed #{total_relationships} relationships") + ).to_stdout + end + end + end + end end From 1e243e2df7ff9dfaf753e86e8f93760a96ffda18 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 6 Jun 2023 07:57:00 -0400 Subject: [PATCH 08/17] Misc spec coverage for `Admin::` area controllers (#25282) --- .../admin/account_actions_controller_spec.rb | 12 ++ .../admin/accounts_controller_spec.rb | 124 ++++++++++++++++++ .../admin/announcements_controller_spec.rb | 26 ++++ .../admin/relays_controller_spec.rb | 41 ++++++ .../admin/statuses_controller_spec.rb | 10 ++ .../admin/warning_presets_controller_spec.rb | 64 +++++++++ 6 files changed, 277 insertions(+) diff --git a/spec/controllers/admin/account_actions_controller_spec.rb b/spec/controllers/admin/account_actions_controller_spec.rb index 4eae51c7b5..b8dae79939 100644 --- a/spec/controllers/admin/account_actions_controller_spec.rb +++ b/spec/controllers/admin/account_actions_controller_spec.rb @@ -20,4 +20,16 @@ describe Admin::AccountActionsController do expect(response).to have_http_status(:success) end end + + describe 'POST #create' do + let(:account) { Fabricate(:account) } + + it 'records the account action' do + expect do + post :create, params: { account_id: account.id, admin_account_action: { type: 'silence' } } + end.to change { account.strikes.count }.by(1) + + expect(response).to redirect_to(admin_account_path(account.id)) + end + end end diff --git a/spec/controllers/admin/accounts_controller_spec.rb b/spec/controllers/admin/accounts_controller_spec.rb index 7d001c4cbc..782e460a42 100644 --- a/spec/controllers/admin/accounts_controller_spec.rb +++ b/spec/controllers/admin/accounts_controller_spec.rb @@ -309,4 +309,128 @@ RSpec.describe Admin::AccountsController do end end end + + describe 'POST #unsensitive' do + subject { post :unsensitive, params: { id: account.id } } + + let(:current_user) { Fabricate(:user, role: role) } + let(:account) { Fabricate(:account, sensitized_at: 1.year.ago) } + + context 'when user is admin' do + let(:role) { UserRole.find_by(name: 'Admin') } + + it 'marks accounts not sensitized' do + subject + + expect(account.reload).to_not be_sensitized + expect(response).to redirect_to admin_account_path(account.id) + end + end + + context 'when user is not admin' do + let(:role) { UserRole.everyone } + + it 'fails to change account' do + subject + + expect(response).to have_http_status 403 + end + end + end + + describe 'POST #unsilence' do + subject { post :unsilence, params: { id: account.id } } + + let(:current_user) { Fabricate(:user, role: role) } + let(:account) { Fabricate(:account, silenced_at: 1.year.ago) } + + context 'when user is admin' do + let(:role) { UserRole.find_by(name: 'Admin') } + + it 'marks accounts not silenced' do + subject + + expect(account.reload).to_not be_silenced + expect(response).to redirect_to admin_account_path(account.id) + end + end + + context 'when user is not admin' do + let(:role) { UserRole.everyone } + + it 'fails to change account' do + subject + + expect(response).to have_http_status 403 + end + end + end + + describe 'POST #unsuspend' do + subject { post :unsuspend, params: { id: account.id } } + + let(:current_user) { Fabricate(:user, role: role) } + let(:account) { Fabricate(:account) } + + before do + account.suspend! + end + + context 'when user is admin' do + let(:role) { UserRole.find_by(name: 'Admin') } + + it 'marks accounts not suspended' do + subject + + expect(account.reload).to_not be_suspended + expect(response).to redirect_to admin_account_path(account.id) + end + end + + context 'when user is not admin' do + let(:role) { UserRole.everyone } + + it 'fails to change account' do + subject + + expect(response).to have_http_status 403 + end + end + end + + describe 'POST #destroy' do + subject { post :destroy, params: { id: account.id } } + + let(:current_user) { Fabricate(:user, role: role) } + let(:account) { Fabricate(:account) } + + before do + account.suspend! + end + + context 'when user is admin' do + let(:role) { UserRole.find_by(name: 'Admin') } + + before do + allow(Admin::AccountDeletionWorker).to receive(:perform_async).with(account.id) + end + + it 'destroys the account' do + subject + + expect(Admin::AccountDeletionWorker).to have_received(:perform_async).with(account.id) + expect(response).to redirect_to admin_account_path(account.id) + end + end + + context 'when user is not admin' do + let(:role) { UserRole.everyone } + + it 'fails to change account' do + subject + + expect(response).to have_http_status 403 + end + end + end end diff --git a/spec/controllers/admin/announcements_controller_spec.rb b/spec/controllers/admin/announcements_controller_spec.rb index a8905160f5..c2d3135d92 100644 --- a/spec/controllers/admin/announcements_controller_spec.rb +++ b/spec/controllers/admin/announcements_controller_spec.rb @@ -73,4 +73,30 @@ describe Admin::AnnouncementsController do expect(flash.notice).to match(I18n.t('admin.announcements.destroyed_msg')) end end + + describe 'POST #publish' do + subject { post :publish, params: { id: announcement.id } } + + let(:announcement) { Fabricate(:announcement, published_at: nil) } + + it 'marks announcement published' do + subject + + expect(announcement.reload).to be_published + expect(response).to redirect_to admin_announcements_path + end + end + + describe 'POST #unpublish' do + subject { post :unpublish, params: { id: announcement.id } } + + let(:announcement) { Fabricate(:announcement, published_at: 4.days.ago) } + + it 'marks announcement as not published' do + subject + + expect(announcement.reload).to_not be_published + expect(response).to redirect_to admin_announcements_path + end + end end diff --git a/spec/controllers/admin/relays_controller_spec.rb b/spec/controllers/admin/relays_controller_spec.rb index 261f302c05..ca351c39b2 100644 --- a/spec/controllers/admin/relays_controller_spec.rb +++ b/spec/controllers/admin/relays_controller_spec.rb @@ -56,4 +56,45 @@ describe Admin::RelaysController do end end end + + describe 'DELETE #destroy' do + let(:relay) { Fabricate(:relay) } + + it 'deletes an existing relay' do + delete :destroy, params: { id: relay.id } + + expect { relay.reload }.to raise_error(ActiveRecord::RecordNotFound) + expect(response).to redirect_to(admin_relays_path) + end + end + + describe 'POST #enable' do + let(:relay) { Fabricate(:relay, state: :idle) } + + before do + stub_request(:post, /example.com/).to_return(status: 200) + end + + it 'updates a relay from idle to pending' do + post :enable, params: { id: relay.id } + + expect(relay.reload).to be_pending + expect(response).to redirect_to(admin_relays_path) + end + end + + describe 'POST #disable' do + let(:relay) { Fabricate(:relay, state: :pending) } + + before do + stub_request(:post, /example.com/).to_return(status: 200) + end + + it 'updates a relay from pending to idle' do + post :disable, params: { id: relay.id } + + expect(relay.reload).to be_idle + expect(response).to redirect_to(admin_relays_path) + end + end end diff --git a/spec/controllers/admin/statuses_controller_spec.rb b/spec/controllers/admin/statuses_controller_spec.rb index 872aed9998..fc27f71473 100644 --- a/spec/controllers/admin/statuses_controller_spec.rb +++ b/spec/controllers/admin/statuses_controller_spec.rb @@ -41,6 +41,16 @@ describe Admin::StatusesController do end end + describe 'GET #show' do + before do + get :show, params: { account_id: account.id, id: status.id } + end + + it 'returns http success' do + expect(response).to have_http_status(200) + end + end + describe 'POST #batch' do before do post :batch, params: { :account_id => account.id, action => '', :admin_status_batch_action => { status_ids: status_ids } } diff --git a/spec/controllers/admin/warning_presets_controller_spec.rb b/spec/controllers/admin/warning_presets_controller_spec.rb index 6b48fc28bb..b32a58e990 100644 --- a/spec/controllers/admin/warning_presets_controller_spec.rb +++ b/spec/controllers/admin/warning_presets_controller_spec.rb @@ -18,4 +18,68 @@ describe Admin::WarningPresetsController do expect(response).to have_http_status(:success) end end + + describe 'GET #edit' do + let(:account_warning_preset) { Fabricate(:account_warning_preset) } + + it 'returns http success and renders edit' do + get :edit, params: { id: account_warning_preset.id } + + expect(response).to have_http_status(:success) + expect(response).to render_template(:edit) + end + end + + describe 'POST #create' do + context 'with valid data' do + it 'creates a new account_warning_preset and redirects' do + expect do + post :create, params: { account_warning_preset: { text: 'The account_warning_preset text.' } } + end.to change(AccountWarningPreset, :count).by(1) + + expect(response).to redirect_to(admin_warning_presets_path) + end + end + + context 'with invalid data' do + it 'does creates a new account_warning_preset and renders index' do + expect do + post :create, params: { account_warning_preset: { text: '' } } + end.to_not change(AccountWarningPreset, :count) + + expect(response).to render_template(:index) + end + end + end + + describe 'PUT #update' do + let(:account_warning_preset) { Fabricate(:account_warning_preset, text: 'Original text') } + + context 'with valid data' do + it 'updates the account_warning_preset and redirects' do + put :update, params: { id: account_warning_preset.id, account_warning_preset: { text: 'Updated text.' } } + + expect(response).to redirect_to(admin_warning_presets_path) + end + end + + context 'with invalid data' do + it 'does not update the account_warning_preset and renders index' do + put :update, params: { id: account_warning_preset.id, account_warning_preset: { text: '' } } + + expect(response).to render_template(:edit) + end + end + end + + describe 'DELETE #destroy' do + let!(:account_warning_preset) { Fabricate(:account_warning_preset) } + + it 'destroys the account_warning_preset and redirects' do + delete :destroy, params: { id: account_warning_preset.id } + + expect { account_warning_preset.reload }.to raise_error(ActiveRecord::RecordNotFound) + expect(response).to redirect_to(admin_warning_presets_path) + end + end end From c42591356da45c52f215ea00cf5c0ecd753afe06 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 6 Jun 2023 07:58:33 -0400 Subject: [PATCH 09/17] Fix `RSpec/DescribedClass` cop (#25104) --- .rubocop_todo.yml | 73 --------- spec/controllers/.rubocop.yml | 6 + spec/lib/entity_cache_spec.rb | 2 +- spec/lib/extractor_spec.rb | 20 +-- spec/lib/feed_manager_spec.rb | 140 +++++++++--------- spec/lib/ostatus/tag_manager_spec.rb | 16 +- spec/lib/request_spec.rb | 2 +- spec/lib/tag_manager_spec.rb | 22 +-- spec/lib/webfinger_resource_spec.rb | 28 ++-- spec/mailers/notification_mailer_spec.rb | 10 +- spec/mailers/user_mailer_spec.rb | 20 +-- spec/models/account_conversation_spec.rb | 16 +- spec/models/account_domain_block_spec.rb | 4 +- spec/models/account_migration_spec.rb | 2 +- spec/models/account_spec.rb | 90 +++++------ spec/models/block_spec.rb | 4 +- spec/models/domain_block_spec.rb | 36 ++--- spec/models/email_domain_block_spec.rb | 6 +- spec/models/export_spec.rb | 14 +- spec/models/favourite_spec.rb | 8 +- spec/models/follow_spec.rb | 8 +- spec/models/identity_spec.rb | 2 +- spec/models/import_spec.rb | 6 +- spec/models/media_attachment_spec.rb | 20 +-- spec/models/notification_spec.rb | 8 +- spec/models/relationship_filter_spec.rb | 2 +- spec/models/report_filter_spec.rb | 6 +- spec/models/session_activation_spec.rb | 2 +- spec/models/setting_spec.rb | 2 +- spec/models/site_upload_spec.rb | 2 +- spec/models/status_pin_spec.rb | 18 +-- spec/models/status_spec.rb | 54 +++---- spec/models/user_spec.rb | 32 ++-- .../account_moderation_note_policy_spec.rb | 4 +- .../account_relationships_presenter_spec.rb | 2 +- .../status_relationships_presenter_spec.rb | 2 +- .../activitypub/note_serializer_spec.rb | 2 +- .../update_poll_serializer_spec.rb | 2 +- .../rest/account_serializer_spec.rb | 2 +- .../fetch_remote_account_service_spec.rb | 2 +- .../fetch_remote_actor_service_spec.rb | 2 +- .../fetch_remote_key_service_spec.rb | 2 +- ..._block_domain_from_account_service_spec.rb | 2 +- .../services/authorize_follow_service_spec.rb | 2 +- .../batched_remove_status_service_spec.rb | 2 +- spec/services/block_domain_service_spec.rb | 2 +- spec/services/block_service_spec.rb | 2 +- .../bootstrap_timeline_service_spec.rb | 2 +- .../clear_domain_media_service_spec.rb | 2 +- spec/services/favourite_service_spec.rb | 2 +- spec/services/follow_service_spec.rb | 2 +- spec/services/import_service_spec.rb | 12 +- spec/services/post_status_service_spec.rb | 2 +- spec/services/precompute_feed_service_spec.rb | 2 +- .../services/process_mentions_service_spec.rb | 2 +- spec/services/purge_domain_service_spec.rb | 2 +- spec/services/reblog_service_spec.rb | 4 +- spec/services/reject_follow_service_spec.rb | 2 +- .../remove_from_followers_service_spec.rb | 2 +- spec/services/remove_status_service_spec.rb | 2 +- spec/services/unallow_domain_service_spec.rb | 2 +- spec/services/unblock_service_spec.rb | 2 +- spec/services/unfollow_service_spec.rb | 2 +- spec/services/unmute_service_spec.rb | 2 +- spec/services/update_account_service_spec.rb | 2 +- spec/validators/note_length_validator_spec.rb | 2 +- 66 files changed, 347 insertions(+), 414 deletions(-) create mode 100644 spec/controllers/.rubocop.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c8b287f90d..1a16472bdb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -237,79 +237,6 @@ RSpec/AnyInstance: - 'spec/workers/activitypub/delivery_worker_spec.rb' - 'spec/workers/web/push_notification_worker_spec.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: SkipBlocks, EnforcedStyle. -# SupportedStyles: described_class, explicit -RSpec/DescribedClass: - Exclude: - - 'spec/controllers/concerns/cache_concern_spec.rb' - - 'spec/controllers/concerns/challengable_concern_spec.rb' - - 'spec/lib/entity_cache_spec.rb' - - 'spec/lib/extractor_spec.rb' - - 'spec/lib/feed_manager_spec.rb' - - 'spec/lib/hash_object_spec.rb' - - 'spec/lib/ostatus/tag_manager_spec.rb' - - 'spec/lib/request_spec.rb' - - 'spec/lib/tag_manager_spec.rb' - - 'spec/lib/webfinger_resource_spec.rb' - - 'spec/mailers/notification_mailer_spec.rb' - - 'spec/mailers/user_mailer_spec.rb' - - 'spec/models/account_conversation_spec.rb' - - 'spec/models/account_domain_block_spec.rb' - - 'spec/models/account_migration_spec.rb' - - 'spec/models/account_spec.rb' - - 'spec/models/block_spec.rb' - - 'spec/models/domain_block_spec.rb' - - 'spec/models/email_domain_block_spec.rb' - - 'spec/models/export_spec.rb' - - 'spec/models/favourite_spec.rb' - - 'spec/models/follow_spec.rb' - - 'spec/models/identity_spec.rb' - - 'spec/models/import_spec.rb' - - 'spec/models/media_attachment_spec.rb' - - 'spec/models/notification_spec.rb' - - 'spec/models/relationship_filter_spec.rb' - - 'spec/models/report_filter_spec.rb' - - 'spec/models/session_activation_spec.rb' - - 'spec/models/setting_spec.rb' - - 'spec/models/site_upload_spec.rb' - - 'spec/models/status_pin_spec.rb' - - 'spec/models/status_spec.rb' - - 'spec/models/user_spec.rb' - - 'spec/policies/account_moderation_note_policy_spec.rb' - - 'spec/presenters/account_relationships_presenter_spec.rb' - - 'spec/presenters/status_relationships_presenter_spec.rb' - - 'spec/serializers/activitypub/note_serializer_spec.rb' - - 'spec/serializers/activitypub/update_poll_serializer_spec.rb' - - 'spec/serializers/rest/account_serializer_spec.rb' - - 'spec/services/activitypub/fetch_remote_account_service_spec.rb' - - 'spec/services/activitypub/fetch_remote_actor_service_spec.rb' - - 'spec/services/activitypub/fetch_remote_key_service_spec.rb' - - 'spec/services/after_block_domain_from_account_service_spec.rb' - - 'spec/services/authorize_follow_service_spec.rb' - - 'spec/services/batched_remove_status_service_spec.rb' - - 'spec/services/block_domain_service_spec.rb' - - 'spec/services/block_service_spec.rb' - - 'spec/services/bootstrap_timeline_service_spec.rb' - - 'spec/services/clear_domain_media_service_spec.rb' - - 'spec/services/favourite_service_spec.rb' - - 'spec/services/follow_service_spec.rb' - - 'spec/services/import_service_spec.rb' - - 'spec/services/post_status_service_spec.rb' - - 'spec/services/precompute_feed_service_spec.rb' - - 'spec/services/process_mentions_service_spec.rb' - - 'spec/services/purge_domain_service_spec.rb' - - 'spec/services/reblog_service_spec.rb' - - 'spec/services/reject_follow_service_spec.rb' - - 'spec/services/remove_from_followers_service_spec.rb' - - 'spec/services/remove_status_service_spec.rb' - - 'spec/services/unallow_domain_service_spec.rb' - - 'spec/services/unblock_service_spec.rb' - - 'spec/services/unfollow_service_spec.rb' - - 'spec/services/unmute_service_spec.rb' - - 'spec/services/update_account_service_spec.rb' - - 'spec/validators/note_length_validator_spec.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). RSpec/EmptyExampleGroup: Exclude: diff --git a/spec/controllers/.rubocop.yml b/spec/controllers/.rubocop.yml new file mode 100644 index 0000000000..525479be81 --- /dev/null +++ b/spec/controllers/.rubocop.yml @@ -0,0 +1,6 @@ +inherit_from: ../../.rubocop.yml + +# Anonymous controllers in specs cannot access described_class +# https://github.com/rubocop/rubocop-rspec/blob/master/lib/rubocop/cop/rspec/described_class.rb#L36-L39 +RSpec/DescribedClass: + SkipBlocks: true diff --git a/spec/lib/entity_cache_spec.rb b/spec/lib/entity_cache_spec.rb index 6d9afa4740..5818de7119 100644 --- a/spec/lib/entity_cache_spec.rb +++ b/spec/lib/entity_cache_spec.rb @@ -7,7 +7,7 @@ RSpec.describe EntityCache do let(:remote_account) { Fabricate(:account, domain: 'remote.test', username: 'bob', url: 'https://remote.test/') } describe '#emoji' do - subject { EntityCache.instance.emoji(shortcodes, domain) } + subject { described_class.instance.emoji(shortcodes, domain) } context 'when called with an empty list of shortcodes' do let(:shortcodes) { [] } diff --git a/spec/lib/extractor_spec.rb b/spec/lib/extractor_spec.rb index 560617ed7d..b6c910171d 100644 --- a/spec/lib/extractor_spec.rb +++ b/spec/lib/extractor_spec.rb @@ -6,19 +6,19 @@ describe Extractor do describe 'extract_mentions_or_lists_with_indices' do it 'returns an empty array if the given string does not have at signs' do text = 'a string without at signs' - extracted = Extractor.extract_mentions_or_lists_with_indices(text) + extracted = described_class.extract_mentions_or_lists_with_indices(text) expect(extracted).to eq [] end it 'does not extract mentions which ends with particular characters' do text = '@screen_name@' - extracted = Extractor.extract_mentions_or_lists_with_indices(text) + extracted = described_class.extract_mentions_or_lists_with_indices(text) expect(extracted).to eq [] end it 'returns mentions as an array' do text = '@screen_name' - extracted = Extractor.extract_mentions_or_lists_with_indices(text) + extracted = described_class.extract_mentions_or_lists_with_indices(text) expect(extracted).to eq [ { screen_name: 'screen_name', indices: [0, 12] }, ] @@ -26,7 +26,7 @@ describe Extractor do it 'yields mentions if a block is given' do text = '@screen_name' - Extractor.extract_mentions_or_lists_with_indices(text) do |screen_name, start_position, end_position| + described_class.extract_mentions_or_lists_with_indices(text) do |screen_name, start_position, end_position| expect(screen_name).to eq 'screen_name' expect(start_position).to eq 0 expect(end_position).to eq 12 @@ -37,31 +37,31 @@ describe Extractor do describe 'extract_hashtags_with_indices' do it 'returns an empty array if it does not have #' do text = 'a string without hash sign' - extracted = Extractor.extract_hashtags_with_indices(text) + extracted = described_class.extract_hashtags_with_indices(text) expect(extracted).to eq [] end it 'does not exclude normal hash text before ://' do text = '#hashtag://' - extracted = Extractor.extract_hashtags_with_indices(text) + extracted = described_class.extract_hashtags_with_indices(text) expect(extracted).to eq [{ hashtag: 'hashtag', indices: [0, 8] }] end it 'excludes http://' do text = '#hashtaghttp://' - extracted = Extractor.extract_hashtags_with_indices(text) + extracted = described_class.extract_hashtags_with_indices(text) expect(extracted).to eq [{ hashtag: 'hashtag', indices: [0, 8] }] end it 'excludes https://' do text = '#hashtaghttps://' - extracted = Extractor.extract_hashtags_with_indices(text) + extracted = described_class.extract_hashtags_with_indices(text) expect(extracted).to eq [{ hashtag: 'hashtag', indices: [0, 8] }] end it 'yields hashtags if a block is given' do text = '#hashtag' - Extractor.extract_hashtags_with_indices(text) do |hashtag, start_position, end_position| + described_class.extract_hashtags_with_indices(text) do |hashtag, start_position, end_position| expect(hashtag).to eq 'hashtag' expect(start_position).to eq 0 expect(end_position).to eq 8 @@ -72,7 +72,7 @@ describe Extractor do describe 'extract_cashtags_with_indices' do it 'returns []' do text = '$cashtag' - extracted = Extractor.extract_cashtags_with_indices(text) + extracted = described_class.extract_cashtags_with_indices(text) expect(extracted).to eq [] end end diff --git a/spec/lib/feed_manager_spec.rb b/spec/lib/feed_manager_spec.rb index 31b53fd879..5bfe11f6aa 100644 --- a/spec/lib/feed_manager_spec.rb +++ b/spec/lib/feed_manager_spec.rb @@ -15,7 +15,7 @@ RSpec.describe FeedManager do end describe '#key' do - subject { FeedManager.instance.key(:home, 1) } + subject { described_class.instance.key(:home, 1) } it 'returns a string' do expect(subject).to be_a String @@ -32,26 +32,26 @@ RSpec.describe FeedManager do it 'returns false for followee\'s status' do status = Fabricate(:status, text: 'Hello world', account: alice) bob.follow!(alice) - expect(FeedManager.instance.filter?(:home, status, bob)).to be false + expect(described_class.instance.filter?(:home, status, bob)).to be false end it 'returns false for reblog by followee' do status = Fabricate(:status, text: 'Hello world', account: jeff) reblog = Fabricate(:status, reblog: status, account: alice) bob.follow!(alice) - expect(FeedManager.instance.filter?(:home, reblog, bob)).to be false + expect(described_class.instance.filter?(:home, reblog, bob)).to be false end it 'returns true for post from account who blocked me' do status = Fabricate(:status, text: 'Hello, World', account: alice) alice.block!(bob) - expect(FeedManager.instance.filter?(:home, status, bob)).to be true + expect(described_class.instance.filter?(:home, status, bob)).to be true end it 'returns true for post from blocked account' do status = Fabricate(:status, text: 'Hello, World', account: alice) bob.block!(alice) - expect(FeedManager.instance.filter?(:home, status, bob)).to be true + expect(described_class.instance.filter?(:home, status, bob)).to be true end it 'returns true for reblog by followee of blocked account' do @@ -59,7 +59,7 @@ RSpec.describe FeedManager do reblog = Fabricate(:status, reblog: status, account: alice) bob.follow!(alice) bob.block!(jeff) - expect(FeedManager.instance.filter?(:home, reblog, bob)).to be true + expect(described_class.instance.filter?(:home, reblog, bob)).to be true end it 'returns true for reblog by followee of muted account' do @@ -67,7 +67,7 @@ RSpec.describe FeedManager do reblog = Fabricate(:status, reblog: status, account: alice) bob.follow!(alice) bob.mute!(jeff) - expect(FeedManager.instance.filter?(:home, reblog, bob)).to be true + expect(described_class.instance.filter?(:home, reblog, bob)).to be true end it 'returns true for reblog by followee of someone who is blocking recipient' do @@ -75,14 +75,14 @@ RSpec.describe FeedManager do reblog = Fabricate(:status, reblog: status, account: alice) bob.follow!(alice) jeff.block!(bob) - expect(FeedManager.instance.filter?(:home, reblog, bob)).to be true + expect(described_class.instance.filter?(:home, reblog, bob)).to be true end it 'returns true for reblog from account with reblogs disabled' do status = Fabricate(:status, text: 'Hello world', account: jeff) reblog = Fabricate(:status, reblog: status, account: alice) bob.follow!(alice, reblogs: false) - expect(FeedManager.instance.filter?(:home, reblog, bob)).to be true + expect(described_class.instance.filter?(:home, reblog, bob)).to be true end it 'returns false for reply by followee to another followee' do @@ -90,49 +90,49 @@ RSpec.describe FeedManager do reply = Fabricate(:status, text: 'Nay', thread: status, account: alice) bob.follow!(alice) bob.follow!(jeff) - expect(FeedManager.instance.filter?(:home, reply, bob)).to be false + expect(described_class.instance.filter?(:home, reply, bob)).to be false end it 'returns false for reply by followee to recipient' do status = Fabricate(:status, text: 'Hello world', account: bob) reply = Fabricate(:status, text: 'Nay', thread: status, account: alice) bob.follow!(alice) - expect(FeedManager.instance.filter?(:home, reply, bob)).to be false + expect(described_class.instance.filter?(:home, reply, bob)).to be false end it 'returns false for reply by followee to self' do status = Fabricate(:status, text: 'Hello world', account: alice) reply = Fabricate(:status, text: 'Nay', thread: status, account: alice) bob.follow!(alice) - expect(FeedManager.instance.filter?(:home, reply, bob)).to be false + expect(described_class.instance.filter?(:home, reply, bob)).to be false end it 'returns true for reply by followee to non-followed account' do status = Fabricate(:status, text: 'Hello world', account: jeff) reply = Fabricate(:status, text: 'Nay', thread: status, account: alice) bob.follow!(alice) - expect(FeedManager.instance.filter?(:home, reply, bob)).to be true + expect(described_class.instance.filter?(:home, reply, bob)).to be true end it 'returns true for the second reply by followee to a non-federated status' do reply = Fabricate(:status, text: 'Reply 1', reply: true, account: alice) second_reply = Fabricate(:status, text: 'Reply 2', thread: reply, account: alice) bob.follow!(alice) - expect(FeedManager.instance.filter?(:home, second_reply, bob)).to be true + expect(described_class.instance.filter?(:home, second_reply, bob)).to be true end it 'returns false for status by followee mentioning another account' do bob.follow!(alice) jeff.follow!(alice) status = PostStatusService.new.call(alice, text: 'Hey @jeff') - expect(FeedManager.instance.filter?(:home, status, bob)).to be false + expect(described_class.instance.filter?(:home, status, bob)).to be false end it 'returns true for status by followee mentioning blocked account' do bob.block!(jeff) bob.follow!(alice) status = PostStatusService.new.call(alice, text: 'Hey @jeff') - expect(FeedManager.instance.filter?(:home, status, bob)).to be true + expect(described_class.instance.filter?(:home, status, bob)).to be true end it 'returns true for reblog of a personally blocked domain' do @@ -140,19 +140,19 @@ RSpec.describe FeedManager do alice.follow!(jeff) status = Fabricate(:status, text: 'Hello world', account: bob) reblog = Fabricate(:status, reblog: status, account: jeff) - expect(FeedManager.instance.filter?(:home, reblog, alice)).to be true + expect(described_class.instance.filter?(:home, reblog, alice)).to be true end it 'returns true for German post when follow is set to English only' do alice.follow!(bob, languages: %w(en)) status = Fabricate(:status, text: 'Hallo Welt', account: bob, language: 'de') - expect(FeedManager.instance.filter?(:home, status, alice)).to be true + expect(described_class.instance.filter?(:home, status, alice)).to be true end it 'returns false for German post when follow is set to German' do alice.follow!(bob, languages: %w(de)) status = Fabricate(:status, text: 'Hallo Welt', account: bob, language: 'de') - expect(FeedManager.instance.filter?(:home, status, alice)).to be false + expect(described_class.instance.filter?(:home, status, alice)).to be false end it 'returns true for post from followee on exclusive list' do @@ -196,27 +196,27 @@ RSpec.describe FeedManager do it 'returns true for status that mentions blocked account' do bob.block!(jeff) status = PostStatusService.new.call(alice, text: 'Hey @jeff') - expect(FeedManager.instance.filter?(:mentions, status, bob)).to be true + expect(described_class.instance.filter?(:mentions, status, bob)).to be true end it 'returns true for status that replies to a blocked account' do status = Fabricate(:status, text: 'Hello world', account: jeff) reply = Fabricate(:status, text: 'Nay', thread: status, account: alice) bob.block!(jeff) - expect(FeedManager.instance.filter?(:mentions, reply, bob)).to be true + expect(described_class.instance.filter?(:mentions, reply, bob)).to be true end it 'returns true for status by silenced account who recipient is not following' do status = Fabricate(:status, text: 'Hello world', account: alice) alice.silence! - expect(FeedManager.instance.filter?(:mentions, status, bob)).to be true + expect(described_class.instance.filter?(:mentions, status, bob)).to be true end it 'returns false for status by followed silenced account' do status = Fabricate(:status, text: 'Hello world', account: alice) alice.silence! bob.follow!(alice) - expect(FeedManager.instance.filter?(:mentions, status, bob)).to be false + expect(described_class.instance.filter?(:mentions, status, bob)).to be false end end end @@ -228,7 +228,7 @@ RSpec.describe FeedManager do members = Array.new(FeedManager::MAX_ITEMS) { |count| [count, count] } redis.zadd("feed:home:#{account.id}", members) - FeedManager.instance.push_to_home(account, status) + described_class.instance.push_to_home(account, status) expect(redis.zcard("feed:home:#{account.id}")).to eq FeedManager::MAX_ITEMS end @@ -239,7 +239,7 @@ RSpec.describe FeedManager do reblogged = Fabricate(:status) reblog = Fabricate(:status, reblog: reblogged) - expect(FeedManager.instance.push_to_home(account, reblog)).to be true + expect(described_class.instance.push_to_home(account, reblog)).to be true end it 'does not save a new reblog of a recent status' do @@ -247,9 +247,9 @@ RSpec.describe FeedManager do reblogged = Fabricate(:status) reblog = Fabricate(:status, reblog: reblogged) - FeedManager.instance.push_to_home(account, reblogged) + described_class.instance.push_to_home(account, reblogged) - expect(FeedManager.instance.push_to_home(account, reblog)).to be false + expect(described_class.instance.push_to_home(account, reblog)).to be false end it 'saves a new reblog of an old status' do @@ -257,14 +257,14 @@ RSpec.describe FeedManager do reblogged = Fabricate(:status) reblog = Fabricate(:status, reblog: reblogged) - FeedManager.instance.push_to_home(account, reblogged) + described_class.instance.push_to_home(account, reblogged) # Fill the feed with intervening statuses FeedManager::REBLOG_FALLOFF.times do - FeedManager.instance.push_to_home(account, Fabricate(:status)) + described_class.instance.push_to_home(account, Fabricate(:status)) end - expect(FeedManager.instance.push_to_home(account, reblog)).to be true + expect(described_class.instance.push_to_home(account, reblog)).to be true end it 'does not save a new reblog of a recently-reblogged status' do @@ -273,10 +273,10 @@ RSpec.describe FeedManager do reblogs = Array.new(2) { Fabricate(:status, reblog: reblogged) } # The first reblog will be accepted - FeedManager.instance.push_to_home(account, reblogs.first) + described_class.instance.push_to_home(account, reblogs.first) # The second reblog should be ignored - expect(FeedManager.instance.push_to_home(account, reblogs.last)).to be false + expect(described_class.instance.push_to_home(account, reblogs.last)).to be false end it 'saves a new reblog of a recently-reblogged status when previous reblog has been deleted' do @@ -285,15 +285,15 @@ RSpec.describe FeedManager do old_reblog = Fabricate(:status, reblog: reblogged) # The first reblog should be accepted - expect(FeedManager.instance.push_to_home(account, old_reblog)).to be true + expect(described_class.instance.push_to_home(account, old_reblog)).to be true # The first reblog should be successfully removed - expect(FeedManager.instance.unpush_from_home(account, old_reblog)).to be true + expect(described_class.instance.unpush_from_home(account, old_reblog)).to be true reblog = Fabricate(:status, reblog: reblogged) # The second reblog should be accepted - expect(FeedManager.instance.push_to_home(account, reblog)).to be true + expect(described_class.instance.push_to_home(account, reblog)).to be true end it 'does not save a new reblog of a multiply-reblogged-then-unreblogged status' do @@ -302,14 +302,14 @@ RSpec.describe FeedManager do reblogs = Array.new(3) { Fabricate(:status, reblog: reblogged) } # Accept the reblogs - FeedManager.instance.push_to_home(account, reblogs[0]) - FeedManager.instance.push_to_home(account, reblogs[1]) + described_class.instance.push_to_home(account, reblogs[0]) + described_class.instance.push_to_home(account, reblogs[1]) # Unreblog the first one - FeedManager.instance.unpush_from_home(account, reblogs[0]) + described_class.instance.unpush_from_home(account, reblogs[0]) # The last reblog should still be ignored - expect(FeedManager.instance.push_to_home(account, reblogs.last)).to be false + expect(described_class.instance.push_to_home(account, reblogs.last)).to be false end it 'saves a new reblog of a long-ago-reblogged status' do @@ -318,15 +318,15 @@ RSpec.describe FeedManager do reblogs = Array.new(2) { Fabricate(:status, reblog: reblogged) } # The first reblog will be accepted - FeedManager.instance.push_to_home(account, reblogs.first) + described_class.instance.push_to_home(account, reblogs.first) # Fill the feed with intervening statuses FeedManager::REBLOG_FALLOFF.times do - FeedManager.instance.push_to_home(account, Fabricate(:status)) + described_class.instance.push_to_home(account, Fabricate(:status)) end # The second reblog should also be accepted - expect(FeedManager.instance.push_to_home(account, reblogs.last)).to be true + expect(described_class.instance.push_to_home(account, reblogs.last)).to be true end end @@ -334,9 +334,9 @@ RSpec.describe FeedManager do account = Fabricate(:account) reblog = Fabricate(:status) status = Fabricate(:status, reblog: reblog) - FeedManager.instance.push_to_home(account, status) + described_class.instance.push_to_home(account, status) - expect(FeedManager.instance.push_to_home(account, reblog)).to be false + expect(described_class.instance.push_to_home(account, reblog)).to be false end end @@ -359,9 +359,9 @@ RSpec.describe FeedManager do it "does not push when the given status's reblog is already inserted" do reblog = Fabricate(:status) status = Fabricate(:status, reblog: reblog) - FeedManager.instance.push_to_list(list, status) + described_class.instance.push_to_list(list, status) - expect(FeedManager.instance.push_to_list(list, reblog)).to be false + expect(described_class.instance.push_to_list(list, reblog)).to be false end context 'when replies policy is set to no replies' do @@ -371,19 +371,19 @@ RSpec.describe FeedManager do it 'pushes statuses that are not replies' do status = Fabricate(:status, text: 'Hello world', account: bob) - expect(FeedManager.instance.push_to_list(list, status)).to be true + expect(described_class.instance.push_to_list(list, status)).to be true end it 'pushes statuses that are replies to list owner' do status = Fabricate(:status, text: 'Hello world', account: owner) reply = Fabricate(:status, text: 'Nay', thread: status, account: bob) - expect(FeedManager.instance.push_to_list(list, reply)).to be true + expect(described_class.instance.push_to_list(list, reply)).to be true end it 'does not push replies to another member of the list' do status = Fabricate(:status, text: 'Hello world', account: alice) reply = Fabricate(:status, text: 'Nay', thread: status, account: bob) - expect(FeedManager.instance.push_to_list(list, reply)).to be false + expect(described_class.instance.push_to_list(list, reply)).to be false end end @@ -394,25 +394,25 @@ RSpec.describe FeedManager do it 'pushes statuses that are not replies' do status = Fabricate(:status, text: 'Hello world', account: bob) - expect(FeedManager.instance.push_to_list(list, status)).to be true + expect(described_class.instance.push_to_list(list, status)).to be true end it 'pushes statuses that are replies to list owner' do status = Fabricate(:status, text: 'Hello world', account: owner) reply = Fabricate(:status, text: 'Nay', thread: status, account: bob) - expect(FeedManager.instance.push_to_list(list, reply)).to be true + expect(described_class.instance.push_to_list(list, reply)).to be true end it 'pushes replies to another member of the list' do status = Fabricate(:status, text: 'Hello world', account: alice) reply = Fabricate(:status, text: 'Nay', thread: status, account: bob) - expect(FeedManager.instance.push_to_list(list, reply)).to be true + expect(described_class.instance.push_to_list(list, reply)).to be true end it 'does not push replies to someone not a member of the list' do status = Fabricate(:status, text: 'Hello world', account: eve) reply = Fabricate(:status, text: 'Nay', thread: status, account: bob) - expect(FeedManager.instance.push_to_list(list, reply)).to be false + expect(described_class.instance.push_to_list(list, reply)).to be false end end @@ -423,25 +423,25 @@ RSpec.describe FeedManager do it 'pushes statuses that are not replies' do status = Fabricate(:status, text: 'Hello world', account: bob) - expect(FeedManager.instance.push_to_list(list, status)).to be true + expect(described_class.instance.push_to_list(list, status)).to be true end it 'pushes statuses that are replies to list owner' do status = Fabricate(:status, text: 'Hello world', account: owner) reply = Fabricate(:status, text: 'Nay', thread: status, account: bob) - expect(FeedManager.instance.push_to_list(list, reply)).to be true + expect(described_class.instance.push_to_list(list, reply)).to be true end it 'pushes replies to another member of the list' do status = Fabricate(:status, text: 'Hello world', account: alice) reply = Fabricate(:status, text: 'Nay', thread: status, account: bob) - expect(FeedManager.instance.push_to_list(list, reply)).to be true + expect(described_class.instance.push_to_list(list, reply)).to be true end it 'pushes replies to someone not a member of the list' do status = Fabricate(:status, text: 'Hello world', account: eve) reply = Fabricate(:status, text: 'Nay', thread: status, account: bob) - expect(FeedManager.instance.push_to_list(list, reply)).to be true + expect(described_class.instance.push_to_list(list, reply)).to be true end end end @@ -451,9 +451,9 @@ RSpec.describe FeedManager do account = Fabricate(:account, id: 0) reblog = Fabricate(:status) status = Fabricate(:status, reblog: reblog) - FeedManager.instance.push_to_home(account, status) + described_class.instance.push_to_home(account, status) - FeedManager.instance.merge_into_home(account, reblog.account) + described_class.instance.merge_into_home(account, reblog.account) expect(redis.zscore('feed:home:0', reblog.id)).to be_nil end @@ -466,14 +466,14 @@ RSpec.describe FeedManager do reblogged = Fabricate(:status) status = Fabricate(:status, reblog: reblogged) - FeedManager.instance.push_to_home(receiver, reblogged) - FeedManager::REBLOG_FALLOFF.times { FeedManager.instance.push_to_home(receiver, Fabricate(:status)) } - FeedManager.instance.push_to_home(receiver, status) + described_class.instance.push_to_home(receiver, reblogged) + FeedManager::REBLOG_FALLOFF.times { described_class.instance.push_to_home(receiver, Fabricate(:status)) } + described_class.instance.push_to_home(receiver, status) # The reblogging status should show up under normal conditions. expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to include(status.id.to_s) - FeedManager.instance.unpush_from_home(receiver, status) + described_class.instance.unpush_from_home(receiver, status) # Restore original status expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to_not include(status.id.to_s) @@ -484,12 +484,12 @@ RSpec.describe FeedManager do reblogged = Fabricate(:status) status = Fabricate(:status, reblog: reblogged) - FeedManager.instance.push_to_home(receiver, status) + described_class.instance.push_to_home(receiver, status) # The reblogging status should show up under normal conditions. expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [status.id.to_s] - FeedManager.instance.unpush_from_home(receiver, status) + described_class.instance.unpush_from_home(receiver, status) expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to be_empty end @@ -499,14 +499,14 @@ RSpec.describe FeedManager do reblogs = Array.new(3) { Fabricate(:status, reblog: reblogged) } reblogs.each do |reblog| - FeedManager.instance.push_to_home(receiver, reblog) + described_class.instance.push_to_home(receiver, reblog) end # The reblogging status should show up under normal conditions. expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [reblogs.first.id.to_s] reblogs[0...-1].each do |reblog| - FeedManager.instance.unpush_from_home(receiver, reblog) + described_class.instance.unpush_from_home(receiver, reblog) end expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [reblogs.last.id.to_s] @@ -515,10 +515,10 @@ RSpec.describe FeedManager do it 'sends push updates' do status = Fabricate(:status) - FeedManager.instance.push_to_home(receiver, status) + described_class.instance.push_to_home(receiver, status) allow(redis).to receive_messages(publish: nil) - FeedManager.instance.unpush_from_home(receiver, status) + described_class.instance.unpush_from_home(receiver, status) deletion = Oj.dump(event: :delete, payload: status.id.to_s) expect(redis).to have_received(:publish).with("timeline:#{receiver.id}", deletion) @@ -544,7 +544,7 @@ RSpec.describe FeedManager do end it 'correctly cleans the home timeline' do - FeedManager.instance.clear_from_home(account, target_account) + described_class.instance.clear_from_home(account, target_account) expect(redis.zrange("feed:home:#{account.id}", 0, -1)).to eq [status_1.id.to_s, status_7.id.to_s] end diff --git a/spec/lib/ostatus/tag_manager_spec.rb b/spec/lib/ostatus/tag_manager_spec.rb index fb9740ce3f..0e20f26c7c 100644 --- a/spec/lib/ostatus/tag_manager_spec.rb +++ b/spec/lib/ostatus/tag_manager_spec.rb @@ -5,40 +5,40 @@ require 'rails_helper' describe OStatus::TagManager do describe '#unique_tag' do it 'returns a unique tag' do - expect(OStatus::TagManager.instance.unique_tag(Time.utc(2000), 12, 'Status')).to eq 'tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Status' + expect(described_class.instance.unique_tag(Time.utc(2000), 12, 'Status')).to eq 'tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Status' end end describe '#unique_tag_to_local_id' do it 'returns the ID part' do - expect(OStatus::TagManager.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Status', 'Status')).to eql '12' + expect(described_class.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Status', 'Status')).to eql '12' end it 'returns nil if it is not local id' do - expect(OStatus::TagManager.instance.unique_tag_to_local_id('tag:remote,2000-01-01:objectId=12:objectType=Status', 'Status')).to be_nil + expect(described_class.instance.unique_tag_to_local_id('tag:remote,2000-01-01:objectId=12:objectType=Status', 'Status')).to be_nil end it 'returns nil if it is not expected type' do - expect(OStatus::TagManager.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Block', 'Status')).to be_nil + expect(described_class.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Block', 'Status')).to be_nil end it 'returns nil if it does not have object ID' do - expect(OStatus::TagManager.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectType=Status', 'Status')).to be_nil + expect(described_class.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectType=Status', 'Status')).to be_nil end end describe '#local_id?' do it 'returns true for a local ID' do - expect(OStatus::TagManager.instance.local_id?('tag:cb6e6126.ngrok.io;objectId=12:objectType=Status')).to be true + expect(described_class.instance.local_id?('tag:cb6e6126.ngrok.io;objectId=12:objectType=Status')).to be true end it 'returns false for a foreign ID' do - expect(OStatus::TagManager.instance.local_id?('tag:foreign.tld;objectId=12:objectType=Status')).to be false + expect(described_class.instance.local_id?('tag:foreign.tld;objectId=12:objectType=Status')).to be false end end describe '#uri_for' do - subject { OStatus::TagManager.instance.uri_for(target) } + subject { described_class.instance.uri_for(target) } context 'with comment object' do let(:target) { Fabricate(:status, created_at: '2000-01-01T00:00:00Z', reply: true) } diff --git a/spec/lib/request_spec.rb b/spec/lib/request_spec.rb index 25fe9ed379..e88631e475 100644 --- a/spec/lib/request_spec.rb +++ b/spec/lib/request_spec.rb @@ -4,7 +4,7 @@ require 'rails_helper' require 'securerandom' describe Request do - subject { Request.new(:get, 'http://example.com') } + subject { described_class.new(:get, 'http://example.com') } describe '#headers' do it 'returns user agent' do diff --git a/spec/lib/tag_manager_spec.rb b/spec/lib/tag_manager_spec.rb index 8de2905414..38203a55f7 100644 --- a/spec/lib/tag_manager_spec.rb +++ b/spec/lib/tag_manager_spec.rb @@ -16,15 +16,15 @@ RSpec.describe TagManager do end it 'returns true for nil' do - expect(TagManager.instance.local_domain?(nil)).to be true + expect(described_class.instance.local_domain?(nil)).to be true end it 'returns true if the slash-stripped string equals to local domain' do - expect(TagManager.instance.local_domain?('DoMaIn.Example.com/')).to be true + expect(described_class.instance.local_domain?('DoMaIn.Example.com/')).to be true end it 'returns false for irrelevant string' do - expect(TagManager.instance.local_domain?('DoMaIn.Example.com!')).to be false + expect(described_class.instance.local_domain?('DoMaIn.Example.com!')).to be false end end @@ -41,25 +41,25 @@ RSpec.describe TagManager do end it 'returns true for nil' do - expect(TagManager.instance.web_domain?(nil)).to be true + expect(described_class.instance.web_domain?(nil)).to be true end it 'returns true if the slash-stripped string equals to web domain' do - expect(TagManager.instance.web_domain?('DoMaIn.Example.com/')).to be true + expect(described_class.instance.web_domain?('DoMaIn.Example.com/')).to be true end it 'returns false for string with irrelevant characters' do - expect(TagManager.instance.web_domain?('DoMaIn.Example.com!')).to be false + expect(described_class.instance.web_domain?('DoMaIn.Example.com!')).to be false end end describe '#normalize_domain' do it 'returns nil if the given parameter is nil' do - expect(TagManager.instance.normalize_domain(nil)).to be_nil + expect(described_class.instance.normalize_domain(nil)).to be_nil end it 'returns normalized domain' do - expect(TagManager.instance.normalize_domain('DoMaIn.Example.com/')).to eq 'domain.example.com' + expect(described_class.instance.normalize_domain('DoMaIn.Example.com/')).to eq 'domain.example.com' end end @@ -72,17 +72,17 @@ RSpec.describe TagManager do it 'returns true if the normalized string with port is local URL' do Rails.configuration.x.web_domain = 'domain.example.com:42' - expect(TagManager.instance.local_url?('https://DoMaIn.Example.com:42/')).to be true + expect(described_class.instance.local_url?('https://DoMaIn.Example.com:42/')).to be true end it 'returns true if the normalized string without port is local URL' do Rails.configuration.x.web_domain = 'domain.example.com' - expect(TagManager.instance.local_url?('https://DoMaIn.Example.com/')).to be true + expect(described_class.instance.local_url?('https://DoMaIn.Example.com/')).to be true end it 'returns false for string with irrelevant characters' do Rails.configuration.x.web_domain = 'domain.example.com' - expect(TagManager.instance.local_url?('https://domain.example.net/')).to be false + expect(described_class.instance.local_url?('https://domain.example.net/')).to be false end end end diff --git a/spec/lib/webfinger_resource_spec.rb b/spec/lib/webfinger_resource_spec.rb index 8ec6dd205e..2cad04fccd 100644 --- a/spec/lib/webfinger_resource_spec.rb +++ b/spec/lib/webfinger_resource_spec.rb @@ -17,7 +17,7 @@ describe WebfingerResource do resource = 'https://example.com/users/alice/other' expect do - WebfingerResource.new(resource).username + described_class.new(resource).username end.to raise_error(ActiveRecord::RecordNotFound) end @@ -32,7 +32,7 @@ describe WebfingerResource do expect(Rails.application.routes).to receive(:recognize_path).with(resource).and_return(recognized).at_least(:once) expect do - WebfingerResource.new(resource).username + described_class.new(resource).username end.to raise_error(ActiveRecord::RecordNotFound) end @@ -40,28 +40,28 @@ describe WebfingerResource do resource = 'website for http://example.com/users/alice/other' expect do - WebfingerResource.new(resource).username + described_class.new(resource).username end.to raise_error(WebfingerResource::InvalidRequest) end it 'finds the username in a valid https route' do resource = 'https://example.com/users/alice' - result = WebfingerResource.new(resource).username + result = described_class.new(resource).username expect(result).to eq 'alice' end it 'finds the username in a mixed case http route' do resource = 'HTTp://exAMPLe.com/users/alice' - result = WebfingerResource.new(resource).username + result = described_class.new(resource).username expect(result).to eq 'alice' end it 'finds the username in a valid http route' do resource = 'http://example.com/users/alice' - result = WebfingerResource.new(resource).username + result = described_class.new(resource).username expect(result).to eq 'alice' end end @@ -71,7 +71,7 @@ describe WebfingerResource do resource = 'user@remote-host.com' expect do - WebfingerResource.new(resource).username + described_class.new(resource).username end.to raise_error(ActiveRecord::RecordNotFound) end @@ -79,7 +79,7 @@ describe WebfingerResource do Rails.configuration.x.local_domain = 'example.com' resource = 'alice@example.com' - result = WebfingerResource.new(resource).username + result = described_class.new(resource).username expect(result).to eq 'alice' end @@ -87,7 +87,7 @@ describe WebfingerResource do Rails.configuration.x.web_domain = 'example.com' resource = 'alice@example.com' - result = WebfingerResource.new(resource).username + result = described_class.new(resource).username expect(result).to eq 'alice' end end @@ -97,7 +97,7 @@ describe WebfingerResource do resource = 'acct:user@remote-host.com' expect do - WebfingerResource.new(resource).username + described_class.new(resource).username end.to raise_error(ActiveRecord::RecordNotFound) end @@ -105,7 +105,7 @@ describe WebfingerResource do resource = 'acct:user@remote-host@remote-hostess.remote.local@remote' expect do - WebfingerResource.new(resource).username + described_class.new(resource).username end.to raise_error(ActiveRecord::RecordNotFound) end @@ -113,7 +113,7 @@ describe WebfingerResource do Rails.configuration.x.local_domain = 'example.com' resource = 'acct:alice@example.com' - result = WebfingerResource.new(resource).username + result = described_class.new(resource).username expect(result).to eq 'alice' end @@ -121,7 +121,7 @@ describe WebfingerResource do Rails.configuration.x.web_domain = 'example.com' resource = 'acct:alice@example.com' - result = WebfingerResource.new(resource).username + result = described_class.new(resource).username expect(result).to eq 'alice' end end @@ -131,7 +131,7 @@ describe WebfingerResource do resource = 'df/:dfkj' expect do - WebfingerResource.new(resource).username + described_class.new(resource).username end.to raise_error(WebfingerResource::InvalidRequest) end end diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index 73c751def1..bf364b6253 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -23,7 +23,7 @@ RSpec.describe NotificationMailer do describe 'mention' do let(:mention) { Mention.create!(account: receiver.account, status: foreign_status) } - let(:mail) { NotificationMailer.mention(receiver.account, Notification.create!(account: receiver.account, activity: mention)) } + let(:mail) { described_class.mention(receiver.account, Notification.create!(account: receiver.account, activity: mention)) } include_examples 'localized subject', 'notification_mailer.mention.subject', name: 'bob' @@ -40,7 +40,7 @@ RSpec.describe NotificationMailer do describe 'follow' do let(:follow) { sender.follow!(receiver.account) } - let(:mail) { NotificationMailer.follow(receiver.account, Notification.create!(account: receiver.account, activity: follow)) } + let(:mail) { described_class.follow(receiver.account, Notification.create!(account: receiver.account, activity: follow)) } include_examples 'localized subject', 'notification_mailer.follow.subject', name: 'bob' @@ -56,7 +56,7 @@ RSpec.describe NotificationMailer do describe 'favourite' do let(:favourite) { Favourite.create!(account: sender, status: own_status) } - let(:mail) { NotificationMailer.favourite(own_status.account, Notification.create!(account: receiver.account, activity: favourite)) } + let(:mail) { described_class.favourite(own_status.account, Notification.create!(account: receiver.account, activity: favourite)) } include_examples 'localized subject', 'notification_mailer.favourite.subject', name: 'bob' @@ -73,7 +73,7 @@ RSpec.describe NotificationMailer do describe 'reblog' do let(:reblog) { Status.create!(account: sender, reblog: own_status) } - let(:mail) { NotificationMailer.reblog(own_status.account, Notification.create!(account: receiver.account, activity: reblog)) } + let(:mail) { described_class.reblog(own_status.account, Notification.create!(account: receiver.account, activity: reblog)) } include_examples 'localized subject', 'notification_mailer.reblog.subject', name: 'bob' @@ -90,7 +90,7 @@ RSpec.describe NotificationMailer do describe 'follow_request' do let(:follow_request) { Fabricate(:follow_request, account: sender, target_account: receiver.account) } - let(:mail) { NotificationMailer.follow_request(receiver.account, Notification.create!(account: receiver.account, activity: follow_request)) } + let(:mail) { described_class.follow_request(receiver.account, Notification.create!(account: receiver.account, activity: follow_request)) } include_examples 'localized subject', 'notification_mailer.follow_request.subject', name: 'bob' diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb index a4f6c145ab..702aa1c354 100644 --- a/spec/mailers/user_mailer_spec.rb +++ b/spec/mailers/user_mailer_spec.rb @@ -19,7 +19,7 @@ describe UserMailer do end describe 'confirmation_instructions' do - let(:mail) { UserMailer.confirmation_instructions(receiver, 'spec') } + let(:mail) { described_class.confirmation_instructions(receiver, 'spec') } it 'renders confirmation instructions' do receiver.update!(locale: nil) @@ -34,7 +34,7 @@ describe UserMailer do end describe 'reconfirmation_instructions' do - let(:mail) { UserMailer.confirmation_instructions(receiver, 'spec') } + let(:mail) { described_class.confirmation_instructions(receiver, 'spec') } it 'renders reconfirmation instructions' do receiver.update!(email: 'new-email@example.com', locale: nil) @@ -48,7 +48,7 @@ describe UserMailer do end describe 'reset_password_instructions' do - let(:mail) { UserMailer.reset_password_instructions(receiver, 'spec') } + let(:mail) { described_class.reset_password_instructions(receiver, 'spec') } it 'renders reset password instructions' do receiver.update!(locale: nil) @@ -61,7 +61,7 @@ describe UserMailer do end describe 'password_change' do - let(:mail) { UserMailer.password_change(receiver) } + let(:mail) { described_class.password_change(receiver) } it 'renders password change notification' do receiver.update!(locale: nil) @@ -73,7 +73,7 @@ describe UserMailer do end describe 'email_changed' do - let(:mail) { UserMailer.email_changed(receiver) } + let(:mail) { described_class.email_changed(receiver) } it 'renders email change notification' do receiver.update!(locale: nil) @@ -86,7 +86,7 @@ describe UserMailer do describe 'warning' do let(:strike) { Fabricate(:account_warning, target_account: receiver.account, text: 'dont worry its just the testsuite', action: 'suspend') } - let(:mail) { UserMailer.warning(receiver, strike) } + let(:mail) { described_class.warning(receiver, strike) } it 'renders warning notification' do receiver.update!(locale: nil) @@ -97,7 +97,7 @@ describe UserMailer do describe 'webauthn_credential_deleted' do let(:credential) { Fabricate(:webauthn_credential, user_id: receiver.id) } - let(:mail) { UserMailer.webauthn_credential_deleted(receiver, credential) } + let(:mail) { described_class.webauthn_credential_deleted(receiver, credential) } it 'renders webauthn credential deleted notification' do receiver.update!(locale: nil) @@ -112,7 +112,7 @@ describe UserMailer do let(:ip) { '192.168.0.1' } let(:agent) { 'NCSA_Mosaic/2.0 (Windows 3.1)' } let(:timestamp) { Time.now.utc } - let(:mail) { UserMailer.suspicious_sign_in(receiver, ip, agent, timestamp) } + let(:mail) { described_class.suspicious_sign_in(receiver, ip, agent, timestamp) } it 'renders suspicious sign in notification' do receiver.update!(locale: nil) @@ -125,7 +125,7 @@ describe UserMailer do describe 'appeal_approved' do let(:appeal) { Fabricate(:appeal, account: receiver.account, approved_at: Time.now.utc) } - let(:mail) { UserMailer.appeal_approved(receiver, appeal) } + let(:mail) { described_class.appeal_approved(receiver, appeal) } it 'renders appeal_approved notification' do expect(mail.subject).to eq I18n.t('user_mailer.appeal_approved.subject', date: I18n.l(appeal.created_at)) @@ -135,7 +135,7 @@ describe UserMailer do describe 'appeal_rejected' do let(:appeal) { Fabricate(:appeal, account: receiver.account, rejected_at: Time.now.utc) } - let(:mail) { UserMailer.appeal_rejected(receiver, appeal) } + let(:mail) { described_class.appeal_rejected(receiver, appeal) } it 'renders appeal_rejected notification' do expect(mail.subject).to eq I18n.t('user_mailer.appeal_rejected.subject', date: I18n.l(appeal.created_at)) diff --git a/spec/models/account_conversation_spec.rb b/spec/models/account_conversation_spec.rb index a16aa500cf..4e8727ca39 100644 --- a/spec/models/account_conversation_spec.rb +++ b/spec/models/account_conversation_spec.rb @@ -12,7 +12,7 @@ RSpec.describe AccountConversation do status = Fabricate(:status, account: alice, visibility: :direct) status.mentions.create(account: bob) - conversation = AccountConversation.add_status(alice, status) + conversation = described_class.add_status(alice, status) expect(conversation.participant_accounts).to include(bob) expect(conversation.last_status).to eq status @@ -21,12 +21,12 @@ RSpec.describe AccountConversation do it 'appends to old record when there is a match' do last_status = Fabricate(:status, account: alice, visibility: :direct) - conversation = AccountConversation.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [last_status.id]) + conversation = described_class.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [last_status.id]) status = Fabricate(:status, account: bob, visibility: :direct, thread: last_status) status.mentions.create(account: alice) - new_conversation = AccountConversation.add_status(alice, status) + new_conversation = described_class.add_status(alice, status) expect(new_conversation.id).to eq conversation.id expect(new_conversation.participant_accounts).to include(bob) @@ -36,13 +36,13 @@ RSpec.describe AccountConversation do it 'creates new record when new participants are added' do last_status = Fabricate(:status, account: alice, visibility: :direct) - conversation = AccountConversation.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [last_status.id]) + conversation = described_class.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [last_status.id]) status = Fabricate(:status, account: bob, visibility: :direct, thread: last_status) status.mentions.create(account: alice) status.mentions.create(account: mark) - new_conversation = AccountConversation.add_status(alice, status) + new_conversation = described_class.add_status(alice, status) expect(new_conversation.id).to_not eq conversation.id expect(new_conversation.participant_accounts).to include(bob, mark) @@ -55,7 +55,7 @@ RSpec.describe AccountConversation do it 'updates last status to a previous value' do last_status = Fabricate(:status, account: alice, visibility: :direct) status = Fabricate(:status, account: alice, visibility: :direct) - conversation = AccountConversation.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [status.id, last_status.id]) + conversation = described_class.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [status.id, last_status.id]) last_status.mentions.create(account: bob) last_status.destroy! conversation.reload @@ -65,10 +65,10 @@ RSpec.describe AccountConversation do it 'removes the record if no other statuses are referenced' do last_status = Fabricate(:status, account: alice, visibility: :direct) - conversation = AccountConversation.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [last_status.id]) + conversation = described_class.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [last_status.id]) last_status.mentions.create(account: bob) last_status.destroy! - expect(AccountConversation.where(id: conversation.id).count).to eq 0 + expect(described_class.where(id: conversation.id).count).to eq 0 end end end diff --git a/spec/models/account_domain_block_spec.rb b/spec/models/account_domain_block_spec.rb index f3246d04c5..10bd579363 100644 --- a/spec/models/account_domain_block_spec.rb +++ b/spec/models/account_domain_block_spec.rb @@ -7,14 +7,14 @@ RSpec.describe AccountDomainBlock do account = Fabricate(:account) Rails.cache.write("exclude_domains_for:#{account.id}", 'a.domain.already.blocked') - AccountDomainBlock.create!(account: account, domain: 'a.domain.blocked.later') + described_class.create!(account: account, domain: 'a.domain.blocked.later') expect(Rails.cache.exist?("exclude_domains_for:#{account.id}")).to be false end it 'removes blocking cache after destruction' do account = Fabricate(:account) - block = AccountDomainBlock.create!(account: account, domain: 'domain') + block = described_class.create!(account: account, domain: 'domain') Rails.cache.write("exclude_domains_for:#{account.id}", 'domain') block.destroy! diff --git a/spec/models/account_migration_spec.rb b/spec/models/account_migration_spec.rb index 519b9a97a5..d76edddd51 100644 --- a/spec/models/account_migration_spec.rb +++ b/spec/models/account_migration_spec.rb @@ -7,7 +7,7 @@ RSpec.describe AccountMigration do let(:source_account) { Fabricate(:account) } let(:target_acct) { target_account.acct } - let(:subject) { AccountMigration.new(account: source_account, acct: target_acct) } + let(:subject) { described_class.new(account: source_account, acct: target_acct) } context 'with valid properties' do let(:target_account) { Fabricate(:account, username: 'target', domain: 'remote.org') } diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 6e9c608ab0..d966bffa9b 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -362,7 +362,7 @@ RSpec.describe Account do suspended: true ) - results = Account.search_for('username') + results = described_class.search_for('username') expect(results).to eq [] end @@ -375,7 +375,7 @@ RSpec.describe Account do match.user.update(approved: false) - results = Account.search_for('username') + results = described_class.search_for('username') expect(results).to eq [] end @@ -388,7 +388,7 @@ RSpec.describe Account do match.user.update(confirmed_at: nil) - results = Account.search_for('username') + results = described_class.search_for('username') expect(results).to eq [] end @@ -400,7 +400,7 @@ RSpec.describe Account do domain: 'example.com' ) - results = Account.search_for('A?l\i:c e') + results = described_class.search_for('A?l\i:c e') expect(results).to eq [match] end @@ -412,7 +412,7 @@ RSpec.describe Account do domain: 'example.com' ) - results = Account.search_for('display') + results = described_class.search_for('display') expect(results).to eq [match] end @@ -424,7 +424,7 @@ RSpec.describe Account do domain: 'example.com' ) - results = Account.search_for('username') + results = described_class.search_for('username') expect(results).to eq [match] end @@ -436,19 +436,19 @@ RSpec.describe Account do domain: 'example.com' ) - results = Account.search_for('example') + results = described_class.search_for('example') expect(results).to eq [match] end it 'limits by 10 by default' do 11.times.each { Fabricate(:account, display_name: 'Display Name') } - results = Account.search_for('display') + results = described_class.search_for('display') expect(results.size).to eq 10 end it 'accepts arbitrary limits' do 2.times.each { Fabricate(:account, display_name: 'Display Name') } - results = Account.search_for('display', limit: 1) + results = described_class.search_for('display', limit: 1) expect(results.size).to eq 1 end @@ -458,7 +458,7 @@ RSpec.describe Account do { display_name: 'Display Name', username: 'username', domain: 'example.com' }, ].map(&method(:Fabricate).curry(2).call(:account)) - results = Account.search_for('username') + results = described_class.search_for('username') expect(results).to eq matches end end @@ -476,7 +476,7 @@ RSpec.describe Account do ) account.follow!(match) - results = Account.advanced_search_for('A?l\i:c e', account, limit: 10, following: true) + results = described_class.advanced_search_for('A?l\i:c e', account, limit: 10, following: true) expect(results).to eq [match] end @@ -488,7 +488,7 @@ RSpec.describe Account do domain: 'example.com' ) - results = Account.advanced_search_for('A?l\i:c e', account, limit: 10, following: true) + results = described_class.advanced_search_for('A?l\i:c e', account, limit: 10, following: true) expect(results).to eq [] end @@ -501,7 +501,7 @@ RSpec.describe Account do suspended: true ) - results = Account.advanced_search_for('username', account, limit: 10, following: true) + results = described_class.advanced_search_for('username', account, limit: 10, following: true) expect(results).to eq [] end @@ -514,7 +514,7 @@ RSpec.describe Account do match.user.update(approved: false) - results = Account.advanced_search_for('username', account, limit: 10, following: true) + results = described_class.advanced_search_for('username', account, limit: 10, following: true) expect(results).to eq [] end @@ -527,7 +527,7 @@ RSpec.describe Account do match.user.update(confirmed_at: nil) - results = Account.advanced_search_for('username', account, limit: 10, following: true) + results = described_class.advanced_search_for('username', account, limit: 10, following: true) expect(results).to eq [] end end @@ -541,7 +541,7 @@ RSpec.describe Account do suspended: true ) - results = Account.advanced_search_for('username', account) + results = described_class.advanced_search_for('username', account) expect(results).to eq [] end @@ -554,7 +554,7 @@ RSpec.describe Account do match.user.update(approved: false) - results = Account.advanced_search_for('username', account) + results = described_class.advanced_search_for('username', account) expect(results).to eq [] end @@ -567,7 +567,7 @@ RSpec.describe Account do match.user.update(confirmed_at: nil) - results = Account.advanced_search_for('username', account) + results = described_class.advanced_search_for('username', account) expect(results).to eq [] end @@ -579,19 +579,19 @@ RSpec.describe Account do domain: 'example.com' ) - results = Account.advanced_search_for('A?l\i:c e', account) + results = described_class.advanced_search_for('A?l\i:c e', account) expect(results).to eq [match] end it 'limits by 10 by default' do 11.times { Fabricate(:account, display_name: 'Display Name') } - results = Account.advanced_search_for('display', account) + results = described_class.advanced_search_for('display', account) expect(results.size).to eq 10 end it 'accepts arbitrary limits' do 2.times { Fabricate(:account, display_name: 'Display Name') } - results = Account.advanced_search_for('display', account, limit: 1) + results = described_class.advanced_search_for('display', account, limit: 1) expect(results.size).to eq 1 end @@ -600,7 +600,7 @@ RSpec.describe Account do followed_match = Fabricate(:account, username: 'Matcher') Fabricate(:follow, account: account, target_account: followed_match) - results = Account.advanced_search_for('match', account) + results = described_class.advanced_search_for('match', account) expect(results).to eq [followed_match, match] expect(results.first.rank).to be > results.last.rank end @@ -639,31 +639,31 @@ RSpec.describe Account do describe '.following_map' do it 'returns an hash' do - expect(Account.following_map([], 1)).to be_a Hash + expect(described_class.following_map([], 1)).to be_a Hash end end describe '.followed_by_map' do it 'returns an hash' do - expect(Account.followed_by_map([], 1)).to be_a Hash + expect(described_class.followed_by_map([], 1)).to be_a Hash end end describe '.blocking_map' do it 'returns an hash' do - expect(Account.blocking_map([], 1)).to be_a Hash + expect(described_class.blocking_map([], 1)).to be_a Hash end end describe '.requested_map' do it 'returns an hash' do - expect(Account.requested_map([], 1)).to be_a Hash + expect(described_class.requested_map([], 1)).to be_a Hash end end describe '.requested_by_map' do it 'returns an hash' do - expect(Account.requested_by_map([], 1)).to be_a Hash + expect(described_class.requested_by_map([], 1)).to be_a Hash end end @@ -834,7 +834,7 @@ RSpec.describe Account do { username: 'b', domain: 'b' }, ].map(&method(:Fabricate).curry(2).call(:account)) - expect(Account.where('id > 0').alphabetic).to eq matches + expect(described_class.where('id > 0').alphabetic).to eq matches end end @@ -843,7 +843,7 @@ RSpec.describe Account do match = Fabricate(:account, display_name: 'pattern and suffix') Fabricate(:account, display_name: 'prefix and pattern') - expect(Account.matches_display_name('pattern')).to eq [match] + expect(described_class.matches_display_name('pattern')).to eq [match] end end @@ -852,24 +852,24 @@ RSpec.describe Account do match = Fabricate(:account, username: 'pattern_and_suffix') Fabricate(:account, username: 'prefix_and_pattern') - expect(Account.matches_username('pattern')).to eq [match] + expect(described_class.matches_username('pattern')).to eq [match] end end describe 'by_domain_and_subdomains' do it 'returns exact domain matches' do account = Fabricate(:account, domain: 'example.com') - expect(Account.by_domain_and_subdomains('example.com')).to eq [account] + expect(described_class.by_domain_and_subdomains('example.com')).to eq [account] end it 'returns subdomains' do account = Fabricate(:account, domain: 'foo.example.com') - expect(Account.by_domain_and_subdomains('example.com')).to eq [account] + expect(described_class.by_domain_and_subdomains('example.com')).to eq [account] end it 'does not return partially matching domains' do account = Fabricate(:account, domain: 'grexample.com') - expect(Account.by_domain_and_subdomains('example.com')).to_not eq [account] + expect(described_class.by_domain_and_subdomains('example.com')).to_not eq [account] end end @@ -877,7 +877,7 @@ RSpec.describe Account do it 'returns an array of accounts who have a domain' do account_1 = Fabricate(:account, domain: nil) account_2 = Fabricate(:account, domain: 'example.com') - expect(Account.remote).to contain_exactly(account_2) + expect(described_class.remote).to contain_exactly(account_2) end end @@ -885,7 +885,7 @@ RSpec.describe Account do it 'returns an array of accounts who do not have a domain' do account_1 = Fabricate(:account, domain: nil) account_2 = Fabricate(:account, domain: 'example.com') - expect(Account.where('id > 0').local).to contain_exactly(account_1) + expect(described_class.where('id > 0').local).to contain_exactly(account_1) end end @@ -896,14 +896,14 @@ RSpec.describe Account do matches[index] = Fabricate(:account, domain: matches[index]) end - expect(Account.where('id > 0').partitioned).to match_array(matches) + expect(described_class.where('id > 0').partitioned).to match_array(matches) end end describe 'recent' do it 'returns a relation of accounts sorted by recent creation' do matches = Array.new(2) { Fabricate(:account) } - expect(Account.where('id > 0').recent).to match_array(matches) + expect(described_class.where('id > 0').recent).to match_array(matches) end end @@ -911,7 +911,7 @@ RSpec.describe Account do it 'returns an array of accounts who are silenced' do account_1 = Fabricate(:account, silenced: true) account_2 = Fabricate(:account, silenced: false) - expect(Account.silenced).to contain_exactly(account_1) + expect(described_class.silenced).to contain_exactly(account_1) end end @@ -919,7 +919,7 @@ RSpec.describe Account do it 'returns an array of accounts who are suspended' do account_1 = Fabricate(:account, suspended: true) account_2 = Fabricate(:account, suspended: false) - expect(Account.suspended).to contain_exactly(account_1) + expect(described_class.suspended).to contain_exactly(account_1) end end @@ -941,18 +941,18 @@ RSpec.describe Account do end it 'returns every usable non-suspended account' do - expect(Account.searchable).to contain_exactly(silenced_local, silenced_remote, local_account, remote_account) + expect(described_class.searchable).to contain_exactly(silenced_local, silenced_remote, local_account, remote_account) end it 'does not mess with previously-applied scopes' do - expect(Account.where.not(id: remote_account.id).searchable).to contain_exactly(silenced_local, silenced_remote, local_account) + expect(described_class.where.not(id: remote_account.id).searchable).to contain_exactly(silenced_local, silenced_remote, local_account) end end end context 'when is local' do it 'generates keys' do - account = Account.create!(domain: nil, username: Faker::Internet.user_name(separators: ['_'])) + account = described_class.create!(domain: nil, username: Faker::Internet.user_name(separators: ['_'])) expect(account.keypair).to be_private expect(account.keypair).to be_public end @@ -961,12 +961,12 @@ RSpec.describe Account do context 'when is remote' do it 'does not generate keys' do key = OpenSSL::PKey::RSA.new(1024).public_key - account = Account.create!(domain: 'remote', username: Faker::Internet.user_name(separators: ['_']), public_key: key.to_pem) + account = described_class.create!(domain: 'remote', username: Faker::Internet.user_name(separators: ['_']), public_key: key.to_pem) expect(account.keypair.params).to eq key.params end it 'normalizes domain' do - account = Account.create!(domain: 'にゃん', username: Faker::Internet.user_name(separators: ['_'])) + account = described_class.create!(domain: 'にゃん', username: Faker::Internet.user_name(separators: ['_'])) expect(account.domain).to eq 'xn--r9j5b5b' end end @@ -986,7 +986,7 @@ RSpec.describe Account do threads = Array.new(increment_by) do Thread.new do true while wait_for_start - Account.find(subject.id).increment_count!(:followers_count) + described_class.find(subject.id).increment_count!(:followers_count) end end diff --git a/spec/models/block_spec.rb b/spec/models/block_spec.rb index de3410fd58..8249503c59 100644 --- a/spec/models/block_spec.rb +++ b/spec/models/block_spec.rb @@ -23,7 +23,7 @@ RSpec.describe Block do Rails.cache.write("exclude_account_ids_for:#{account.id}", []) Rails.cache.write("exclude_account_ids_for:#{target_account.id}", []) - Block.create!(account: account, target_account: target_account) + described_class.create!(account: account, target_account: target_account) expect(Rails.cache.exist?("exclude_account_ids_for:#{account.id}")).to be false expect(Rails.cache.exist?("exclude_account_ids_for:#{target_account.id}")).to be false @@ -32,7 +32,7 @@ RSpec.describe Block do it 'removes blocking cache after destruction' do account = Fabricate(:account) target_account = Fabricate(:account) - block = Block.create!(account: account, target_account: target_account) + block = described_class.create!(account: account, target_account: target_account) Rails.cache.write("exclude_account_ids_for:#{account.id}", [target_account.id]) Rails.cache.write("exclude_account_ids_for:#{target_account.id}", [account.id]) diff --git a/spec/models/domain_block_spec.rb b/spec/models/domain_block_spec.rb index e123c03d66..67f53fa785 100644 --- a/spec/models/domain_block_spec.rb +++ b/spec/models/domain_block_spec.rb @@ -21,73 +21,73 @@ RSpec.describe DomainBlock do describe '.blocked?' do it 'returns true if the domain is suspended' do Fabricate(:domain_block, domain: 'example.com', severity: :suspend) - expect(DomainBlock.blocked?('example.com')).to be true + expect(described_class.blocked?('example.com')).to be true end it 'returns false even if the domain is silenced' do Fabricate(:domain_block, domain: 'example.com', severity: :silence) - expect(DomainBlock.blocked?('example.com')).to be false + expect(described_class.blocked?('example.com')).to be false end it 'returns false if the domain is not suspended nor silenced' do - expect(DomainBlock.blocked?('example.com')).to be false + expect(described_class.blocked?('example.com')).to be false end end describe '.rule_for' do it 'returns rule matching a blocked domain' do block = Fabricate(:domain_block, domain: 'example.com') - expect(DomainBlock.rule_for('example.com')).to eq block + expect(described_class.rule_for('example.com')).to eq block end it 'returns a rule matching a subdomain of a blocked domain' do block = Fabricate(:domain_block, domain: 'example.com') - expect(DomainBlock.rule_for('sub.example.com')).to eq block + expect(described_class.rule_for('sub.example.com')).to eq block end it 'returns a rule matching a blocked subdomain' do block = Fabricate(:domain_block, domain: 'sub.example.com') - expect(DomainBlock.rule_for('sub.example.com')).to eq block + expect(described_class.rule_for('sub.example.com')).to eq block end it 'returns a rule matching a blocked TLD' do block = Fabricate(:domain_block, domain: 'google') - expect(DomainBlock.rule_for('google')).to eq block + expect(described_class.rule_for('google')).to eq block end it 'returns a rule matching a subdomain of a blocked TLD' do block = Fabricate(:domain_block, domain: 'google') - expect(DomainBlock.rule_for('maps.google')).to eq block + expect(described_class.rule_for('maps.google')).to eq block end end describe '#stricter_than?' do it 'returns true if the new block has suspend severity while the old has lower severity' do - suspend = DomainBlock.new(domain: 'domain', severity: :suspend) - silence = DomainBlock.new(domain: 'domain', severity: :silence) - noop = DomainBlock.new(domain: 'domain', severity: :noop) + suspend = described_class.new(domain: 'domain', severity: :suspend) + silence = described_class.new(domain: 'domain', severity: :silence) + noop = described_class.new(domain: 'domain', severity: :noop) expect(suspend.stricter_than?(silence)).to be true expect(suspend.stricter_than?(noop)).to be true end it 'returns false if the new block has lower severity than the old one' do - suspend = DomainBlock.new(domain: 'domain', severity: :suspend) - silence = DomainBlock.new(domain: 'domain', severity: :silence) - noop = DomainBlock.new(domain: 'domain', severity: :noop) + suspend = described_class.new(domain: 'domain', severity: :suspend) + silence = described_class.new(domain: 'domain', severity: :silence) + noop = described_class.new(domain: 'domain', severity: :noop) expect(silence.stricter_than?(suspend)).to be false expect(noop.stricter_than?(suspend)).to be false expect(noop.stricter_than?(silence)).to be false end it 'returns false if the new block does is less strict regarding reports' do - older = DomainBlock.new(domain: 'domain', severity: :silence, reject_reports: true) - newer = DomainBlock.new(domain: 'domain', severity: :silence, reject_reports: false) + older = described_class.new(domain: 'domain', severity: :silence, reject_reports: true) + newer = described_class.new(domain: 'domain', severity: :silence, reject_reports: false) expect(newer.stricter_than?(older)).to be false end it 'returns false if the new block does is less strict regarding media' do - older = DomainBlock.new(domain: 'domain', severity: :silence, reject_media: true) - newer = DomainBlock.new(domain: 'domain', severity: :silence, reject_media: false) + older = described_class.new(domain: 'domain', severity: :silence, reject_media: true) + newer = described_class.new(domain: 'domain', severity: :silence, reject_media: false) expect(newer.stricter_than?(older)).to be false end end diff --git a/spec/models/email_domain_block_spec.rb b/spec/models/email_domain_block_spec.rb index a7232eb6b4..9d9c748877 100644 --- a/spec/models/email_domain_block_spec.rb +++ b/spec/models/email_domain_block_spec.rb @@ -14,12 +14,12 @@ RSpec.describe EmailDomainBlock do it 'returns true if the domain is blocked' do Fabricate(:email_domain_block, domain: 'example.com') - expect(EmailDomainBlock.block?(input)).to be true + expect(described_class.block?(input)).to be true end it 'returns false if the domain is not blocked' do Fabricate(:email_domain_block, domain: 'other-example.com') - expect(EmailDomainBlock.block?(input)).to be false + expect(described_class.block?(input)).to be false end end @@ -38,7 +38,7 @@ RSpec.describe EmailDomainBlock do it 'returns true if the domain is blocked' do Fabricate(:email_domain_block, domain: 'mail.foo.com') - expect(EmailDomainBlock.block?(input)).to be true + expect(described_class.block?(input)).to be true end end end diff --git a/spec/models/export_spec.rb b/spec/models/export_spec.rb index a863678a33..75468898d2 100644 --- a/spec/models/export_spec.rb +++ b/spec/models/export_spec.rb @@ -12,7 +12,7 @@ describe Export do it 'returns a csv of the blocked accounts' do target_accounts.each { |target_account| account.block!(target_account) } - export = Export.new(account).to_blocked_accounts_csv + export = described_class.new(account).to_blocked_accounts_csv results = export.strip.split expect(results.size).to eq 2 @@ -22,7 +22,7 @@ describe Export do it 'returns a csv of the muted accounts' do target_accounts.each { |target_account| account.mute!(target_account) } - export = Export.new(account).to_muted_accounts_csv + export = described_class.new(account).to_muted_accounts_csv results = export.strip.split("\n") expect(results.size).to eq 3 @@ -33,7 +33,7 @@ describe Export do it 'returns a csv of the following accounts' do target_accounts.each { |target_account| account.follow!(target_account) } - export = Export.new(account).to_following_accounts_csv + export = described_class.new(account).to_following_accounts_csv results = export.strip.split("\n") expect(results.size).to eq 3 @@ -45,24 +45,24 @@ describe Export do describe 'total_storage' do it 'returns the total size of the media attachments' do media_attachment = Fabricate(:media_attachment, account: account) - expect(Export.new(account).total_storage).to eq media_attachment.file_file_size || 0 + expect(described_class.new(account).total_storage).to eq media_attachment.file_file_size || 0 end end describe 'total_follows' do it 'returns the total number of the followed accounts' do target_accounts.each { |target_account| account.follow!(target_account) } - expect(Export.new(account.reload).total_follows).to eq 2 + expect(described_class.new(account.reload).total_follows).to eq 2 end it 'returns the total number of the blocked accounts' do target_accounts.each { |target_account| account.block!(target_account) } - expect(Export.new(account.reload).total_blocks).to eq 2 + expect(described_class.new(account.reload).total_blocks).to eq 2 end it 'returns the total number of the muted accounts' do target_accounts.each { |target_account| account.mute!(target_account) } - expect(Export.new(account.reload).total_mutes).to eq 2 + expect(described_class.new(account.reload).total_mutes).to eq 2 end end end diff --git a/spec/models/favourite_spec.rb b/spec/models/favourite_spec.rb index 9e69570a01..ef7fbdefcd 100644 --- a/spec/models/favourite_spec.rb +++ b/spec/models/favourite_spec.rb @@ -10,12 +10,12 @@ RSpec.describe Favourite do let(:status) { Fabricate(:status, reblog: reblog) } it 'invalidates if the reblogged status is already a favourite' do - Favourite.create!(account: account, status: reblog) - expect(Favourite.new(account: account, status: status).valid?).to be false + described_class.create!(account: account, status: reblog) + expect(described_class.new(account: account, status: status).valid?).to be false end it 'replaces status with the reblogged one if it is a reblog' do - favourite = Favourite.create!(account: account, status: status) + favourite = described_class.create!(account: account, status: status) expect(favourite.status).to eq reblog end end @@ -24,7 +24,7 @@ RSpec.describe Favourite do let(:status) { Fabricate(:status, reblog: nil) } it 'saves with the specified status' do - favourite = Favourite.create!(account: account, status: status) + favourite = described_class.create!(account: account, status: status) expect(favourite.status).to eq status end end diff --git a/spec/models/follow_spec.rb b/spec/models/follow_spec.rb index 79c0048f9f..c7743183cc 100644 --- a/spec/models/follow_spec.rb +++ b/spec/models/follow_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Follow do let(:bob) { Fabricate(:account, username: 'bob') } describe 'validations' do - subject { Follow.new(account: alice, target_account: bob, rate_limit: true) } + subject { described_class.new(account: alice, target_account: bob, rate_limit: true) } it 'is invalid without an account' do follow = Fabricate.build(:follow, account: nil) @@ -38,10 +38,10 @@ RSpec.describe Follow do describe 'recent' do it 'sorts so that more recent follows comes earlier' do - follow0 = Follow.create!(account: alice, target_account: bob) - follow1 = Follow.create!(account: bob, target_account: alice) + follow0 = described_class.create!(account: alice, target_account: bob) + follow1 = described_class.create!(account: bob, target_account: alice) - a = Follow.recent.to_a + a = described_class.recent.to_a expect(a.size).to eq 2 expect(a[0]).to eq follow1 diff --git a/spec/models/identity_spec.rb b/spec/models/identity_spec.rb index 59155781c7..2fca1e1c14 100644 --- a/spec/models/identity_spec.rb +++ b/spec/models/identity_spec.rb @@ -12,7 +12,7 @@ RSpec.describe Identity do end it 'returns an instance of Identity' do - expect(described_class.find_for_oauth(auth)).to be_instance_of Identity + expect(described_class.find_for_oauth(auth)).to be_instance_of described_class end end end diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 1dae40a739..3605f0b9bf 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -9,17 +9,17 @@ RSpec.describe Import do describe 'validations' do it 'has a valid parameters' do - import = Import.create(account: account, type: type, data: data) + import = described_class.create(account: account, type: type, data: data) expect(import).to be_valid end it 'is invalid without an type' do - import = Import.create(account: account, data: data) + import = described_class.create(account: account, data: data) expect(import).to model_have_error_on_field(:type) end it 'is invalid without a data' do - import = Import.create(account: account, type: type) + import = described_class.create(account: account, type: type) expect(import).to model_have_error_on_field(:data) end end diff --git a/spec/models/media_attachment_spec.rb b/spec/models/media_attachment_spec.rb index becc748244..4d4bc748f7 100644 --- a/spec/models/media_attachment_spec.rb +++ b/spec/models/media_attachment_spec.rb @@ -85,7 +85,7 @@ RSpec.describe MediaAttachment do end describe 'animated gif conversion' do - let(:media) { MediaAttachment.create(account: Fabricate(:account), file: attachment_fixture('avatar.gif')) } + let(:media) { described_class.create(account: Fabricate(:account), file: attachment_fixture('avatar.gif')) } it 'sets type to gifv' do expect(media.type).to eq 'gifv' @@ -109,7 +109,7 @@ RSpec.describe MediaAttachment do fixtures.each do |fixture| context fixture[:filename] do - let(:media) { MediaAttachment.create(account: Fabricate(:account), file: attachment_fixture(fixture[:filename])) } + let(:media) { described_class.create(account: Fabricate(:account), file: attachment_fixture(fixture[:filename])) } it 'sets type to image' do expect(media.type).to eq 'image' @@ -129,7 +129,7 @@ RSpec.describe MediaAttachment do end describe 'ogg with cover art' do - let(:media) { MediaAttachment.create(account: Fabricate(:account), file: attachment_fixture('boop.ogg')) } + let(:media) { described_class.create(account: Fabricate(:account), file: attachment_fixture('boop.ogg')) } it 'detects it as an audio file' do expect(media.type).to eq 'audio' @@ -153,7 +153,7 @@ RSpec.describe MediaAttachment do end describe 'jpeg' do - let(:media) { MediaAttachment.create(account: Fabricate(:account), file: attachment_fixture('attachment.jpg')) } + let(:media) { described_class.create(account: Fabricate(:account), file: attachment_fixture('attachment.jpg')) } it 'sets meta for different style' do expect(media.file.meta['original']['width']).to eq 600 @@ -171,7 +171,7 @@ RSpec.describe MediaAttachment do describe 'base64-encoded jpeg' do let(:base64_attachment) { "data:image/jpeg;base64,#{Base64.encode64(attachment_fixture('attachment.jpg').read)}" } - let(:media) { MediaAttachment.create(account: Fabricate(:account), file: base64_attachment) } + let(:media) { described_class.create(account: Fabricate(:account), file: base64_attachment) } it 'saves media attachment' do expect(media.persisted?).to be true @@ -184,7 +184,7 @@ RSpec.describe MediaAttachment do end it 'is invalid without file' do - media = MediaAttachment.new(account: Fabricate(:account)) + media = described_class.new(account: Fabricate(:account)) expect(media.valid?).to be false end @@ -192,26 +192,26 @@ RSpec.describe MediaAttachment do it 'rejects video files that are too large' do stub_const 'MediaAttachment::IMAGE_LIMIT', 100.megabytes stub_const 'MediaAttachment::VIDEO_LIMIT', 1.kilobyte - expect { MediaAttachment.create!(account: Fabricate(:account), file: attachment_fixture('attachment.webm')) }.to raise_error(ActiveRecord::RecordInvalid) + expect { described_class.create!(account: Fabricate(:account), file: attachment_fixture('attachment.webm')) }.to raise_error(ActiveRecord::RecordInvalid) end it 'accepts video files that are small enough' do stub_const 'MediaAttachment::IMAGE_LIMIT', 1.kilobyte stub_const 'MediaAttachment::VIDEO_LIMIT', 100.megabytes - media = MediaAttachment.create!(account: Fabricate(:account), file: attachment_fixture('attachment.webm')) + media = described_class.create!(account: Fabricate(:account), file: attachment_fixture('attachment.webm')) expect(media.valid?).to be true end it 'rejects image files that are too large' do stub_const 'MediaAttachment::IMAGE_LIMIT', 1.kilobyte stub_const 'MediaAttachment::VIDEO_LIMIT', 100.megabytes - expect { MediaAttachment.create!(account: Fabricate(:account), file: attachment_fixture('attachment.jpg')) }.to raise_error(ActiveRecord::RecordInvalid) + expect { described_class.create!(account: Fabricate(:account), file: attachment_fixture('attachment.jpg')) }.to raise_error(ActiveRecord::RecordInvalid) end it 'accepts image files that are small enough' do stub_const 'MediaAttachment::IMAGE_LIMIT', 100.megabytes stub_const 'MediaAttachment::VIDEO_LIMIT', 1.kilobyte - media = MediaAttachment.create!(account: Fabricate(:account), file: attachment_fixture('attachment.jpg')) + media = described_class.create!(account: Fabricate(:account), file: attachment_fixture('attachment.jpg')) expect(media.valid?).to be true end end diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 795491546c..0dd9264e00 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -38,22 +38,22 @@ RSpec.describe Notification do describe '#type' do it 'returns :reblog for a Status' do - notification = Notification.new(activity: Status.new) + notification = described_class.new(activity: Status.new) expect(notification.type).to eq :reblog end it 'returns :mention for a Mention' do - notification = Notification.new(activity: Mention.new) + notification = described_class.new(activity: Mention.new) expect(notification.type).to eq :mention end it 'returns :favourite for a Favourite' do - notification = Notification.new(activity: Favourite.new) + notification = described_class.new(activity: Favourite.new) expect(notification.type).to eq :favourite end it 'returns :follow for a Follow' do - notification = Notification.new(activity: Follow.new) + notification = described_class.new(activity: Follow.new) expect(notification.type).to eq :follow end end diff --git a/spec/models/relationship_filter_spec.rb b/spec/models/relationship_filter_spec.rb index 7c0f37a06f..b3e855c122 100644 --- a/spec/models/relationship_filter_spec.rb +++ b/spec/models/relationship_filter_spec.rb @@ -8,7 +8,7 @@ describe RelationshipFilter do describe '#results' do context 'when default params are used' do let(:subject) do - RelationshipFilter.new(account, 'order' => 'active').results + described_class.new(account, 'order' => 'active').results end before do diff --git a/spec/models/report_filter_spec.rb b/spec/models/report_filter_spec.rb index 8269c45797..4b0852f081 100644 --- a/spec/models/report_filter_spec.rb +++ b/spec/models/report_filter_spec.rb @@ -5,7 +5,7 @@ require 'rails_helper' describe ReportFilter do describe 'with empty params' do it 'defaults to unresolved reports list' do - filter = ReportFilter.new({}) + filter = described_class.new({}) expect(filter.results).to eq Report.unresolved end @@ -13,7 +13,7 @@ describe ReportFilter do describe 'with invalid params' do it 'raises with key error' do - filter = ReportFilter.new(wrong: true) + filter = described_class.new(wrong: true) expect { filter.results }.to raise_error(/wrong/) end @@ -21,7 +21,7 @@ describe ReportFilter do describe 'with valid params' do it 'combines filters on Report' do - filter = ReportFilter.new(account_id: '123', resolved: true, target_account_id: '456') + filter = described_class.new(account_id: '123', resolved: true, target_account_id: '456') allow(Report).to receive(:where).and_return(Report.none) allow(Report).to receive(:resolved).and_return(Report.none) diff --git a/spec/models/session_activation_spec.rb b/spec/models/session_activation_spec.rb index 51c6aa5cb0..052a06e5ca 100644 --- a/spec/models/session_activation_spec.rb +++ b/spec/models/session_activation_spec.rb @@ -80,7 +80,7 @@ RSpec.describe SessionActivation do end it 'returns an instance of SessionActivation' do - expect(described_class.activate(**options)).to be_a SessionActivation + expect(described_class.activate(**options)).to be_a described_class end end diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index accce10f86..bba585cec6 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -146,7 +146,7 @@ RSpec.describe Setting do it 'includes Setting with value of default_value' do setting = described_class.all_as_records[key] - expect(setting).to be_a Setting + expect(setting).to be_a described_class expect(setting).to have_attributes(var: key) expect(setting).to have_attributes(value: 'default_value') end diff --git a/spec/models/site_upload_spec.rb b/spec/models/site_upload_spec.rb index d4a9293115..9689bce9ee 100644 --- a/spec/models/site_upload_spec.rb +++ b/spec/models/site_upload_spec.rb @@ -4,7 +4,7 @@ require 'rails_helper' RSpec.describe SiteUpload do describe '#cache_key' do - let(:site_upload) { SiteUpload.new(var: 'var') } + let(:site_upload) { described_class.new(var: 'var') } it 'returns cache_key' do expect(site_upload.cache_key).to eq 'site_uploads/var' diff --git a/spec/models/status_pin_spec.rb b/spec/models/status_pin_spec.rb index 52ce0847c4..660b2e92ac 100644 --- a/spec/models/status_pin_spec.rb +++ b/spec/models/status_pin_spec.rb @@ -8,14 +8,14 @@ RSpec.describe StatusPin do account = Fabricate(:account) status = Fabricate(:status, account: account) - expect(StatusPin.new(account: account, status: status).save).to be true + expect(described_class.new(account: account, status: status).save).to be true end it 'does not allow pins of statuses by someone else' do account = Fabricate(:account) status = Fabricate(:status) - expect(StatusPin.new(account: account, status: status).save).to be false + expect(described_class.new(account: account, status: status).save).to be false end it 'does not allow pins of reblogs' do @@ -23,21 +23,21 @@ RSpec.describe StatusPin do status = Fabricate(:status, account: account) reblog = Fabricate(:status, reblog: status) - expect(StatusPin.new(account: account, status: reblog).save).to be false + expect(described_class.new(account: account, status: reblog).save).to be false end it 'does allow pins of direct statuses' do account = Fabricate(:account) status = Fabricate(:status, account: account, visibility: :private) - expect(StatusPin.new(account: account, status: status).save).to be true + expect(described_class.new(account: account, status: status).save).to be true end it 'does not allow pins of direct statuses' do account = Fabricate(:account) status = Fabricate(:status, account: account, visibility: :direct) - expect(StatusPin.new(account: account, status: status).save).to be false + expect(described_class.new(account: account, status: status).save).to be false end max_pins = 5 @@ -50,10 +50,10 @@ RSpec.describe StatusPin do end max_pins.times do |i| - expect(StatusPin.new(account: account, status: status[i]).save).to be true + expect(described_class.new(account: account, status: status[i]).save).to be true end - expect(StatusPin.new(account: account, status: status[max_pins]).save).to be false + expect(described_class.new(account: account, status: status[max_pins]).save).to be false end it 'allows pins above the max for remote accounts' do @@ -65,10 +65,10 @@ RSpec.describe StatusPin do end max_pins.times do |i| - expect(StatusPin.new(account: account, status: status[i]).save).to be true + expect(described_class.new(account: account, status: status[i]).save).to be true end - expect(StatusPin.new(account: account, status: status[max_pins]).save).to be true + expect(described_class.new(account: account, status: status[max_pins]).save).to be true end end end diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb index 84ff82c789..3141c52c05 100644 --- a/spec/models/status_spec.rb +++ b/spec/models/status_spec.rb @@ -160,7 +160,7 @@ RSpec.describe Status do reblog = Fabricate(:status, account: bob, reblog: subject) expect(subject.reblogs_count).to eq 1 expect { subject.destroy }.to_not raise_error - expect(Status.find_by(id: reblog.id)).to be_nil + expect(described_class.find_by(id: reblog.id)).to be_nil end end @@ -206,7 +206,7 @@ RSpec.describe Status do end describe '.mutes_map' do - subject { Status.mutes_map([status.conversation.id], account) } + subject { described_class.mutes_map([status.conversation.id], account) } let(:status) { Fabricate(:status) } let(:account) { Fabricate(:account) } @@ -222,7 +222,7 @@ RSpec.describe Status do end describe '.favourites_map' do - subject { Status.favourites_map([status], account) } + subject { described_class.favourites_map([status], account) } let(:status) { Fabricate(:status) } let(:account) { Fabricate(:account) } @@ -238,7 +238,7 @@ RSpec.describe Status do end describe '.reblogs_map' do - subject { Status.reblogs_map([status], account) } + subject { described_class.reblogs_map([status], account) } let(:status) { Fabricate(:status) } let(:account) { Fabricate(:account) } @@ -265,17 +265,17 @@ RSpec.describe Status do context 'when given one tag' do it 'returns the expected statuses' do - expect(Status.tagged_with([tag1.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status5.id) - expect(Status.tagged_with([tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status5.id) - expect(Status.tagged_with([tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status3.id, status5.id) + expect(described_class.tagged_with([tag1.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status5.id) + expect(described_class.tagged_with([tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status5.id) + expect(described_class.tagged_with([tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status3.id, status5.id) end end context 'when given multiple tags' do it 'returns the expected statuses' do - expect(Status.tagged_with([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status2.id, status5.id) - expect(Status.tagged_with([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status3.id, status5.id) - expect(Status.tagged_with([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status3.id, status5.id) + expect(described_class.tagged_with([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status2.id, status5.id) + expect(described_class.tagged_with([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status3.id, status5.id) + expect(described_class.tagged_with([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status3.id, status5.id) end end end @@ -292,17 +292,17 @@ RSpec.describe Status do context 'when given one tag' do it 'returns the expected statuses' do - expect(Status.tagged_with_all([tag1.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status5.id) - expect(Status.tagged_with_all([tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status5.id) - expect(Status.tagged_with_all([tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status3.id) + expect(described_class.tagged_with_all([tag1.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status5.id) + expect(described_class.tagged_with_all([tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status5.id) + expect(described_class.tagged_with_all([tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status3.id) end end context 'when given multiple tags' do it 'returns the expected statuses' do - expect(Status.tagged_with_all([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status5.id) - expect(Status.tagged_with_all([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to eq [] - expect(Status.tagged_with_all([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to eq [] + expect(described_class.tagged_with_all([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status5.id) + expect(described_class.tagged_with_all([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to eq [] + expect(described_class.tagged_with_all([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to eq [] end end end @@ -319,17 +319,17 @@ RSpec.describe Status do context 'when given one tag' do it 'returns the expected statuses' do - expect(Status.tagged_with_none([tag1.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status3.id, status4.id) - expect(Status.tagged_with_none([tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status3.id, status4.id) - expect(Status.tagged_with_none([tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status2.id, status4.id) + expect(described_class.tagged_with_none([tag1.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status3.id, status4.id) + expect(described_class.tagged_with_none([tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status3.id, status4.id) + expect(described_class.tagged_with_none([tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status2.id, status4.id) end end context 'when given multiple tags' do it 'returns the expected statuses' do - expect(Status.tagged_with_none([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status3.id, status4.id) - expect(Status.tagged_with_none([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status4.id) - expect(Status.tagged_with_none([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status4.id) + expect(described_class.tagged_with_none([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status3.id, status4.id) + expect(described_class.tagged_with_none([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status4.id) + expect(described_class.tagged_with_none([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status4.id) end end end @@ -344,21 +344,21 @@ RSpec.describe Status do end it 'creates new conversation for stand-alone status' do - expect(Status.create(account: alice, text: 'First').conversation_id).to_not be_nil + expect(described_class.create(account: alice, text: 'First').conversation_id).to_not be_nil end it 'keeps conversation of parent node' do parent = Fabricate(:status, text: 'First') - expect(Status.create(account: alice, thread: parent, text: 'Response').conversation_id).to eq parent.conversation_id + expect(described_class.create(account: alice, thread: parent, text: 'Response').conversation_id).to eq parent.conversation_id end it 'sets `local` to true for status by local account' do - expect(Status.create(account: alice, text: 'foo').local).to be true + expect(described_class.create(account: alice, text: 'foo').local).to be true end it 'sets `local` to false for status by remote account' do alice.update(domain: 'example.com') - expect(Status.create(account: alice, text: 'foo').local).to be false + expect(described_class.create(account: alice, text: 'foo').local).to be false end end @@ -372,7 +372,7 @@ RSpec.describe Status do describe 'after_create' do it 'saves ActivityPub uri as uri for local status' do - status = Status.create(account: alice, text: 'foo') + status = described_class.create(account: alice, text: 'foo') status.reload expect(status.uri).to start_with('https://') end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d3e0ac63a4..554e7efb68 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -57,7 +57,7 @@ RSpec.describe User do it 'returns an array of recent users ordered by id' do user_1 = Fabricate(:user) user_2 = Fabricate(:user) - expect(User.recent).to eq [user_2, user_1] + expect(described_class.recent).to eq [user_2, user_1] end end @@ -65,7 +65,7 @@ RSpec.describe User do it 'returns an array of users who are confirmed' do user_1 = Fabricate(:user, confirmed_at: nil) user_2 = Fabricate(:user, confirmed_at: Time.zone.now) - expect(User.confirmed).to contain_exactly(user_2) + expect(described_class.confirmed).to contain_exactly(user_2) end end @@ -74,7 +74,7 @@ RSpec.describe User do specified = Fabricate(:user, current_sign_in_at: 15.days.ago) Fabricate(:user, current_sign_in_at: 6.days.ago) - expect(User.inactive).to contain_exactly(specified) + expect(described_class.inactive).to contain_exactly(specified) end end @@ -83,7 +83,7 @@ RSpec.describe User do specified = Fabricate(:user, email: 'specified@spec') Fabricate(:user, email: 'unspecified@spec') - expect(User.matches_email('specified')).to contain_exactly(specified) + expect(described_class.matches_email('specified')).to contain_exactly(specified) end end @@ -96,7 +96,7 @@ RSpec.describe User do Fabricate(:session_activation, user: user2, ip: '2160:8888::24', session_id: '3') Fabricate(:session_activation, user: user2, ip: '2160:8888::25', session_id: '4') - expect(User.matches_ip('2160:2160::/32')).to contain_exactly(user1) + expect(described_class.matches_ip('2160:2160::/32')).to contain_exactly(user1) end end end @@ -113,19 +113,19 @@ RSpec.describe User do end it 'allows a non-blacklisted user to be created' do - user = User.new(email: 'foo@example.com', account: account, password: password, agreement: true) + user = described_class.new(email: 'foo@example.com', account: account, password: password, agreement: true) 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) + user = described_class.new(email: 'foo@mvrht.com', account: account, password: password, agreement: true) 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) + user = described_class.new(email: 'foo@mvrht.com.topdomain.tld', account: account, password: password, agreement: true) expect(user).to_not be_valid end @@ -349,17 +349,17 @@ RSpec.describe User do end 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) + user = described_class.new(email: 'foo@example.com', account: account, password: password, agreement: true) 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) + user = described_class.new(email: 'foo@mastodon.space', account: account, password: password, agreement: true) 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) + user = described_class.new(email: 'foo@mastodon.space.userdomain.com', account: account, password: password, agreement: true) expect(user).to_not be_valid end @@ -373,7 +373,7 @@ RSpec.describe User do it 'does not allow a user to be created with a specific blacklisted subdomain even if the top domain is whitelisted' do Rails.configuration.x.email_domains_blacklist = 'blacklisted.mastodon.space' - user = User.new(email: 'foo@blacklisted.mastodon.space', account: account, password: password) + user = described_class.new(email: 'foo@blacklisted.mastodon.space', account: account, password: password) expect(user).to_not be_valid end end @@ -527,19 +527,19 @@ RSpec.describe User do end describe '.those_who_can' do - let!(:moderator_user) { Fabricate(:user, role: UserRole.find_by(name: 'Moderator')) } + before { Fabricate(:user, role: UserRole.find_by(name: 'Moderator')) } context 'when there are not any user roles' do before { UserRole.destroy_all } it 'returns an empty list' do - expect(User.those_who_can(:manage_blocks)).to eq([]) + expect(described_class.those_who_can(:manage_blocks)).to eq([]) end end context 'when there are not users with the needed role' do it 'returns an empty list' do - expect(User.those_who_can(:manage_blocks)).to eq([]) + expect(described_class.those_who_can(:manage_blocks)).to eq([]) end end @@ -547,7 +547,7 @@ RSpec.describe User do let!(:admin_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } it 'returns the users with the role' do - expect(User.those_who_can(:manage_blocks)).to eq([admin_user]) + expect(described_class.those_who_can(:manage_blocks)).to eq([admin_user]) end end end diff --git a/spec/policies/account_moderation_note_policy_spec.rb b/spec/policies/account_moderation_note_policy_spec.rb index 03d18250b2..90abdfea76 100644 --- a/spec/policies/account_moderation_note_policy_spec.rb +++ b/spec/policies/account_moderation_note_policy_spec.rb @@ -11,13 +11,13 @@ RSpec.describe AccountModerationNotePolicy do permissions :create? do context 'when staff' do it 'grants to create' do - expect(subject).to permit(admin, AccountModerationNotePolicy) + expect(subject).to permit(admin, described_class) end end context 'when not staff' do it 'denies to create' do - expect(subject).to_not permit(john, AccountModerationNotePolicy) + expect(subject).to_not permit(john, described_class) end end end diff --git a/spec/presenters/account_relationships_presenter_spec.rb b/spec/presenters/account_relationships_presenter_spec.rb index d59060bd5c..5c2ba54e00 100644 --- a/spec/presenters/account_relationships_presenter_spec.rb +++ b/spec/presenters/account_relationships_presenter_spec.rb @@ -14,7 +14,7 @@ RSpec.describe AccountRelationshipsPresenter do allow(Account).to receive(:domain_blocking_map).with(account_ids, current_account_id).and_return(default_map) end - let(:presenter) { AccountRelationshipsPresenter.new(account_ids, current_account_id, **options) } + let(:presenter) { described_class.new(account_ids, current_account_id, **options) } let(:current_account_id) { Fabricate(:account).id } let(:account_ids) { [Fabricate(:account).id] } let(:default_map) { { 1 => true } } diff --git a/spec/presenters/status_relationships_presenter_spec.rb b/spec/presenters/status_relationships_presenter_spec.rb index a62fa004a1..7746c8cd78 100644 --- a/spec/presenters/status_relationships_presenter_spec.rb +++ b/spec/presenters/status_relationships_presenter_spec.rb @@ -12,7 +12,7 @@ RSpec.describe StatusRelationshipsPresenter do allow(Status).to receive(:pins_map).with(anything, current_account_id).and_return(default_map) end - let(:presenter) { StatusRelationshipsPresenter.new(statuses, current_account_id, **options) } + let(:presenter) { described_class.new(statuses, current_account_id, **options) } let(:current_account_id) { Fabricate(:account).id } let(:statuses) { [Fabricate(:status)] } let(:status_ids) { statuses.map(&:id) + statuses.filter_map(&:reblog_of_id) } diff --git a/spec/serializers/activitypub/note_serializer_spec.rb b/spec/serializers/activitypub/note_serializer_spec.rb index 7ea47baef2..68f5378918 100644 --- a/spec/serializers/activitypub/note_serializer_spec.rb +++ b/spec/serializers/activitypub/note_serializer_spec.rb @@ -15,7 +15,7 @@ describe ActivityPub::NoteSerializer do let!(:reply5) { Fabricate(:status, account: account, thread: parent, visibility: :direct) } before(:each) do - @serialization = ActiveModelSerializers::SerializableResource.new(parent, serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter) + @serialization = ActiveModelSerializers::SerializableResource.new(parent, serializer: described_class, adapter: ActivityPub::Adapter) end it 'has a Note type' do diff --git a/spec/serializers/activitypub/update_poll_serializer_spec.rb b/spec/serializers/activitypub/update_poll_serializer_spec.rb index 4360808b50..14c24c70cc 100644 --- a/spec/serializers/activitypub/update_poll_serializer_spec.rb +++ b/spec/serializers/activitypub/update_poll_serializer_spec.rb @@ -10,7 +10,7 @@ describe ActivityPub::UpdatePollSerializer do let!(:status) { Fabricate(:status, account: account, poll: poll) } before(:each) do - @serialization = ActiveModelSerializers::SerializableResource.new(status, serializer: ActivityPub::UpdatePollSerializer, adapter: ActivityPub::Adapter) + @serialization = ActiveModelSerializers::SerializableResource.new(status, serializer: described_class, adapter: ActivityPub::Adapter) end it 'has a Update type' do diff --git a/spec/serializers/rest/account_serializer_spec.rb b/spec/serializers/rest/account_serializer_spec.rb index 528639943c..e399e88f37 100644 --- a/spec/serializers/rest/account_serializer_spec.rb +++ b/spec/serializers/rest/account_serializer_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe REST::AccountSerializer do - subject { JSON.parse(ActiveModelSerializers::SerializableResource.new(account, serializer: REST::AccountSerializer).to_json) } + subject { JSON.parse(ActiveModelSerializers::SerializableResource.new(account, serializer: described_class).to_json) } let(:role) { Fabricate(:user_role, name: 'Role', highlighted: true) } let(:user) { Fabricate(:user, role: role) } diff --git a/spec/services/activitypub/fetch_remote_account_service_spec.rb b/spec/services/activitypub/fetch_remote_account_service_spec.rb index 868bc2a582..ac7484d96d 100644 --- a/spec/services/activitypub/fetch_remote_account_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_account_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe ActivityPub::FetchRemoteAccountService, type: :service do - subject { ActivityPub::FetchRemoteAccountService.new } + subject { described_class.new } let!(:actor) do { diff --git a/spec/services/activitypub/fetch_remote_actor_service_spec.rb b/spec/services/activitypub/fetch_remote_actor_service_spec.rb index a72c6941e9..93d31b69d5 100644 --- a/spec/services/activitypub/fetch_remote_actor_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_actor_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe ActivityPub::FetchRemoteActorService, type: :service do - subject { ActivityPub::FetchRemoteActorService.new } + subject { described_class.new } let!(:actor) do { diff --git a/spec/services/activitypub/fetch_remote_key_service_spec.rb b/spec/services/activitypub/fetch_remote_key_service_spec.rb index 0ec0c27362..cd8f29dddd 100644 --- a/spec/services/activitypub/fetch_remote_key_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_key_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe ActivityPub::FetchRemoteKeyService, type: :service do - subject { ActivityPub::FetchRemoteKeyService.new } + subject { described_class.new } let(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice' }] } } diff --git a/spec/services/after_block_domain_from_account_service_spec.rb b/spec/services/after_block_domain_from_account_service_spec.rb index b75f923729..9bfaa35807 100644 --- a/spec/services/after_block_domain_from_account_service_spec.rb +++ b/spec/services/after_block_domain_from_account_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe AfterBlockDomainFromAccountService, type: :service do - subject { AfterBlockDomainFromAccountService.new } + subject { described_class.new } let!(:wolf) { Fabricate(:account, username: 'wolf', domain: 'evil.org', inbox_url: 'https://evil.org/inbox', protocol: :activitypub) } let!(:alice) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/authorize_follow_service_spec.rb b/spec/services/authorize_follow_service_spec.rb index 63d9e2a0f4..d07645ab6b 100644 --- a/spec/services/authorize_follow_service_spec.rb +++ b/spec/services/authorize_follow_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe AuthorizeFollowService, type: :service do - subject { AuthorizeFollowService.new } + subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/batched_remove_status_service_spec.rb b/spec/services/batched_remove_status_service_spec.rb index 9bedf37444..c0cd01315f 100644 --- a/spec/services/batched_remove_status_service_spec.rb +++ b/spec/services/batched_remove_status_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe BatchedRemoveStatusService, type: :service do - subject { BatchedRemoveStatusService.new } + subject { described_class.new } let!(:alice) { Fabricate(:account) } let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') } diff --git a/spec/services/block_domain_service_spec.rb b/spec/services/block_domain_service_spec.rb index 0ab97b8ce9..93722a15bc 100644 --- a/spec/services/block_domain_service_spec.rb +++ b/spec/services/block_domain_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe BlockDomainService, type: :service do - subject { BlockDomainService.new } + subject { described_class.new } let!(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') } let!(:bad_status1) { Fabricate(:status, account: bad_account, text: 'You suck') } diff --git a/spec/services/block_service_spec.rb b/spec/services/block_service_spec.rb index 75f07f5adf..5f7c2e8da0 100644 --- a/spec/services/block_service_spec.rb +++ b/spec/services/block_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe BlockService, type: :service do - subject { BlockService.new } + subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/bootstrap_timeline_service_spec.rb b/spec/services/bootstrap_timeline_service_spec.rb index 670ac652fb..5a15ba7418 100644 --- a/spec/services/bootstrap_timeline_service_spec.rb +++ b/spec/services/bootstrap_timeline_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe BootstrapTimelineService, type: :service do - subject { BootstrapTimelineService.new } + subject { described_class.new } context 'when the new user has registered from an invite' do let(:service) { double } diff --git a/spec/services/clear_domain_media_service_spec.rb b/spec/services/clear_domain_media_service_spec.rb index 9875075796..2a00409a41 100644 --- a/spec/services/clear_domain_media_service_spec.rb +++ b/spec/services/clear_domain_media_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe ClearDomainMediaService, type: :service do - subject { ClearDomainMediaService.new } + subject { described_class.new } let!(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') } let!(:bad_status1) { Fabricate(:status, account: bad_account, text: 'You suck') } diff --git a/spec/services/favourite_service_spec.rb b/spec/services/favourite_service_spec.rb index 613ae203ed..782c235c41 100644 --- a/spec/services/favourite_service_spec.rb +++ b/spec/services/favourite_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe FavouriteService, type: :service do - subject { FavouriteService.new } + subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/follow_service_spec.rb b/spec/services/follow_service_spec.rb index c9521e3c87..c2ad0d7173 100644 --- a/spec/services/follow_service_spec.rb +++ b/spec/services/follow_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe FollowService, type: :service do - subject { FollowService.new } + subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/import_service_spec.rb b/spec/services/import_service_spec.rb index 7f8e5855fa..32ba4409c3 100644 --- a/spec/services/import_service_spec.rb +++ b/spec/services/import_service_spec.rb @@ -14,7 +14,7 @@ RSpec.describe ImportService, type: :service do end context 'when importing old-style list of muted users' do - subject { ImportService.new } + subject { described_class.new } let(:csv) { attachment_fixture('mute-imports.txt') } @@ -52,7 +52,7 @@ RSpec.describe ImportService, type: :service do end context 'when importing new-style list of muted users' do - subject { ImportService.new } + subject { described_class.new } let(:csv) { attachment_fixture('new-mute-imports.txt') } @@ -93,7 +93,7 @@ RSpec.describe ImportService, type: :service do end context 'when importing old-style list of followed users' do - subject { ImportService.new } + subject { described_class.new } let(:csv) { attachment_fixture('mute-imports.txt') } @@ -135,7 +135,7 @@ RSpec.describe ImportService, type: :service do end context 'when importing new-style list of followed users' do - subject { ImportService.new } + subject { described_class.new } let(:csv) { attachment_fixture('new-following-imports.txt') } @@ -182,7 +182,7 @@ RSpec.describe ImportService, type: :service do # # https://github.com/mastodon/mastodon/issues/20571 context 'with a utf-8 encoded domains' do - subject { ImportService.new } + subject { described_class.new } let!(:nare) { Fabricate(:account, username: 'nare', domain: 'թութ.հայ', locked: false, protocol: :activitypub, inbox_url: 'https://թութ.հայ/inbox') } let(:csv) { attachment_fixture('utf8-followers.txt') } @@ -201,7 +201,7 @@ RSpec.describe ImportService, type: :service do end context 'when importing bookmarks' do - subject { ImportService.new } + subject { described_class.new } let(:csv) { attachment_fixture('bookmark-imports.txt') } let(:local_account) { Fabricate(:account, username: 'foo', domain: '') } diff --git a/spec/services/post_status_service_spec.rb b/spec/services/post_status_service_spec.rb index f577122710..76ef5391f0 100644 --- a/spec/services/post_status_service_spec.rb +++ b/spec/services/post_status_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe PostStatusService, type: :service do - subject { PostStatusService.new } + subject { described_class.new } it 'creates a new status' do account = Fabricate(:account) diff --git a/spec/services/precompute_feed_service_spec.rb b/spec/services/precompute_feed_service_spec.rb index 18ba00244d..54e0d94ee0 100644 --- a/spec/services/precompute_feed_service_spec.rb +++ b/spec/services/precompute_feed_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe PrecomputeFeedService, type: :service do - subject { PrecomputeFeedService.new } + subject { described_class.new } describe 'call' do let(:account) { Fabricate(:account) } diff --git a/spec/services/process_mentions_service_spec.rb b/spec/services/process_mentions_service_spec.rb index 399800b2a6..a28b6db409 100644 --- a/spec/services/process_mentions_service_spec.rb +++ b/spec/services/process_mentions_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe ProcessMentionsService, type: :service do - subject { ProcessMentionsService.new } + subject { described_class.new } let(:account) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/purge_domain_service_spec.rb b/spec/services/purge_domain_service_spec.rb index 310affa5e3..89ab4d8d9f 100644 --- a/spec/services/purge_domain_service_spec.rb +++ b/spec/services/purge_domain_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe PurgeDomainService, type: :service do - subject { PurgeDomainService.new } + subject { described_class.new } let!(:old_account) { Fabricate(:account, domain: 'obsolete.org') } let!(:old_status1) { Fabricate(:status, account: old_account) } diff --git a/spec/services/reblog_service_spec.rb b/spec/services/reblog_service_spec.rb index 69500848d9..7b85e37ed8 100644 --- a/spec/services/reblog_service_spec.rb +++ b/spec/services/reblog_service_spec.rb @@ -6,7 +6,7 @@ RSpec.describe ReblogService, type: :service do let(:alice) { Fabricate(:account, username: 'alice') } context 'when creates a reblog with appropriate visibility' do - subject { ReblogService.new } + subject { described_class.new } let(:visibility) { :public } let(:reblog_visibility) { :public } @@ -62,7 +62,7 @@ RSpec.describe ReblogService, type: :service do end context 'with ActivityPub' do - subject { ReblogService.new } + subject { described_class.new } let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') } let(:status) { Fabricate(:status, account: bob) } diff --git a/spec/services/reject_follow_service_spec.rb b/spec/services/reject_follow_service_spec.rb index be9363d846..d28104b2c7 100644 --- a/spec/services/reject_follow_service_spec.rb +++ b/spec/services/reject_follow_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe RejectFollowService, type: :service do - subject { RejectFollowService.new } + subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/remove_from_followers_service_spec.rb b/spec/services/remove_from_followers_service_spec.rb index 21cea2e4f8..1b29cdcbea 100644 --- a/spec/services/remove_from_followers_service_spec.rb +++ b/spec/services/remove_from_followers_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe RemoveFromFollowersService, type: :service do - subject { RemoveFromFollowersService.new } + subject { described_class.new } let(:bob) { Fabricate(:account, username: 'bob') } diff --git a/spec/services/remove_status_service_spec.rb b/spec/services/remove_status_service_spec.rb index a836109a0d..77b01d3072 100644 --- a/spec/services/remove_status_service_spec.rb +++ b/spec/services/remove_status_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe RemoveStatusService, type: :service do - subject { RemoveStatusService.new } + subject { described_class.new } let!(:alice) { Fabricate(:account) } let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') } diff --git a/spec/services/unallow_domain_service_spec.rb b/spec/services/unallow_domain_service_spec.rb index fbc1d59592..4db718d074 100644 --- a/spec/services/unallow_domain_service_spec.rb +++ b/spec/services/unallow_domain_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe UnallowDomainService, type: :service do - subject { UnallowDomainService.new } + subject { described_class.new } let!(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') } let!(:bad_status1) { Fabricate(:status, account: bad_account, text: 'You suck') } diff --git a/spec/services/unblock_service_spec.rb b/spec/services/unblock_service_spec.rb index 8098d7e6d0..86632c3938 100644 --- a/spec/services/unblock_service_spec.rb +++ b/spec/services/unblock_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe UnblockService, type: :service do - subject { UnblockService.new } + subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/unfollow_service_spec.rb b/spec/services/unfollow_service_spec.rb index a12f01fa5d..3e65e610ba 100644 --- a/spec/services/unfollow_service_spec.rb +++ b/spec/services/unfollow_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe UnfollowService, type: :service do - subject { UnfollowService.new } + subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/unmute_service_spec.rb b/spec/services/unmute_service_spec.rb index 2edb6cfc28..236f837e2d 100644 --- a/spec/services/unmute_service_spec.rb +++ b/spec/services/unmute_service_spec.rb @@ -3,5 +3,5 @@ require 'rails_helper' RSpec.describe UnmuteService, type: :service do - subject { UnmuteService.new } + subject { described_class.new } end diff --git a/spec/services/update_account_service_spec.rb b/spec/services/update_account_service_spec.rb index a711a8ae73..6318cc95fb 100644 --- a/spec/services/update_account_service_spec.rb +++ b/spec/services/update_account_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe UpdateAccountService, type: :service do - subject { UpdateAccountService.new } + subject { described_class.new } describe 'switching form locked to unlocked accounts' do let(:account) { Fabricate(:account, locked: true) } diff --git a/spec/validators/note_length_validator_spec.rb b/spec/validators/note_length_validator_spec.rb index 390ac8d904..e45d221d76 100644 --- a/spec/validators/note_length_validator_spec.rb +++ b/spec/validators/note_length_validator_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe NoteLengthValidator do - subject { NoteLengthValidator.new(attributes: { note: true }, maximum: 500) } + subject { described_class.new(attributes: { note: true }, maximum: 500) } describe '#validate' do it 'adds an error when text is over 500 characters' do From 9a653899e907ff7c1dcec3a6faf868075976974e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 6 Jun 2023 14:16:41 +0200 Subject: [PATCH 10/17] Update dependency redis to v4.6.7 (#25300) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- yarn.lock | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/yarn.lock b/yarn.lock index 8839ed68d7..76414138af 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1880,10 +1880,10 @@ resolved "https://registry.yarnpkg.com/@redis/bloom/-/bloom-1.2.0.tgz#d3fd6d3c0af3ef92f26767b56414a370c7b63b71" integrity sha512-HG2DFjYKbpNmVXsa0keLHp/3leGJz1mjh09f2RLGGLQZzSHpkmZWuwJbAvo3QcRY8p80m5+ZdXZdYOSBLlp7Cg== -"@redis/client@1.5.6": - version "1.5.6" - resolved "https://registry.yarnpkg.com/@redis/client/-/client-1.5.6.tgz#869cc65718d7d5493ef655a71dc40f3bc64a1b28" - integrity sha512-dFD1S6je+A47Lj22jN/upVU2fj4huR7S9APd7/ziUXsIXDL+11GPYti4Suv5y8FuXaN+0ZG4JF+y1houEJ7ToA== +"@redis/client@1.5.8": + version "1.5.8" + resolved "https://registry.yarnpkg.com/@redis/client/-/client-1.5.8.tgz#a375ba7861825bd0d2dc512282b8bff7b98dbcb1" + integrity sha512-xzElwHIO6rBAqzPeVnCzgvrnBEcFL1P0w8P65VNLRkdVW8rOE58f52hdj0BDgmsdOm4f1EoXPZtH4Fh7M/qUpw== dependencies: cluster-key-slot "1.1.2" generic-pool "3.9.0" @@ -1899,10 +1899,10 @@ resolved "https://registry.yarnpkg.com/@redis/json/-/json-1.0.4.tgz#f372b5f93324e6ffb7f16aadcbcb4e5c3d39bda1" integrity sha512-LUZE2Gdrhg0Rx7AN+cZkb1e6HjoSKaeeW8rYnt89Tly13GBI5eP4CwDVr+MY8BAYfCg4/N15OUrtLoona9uSgw== -"@redis/search@1.1.2": - version "1.1.2" - resolved "https://registry.yarnpkg.com/@redis/search/-/search-1.1.2.tgz#6a8f66ba90812d39c2457420f859ce8fbd8f3838" - integrity sha512-/cMfstG/fOh/SsE+4/BQGeuH/JJloeWuH+qJzM8dbxuWvdWibWAOAHHCZTMPhV3xIlH4/cUEIA8OV5QnYpaVoA== +"@redis/search@1.1.3": + version "1.1.3" + resolved "https://registry.yarnpkg.com/@redis/search/-/search-1.1.3.tgz#b5a6837522ce9028267fe6f50762a8bcfd2e998b" + integrity sha512-4Dg1JjvCevdiCBTZqjhKkGoC5/BcB7k9j99kdMnaXFXg8x4eyOIVg9487CMv7/BUVkFLZCaIh8ead9mU15DNng== "@redis/time-series@1.0.4": version "1.0.4" @@ -10001,15 +10001,15 @@ redent@^3.0.0: strip-indent "^3.0.0" redis@^4.6.5: - version "4.6.5" - resolved "https://registry.yarnpkg.com/redis/-/redis-4.6.5.tgz#f32fbde44429e96f562bb0c9b1db0143ab8cfa4f" - integrity sha512-O0OWA36gDQbswOdUuAhRL6mTZpHFN525HlgZgDaVNgCJIAZR3ya06NTESb0R+TUZ+BFaDpz6NnnVvoMx9meUFg== + version "4.6.7" + resolved "https://registry.yarnpkg.com/redis/-/redis-4.6.7.tgz#c73123ad0b572776223f172ec78185adb72a6b57" + integrity sha512-KrkuNJNpCwRm5vFJh0tteMxW8SaUzkm5fBH7eL5hd/D0fAkzvapxbfGPP/r+4JAXdQuX7nebsBkBqA2RHB7Usw== dependencies: "@redis/bloom" "1.2.0" - "@redis/client" "1.5.6" + "@redis/client" "1.5.8" "@redis/graph" "1.1.0" "@redis/json" "1.0.4" - "@redis/search" "1.1.2" + "@redis/search" "1.1.3" "@redis/time-series" "1.0.4" redux-immutable@^4.0.0: From c66250abf17b4aad1abc1500c14bf9862c078226 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Tue, 6 Jun 2023 08:50:51 -0400 Subject: [PATCH 11/17] Autofix Rubocop Regex Style rules (#23690) Co-authored-by: Claire --- .rubocop_todo.yml | 46 ---------------------- app/lib/link_details_extractor.rb | 14 +++---- app/lib/plain_text_formatter.rb | 2 +- app/lib/tag_manager.rb | 6 +-- app/lib/text_formatter.rb | 2 +- app/lib/webfinger_resource.rb | 2 +- app/models/account.rb | 6 +-- app/models/domain_allow.rb | 2 +- app/models/domain_block.rb | 2 +- app/models/site_upload.rb | 2 +- app/models/tag.rb | 2 +- app/services/backup_service.rb | 4 +- app/services/fetch_link_card_service.rb | 2 +- app/services/fetch_oembed_service.rb | 2 +- app/services/search_service.rb | 2 +- config/initializers/rack_attack.rb | 6 +-- config/initializers/twitter_regex.rb | 16 ++++---- config/routes.rb | 6 +-- lib/mastodon/premailer_webpack_strategy.rb | 2 +- lib/paperclip/color_extractor.rb | 2 +- lib/tasks/emojis.rake | 2 +- lib/tasks/mastodon.rake | 8 ++-- 22 files changed, 46 insertions(+), 92 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1a16472bdb..0d0fbfac91 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1412,52 +1412,6 @@ Style/RedundantFetchBlock: - 'config/initializers/paperclip.rb' - 'config/puma.rb' -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantRegexpCharacterClass: - Exclude: - - 'app/lib/link_details_extractor.rb' - - 'app/lib/tag_manager.rb' - - 'app/models/domain_allow.rb' - - 'app/models/domain_block.rb' - - 'app/services/fetch_oembed_service.rb' - - 'config/initializers/rack_attack.rb' - - 'lib/tasks/emojis.rake' - - 'lib/tasks/mastodon.rake' - -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantRegexpEscape: - Exclude: - - 'app/lib/webfinger_resource.rb' - - 'app/models/account.rb' - - 'app/models/tag.rb' - - 'app/services/fetch_link_card_service.rb' - - 'config/initializers/twitter_regex.rb' - - 'lib/paperclip/color_extractor.rb' - - 'lib/tasks/mastodon.rake' - -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, AllowInnerSlashes. -# SupportedStyles: slashes, percent_r, mixed -Style/RegexpLiteral: - Exclude: - - 'app/lib/link_details_extractor.rb' - - 'app/lib/plain_text_formatter.rb' - - 'app/lib/tag_manager.rb' - - 'app/lib/text_formatter.rb' - - 'app/models/account.rb' - - 'app/models/domain_allow.rb' - - 'app/models/domain_block.rb' - - 'app/models/site_upload.rb' - - 'app/models/tag.rb' - - 'app/services/backup_service.rb' - - 'app/services/fetch_oembed_service.rb' - - 'app/services/search_service.rb' - - 'config/initializers/rack_attack.rb' - - 'config/initializers/twitter_regex.rb' - - 'config/routes.rb' - - 'lib/mastodon/premailer_webpack_strategy.rb' - - 'lib/tasks/mastodon.rake' - # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. # AllowedMethods: present?, blank?, presence, try, try! diff --git a/app/lib/link_details_extractor.rb b/app/lib/link_details_extractor.rb index dfed69285f..f0aeec0b3e 100644 --- a/app/lib/link_details_extractor.rb +++ b/app/lib/link_details_extractor.rb @@ -7,15 +7,15 @@ class LinkDetailsExtractor # Some publications wrap their JSON-LD data in their